Started by
DreamMach1ne
on
Topic category: Help with Minecraft modding (Java Edition)
I'm trying to spawn a structure with a procedure as part of a random event and I want to make sure the selected block can see the surface. What i'm trying to achieve is having the y coordinate go up by one each time until the if statement (can position at xPosition yPosition zPosition see the sky) is true. How would i make this repeat until the if statement is true?
there are repeat blocks, but i would be careful with them, as they can screw up performance. there are repeat x amount of times ones, like the ones used in the "check for blocks in a 6x6x6 area" template. there is also one that repeats untill condidtion is met, but that one is riskier.
The while repeat block, like proclarushtaonasat said, is somewhat risky and can crash your game if you're checking until a specific condition is met, because it will keep checking in the same tick. Although in your specific case, it would likely be fine. I can think of two alternate ways to check for something repeatedly, but spread out over time.
The first would be to use global number variables for the X, Y and Z positions and a global logic variable for if a valid position has been found yet. Then run the procedure from the global trigger on world tick update. First make sure a valid position hasn't been found yet, then increase Y value and check if the new position is valid. If it isn't, then next world tick will check one position higher, then one after that.
The second is more complicated and requires you to understand the advanced "call procedure" procedure block. Basically, you have a procedure with no external triggers, create an empty procedure for it, save it, then re-open it (to refresh a list used later on). Have it check if position at X, Y, Z can see the sky, and in the else condition, wait one tick, then on server-side, call the same procedure again, but at X, Y+1, Z. Then in the procedure you currently have, change it so that all it does is call the looping procedure at whatever coordinates you want to start searching at.
Both of those methods do have downsides though. The first one relies on global variables, so you can't have two checks running at the same time, if that's something that matters. The second one relies on the "wait x ticks then do on server-side" procedure block which can act unreliably sometimes and can get cut-off if the player exits and rejoins the world.
Also, one final note, do not, under any circumstances, use the "wait x ticks then do on server-side" procedure block inside the while procedure block as a condition. while does everything in a single tick, so if you tried to wait one tick then check one Y level higher, it would run infinitely in the same tick and crash the game.
I got it working with the second method. Thanks a lot!
Hi! Glad to hear it was resolved. In general, I suggest you check our tutorials collection playlist on our YouTube channel, which contains many examples and tutorials that can help you get started with MCreator: https://www.youtube.com/playlist?list=PLAeL-oIFIEngE6jRgFYeFMfuj8WQsO3Ei
^ very important