(FIXED) block at x y z not being correct when testing for energy in gui update tick

Started by gorgin on

Topic category: Troubleshooting, bugs, and solutions

Joined Dec 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
(FIXED) block at x y z not being correct when testing for energy in gui update tick
Wed, 06/26/2024 - 22:30 (edited)

I am testing if the block at x, y, z has a certain amount of energy. Nothing happens, but if I remove the testing for if the block at x, y, z has enough energy it works.

 

Edit:

It works if you are in the block, so I think it is testing your x, y, z

 

SOLUTION:

Set local number variables for x, y, and z with the blocks:

   "Look X position of Event/TargetEntity with raytrace distance 5 fluid mode None block mode Outline"

   "Look Y position..."

   "Look Z position... "

respectively

replace all x, y, and z blocks with the local variables

 

Though if you move after you've opened the gui it won't work, but most of the time you shouldn't have moved so it should be fine.

Edited by gorgin on Wed, 06/26/2024 - 22:30
Joined Jun 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
could you clarify what is…
Wed, 06/26/2024 - 01:57

could you clarify what is triggering the procedure? sometimes just xyz blocks don't work, so please clarify

Joined Dec 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
could you clarify what is…
Wed, 06/26/2024 - 03:05

could you clarify what is triggering the procedure? sometimes just xyz blocks don't work, so please clarify

the "While this GUI is open tick" of the block's gui

Joined Nov 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I see the raytracing…
Sun, 10/06/2024 - 07:18

I see the raytracing solution. As OP has said, the player might move after the gui is opened, which might cause problems with that solution. What you can do is store the block's coordinates in the player's scoreboard in a procedure where the x, y, and z are still accurate, such as in the procedure for the trigger "when block is right clicked". And then, in the GUI code, use the ones stored on the scoreboard rather than the ones passed to the GUI procedure.

I think the reason why the GUI values are incorrect is because it gets the x, y, and z from a "extraData" buffer instead of just taking them in as parameters for some reason:

public MyGUIMenu(int id, Inventory inv, FriendlyByteBuf extraData){
// ...
// ...
if (extraData != null) {
pos = extraData.readBlockPos();
this.x = pos.getX();
this.y = pos.getY();
this.z = pos.getZ();
access = ContainerLevelAccess.create(world, pos);
}
// ...