PneumaticCraft: Repressurized

PneumaticCraft: Repressurized

43M Downloads

For each coordinate with random area never exits

johalun opened this issue ยท 5 comments

commented

Describe the bug

If using a random area with a for each item widget the iteration never exits. The behavior is like that for each iteration of the area, a new random area is being generated and the iterator never finishes iterating over the initial set of random locations in the area.

How to reproduce the bug

  • create a random area with for example limit of 5 blocks
  • use this area with a for each coordinate widget
  • have the for each coordinate widget call a subroutine that places a block at that position

The program will keep placing blocks beyond the 5 block limit.

Expected behavior

I expect that 5 blocks will be placed in the random location visible in "preview area" and then the for each coordinate widget will exit

Additional details

No response

Which Minecraft version are you using?

1.19

Which version of PneumaticCraft: Repressurized are you using?

1.19.2-4.3.7-30

Crash log

No response

commented

I'm also noticing some weirdness in 1.19 with the For Each Coordinate piece. It's almost as if the drone is re-checking every coordinate checked in all the previous iterations before running the current one, but I'm not seeing the same behavior as @johalun (aside from it choosing a coordinate randomly, that is the same).

commented

Well, I did spot a related arithmetic problem which mistakenly calculate a 0 size for areas only 1 block thick in any axis. Which led the random area setting to just iterate every block in the area instead of a random subset.

However, making the foreach coord widget work with a random area type might be a lot harder, though I will investigate. Related to dynamic area generation. In the short term it's probably easier to have a bit of local logic to force a break after a certain count by setting the foreach widget's variable to an invalid blockpos (anything outside the world's build height).

commented

I should probably add that I wasn't specifically trying to do a 'random area' of any kind, I just wanted a predictable iteration of each coordinate using a statically defined area of the standard filled box type. I didn't have any issues with a 1 block thick area of 8x1x1, that just iterated one block at a time in a predictable sequence, as expected. when I did an 8x8x8 cube however... it would pick a block at random, but each iteration would take exponentially longer than the previous iteration because it'd iterate through every block that it has already checked before picking a new random one.

commented

I noticed another issue too with random areas. I haven't done any scientific investigation yet so can't give specifics but I noticed that in my cuboid that was around 10x10 in X and Z and maybe 10-20 high, the south and east sides of the cuboid would not get any blocks selected, however if I made the cuboid taller, like 100+ blocks, they would. So there's off by one error or something that is related to how tall or how large the random area is. I can dig into this a bit more to see if I can find more exact data.

commented

Sounds like the same bug that I spotted. The volume of the box being calculated was too small (by 1 on each axis).