Topic category: Troubleshooting, bugs, and solutions
In the mod I'm creating, I wanted to be able to click a block with a custom item and have it call a specific procedure if the block is water. However, Minecraft doesn't consider water blocks when getting "Looking at" coordinates. Here's what I mean.
The coordinates are the same, even though I'm looking at the water block in the second image. So, the statement "If block at x,y,z is water" will never return true in this case. I did figure out a work around, though. It doesn't function exactly the same as I originally wanted, but it works well enough for my purpose. It checks around the provided x,y,z coordinates to see if any are water blocks. I plan on improving this later, but you can download my original code here. It will be collapsed when you import it, but you can expand all of it to edit some variables, as I've described below. Here is the expanded code.
The numbers I've circled in red represent how many blocks away you want to check for water. If you want to change how many blocks away the procedure checks, you have to change all of the numbers that are circled. The call procedure outlined in the red rectangle should be changed to the procedure you want to call if water is found.
The "Import procedure" button can be found near the top right of the Mcreator window when you open a procedure. After it's imported, just connect the new blocks to the "Event trigger" block. To trigger the procedure, I created a new item and set its "When right clicked on block (hand loc.)" option to this procedure.
If you have any suggestions or improvement, please let me know!
How you make the Water Bars? I will make mana Bars from terraria but i dont know how.
?
RockstarBonnet You just need to make an overlay and import the picture of bar you want, please don't ask me about procedures because I am not and well aware in the fact I am not an expert in that
thanks
Not sure if this solution was covered in this thread (I might have missed it). I, too, noticed how MCreator looks right through a water block at the block behind it. So, what about telling it to check the block above the one looked at to see if it is a water block? It doesn't necessarily need to check every block around the one being looked at, but just 2 of them... x, y-1, z (in case the crosshairs are sitting on the block directly under the water block), and also x-1,y,z (in case the crosshairs are sitting on the block further away from the player than the water block but on the same "y" as the player).
Actually, one of those coordinates should be x,y+1,z instead of x,y-1,z.
Oh, but wait a minute... I guess it does need to check more than just 2 blocks, because of the angle the player might be looking along.
I found something that works. But it reads only the block directly above the one being looked at, not any other blocks all around. So the player needs to keep moving the crosshairs around a little. But it works, anyway.
https://ibb.co/vPnnVL2
how do i get the "local: loopNumber" and "local: Water nearby"?
Do you have a download for that?
Nevermind
I have a better one here: https://ibb.co/w04CnBs. 
In this one shown here, it checks to see if the block directly above the block you click on has empty air. If it does have empty air AND you're holding a bucket with water, it will put a water block there, remove the water bucket from inventory, and add an empty bucket to your inventory. So you need to create two items: a bucket of water and an empty bucket.
This snippet of commands also checks if the block directly above the block you click on already has water. So in this case, you'd be clicking on a block underwater. If it does have water above it already AND you're holding an empty bucket, it will remove the water block, remove the empty bucket from your inventory, and add a bucket of water to your inventory.
The only problem with this that I haven't been able to fix is that it will take water from both still water and flowing water, whereas the vanilla iron bucket will take water from only still water and not from flowing water. I haven't been able to figure out how distinguish between still water and flowing water. Even though MCreator has two separate water items, one that says "standing water" and the other that says "flowing water", when I use either one in this code, it will treat them both the same.
I hope this helps. Have a good one.
Thank you vision quester for the procedures! i have credited you in the credits of my mod.
Interesting! I wasn't expecting a bucket feature in this mod, but that's a good approach to the issue. That could definitely trim down the amount of code used.