Jump to content

[1.9.4] GuiHandler not getting correct TileEntity


yolp900

Recommended Posts

When I open my gui (using player.openGui() which calls the GuiHandler, that part works) I am trying to get the Tile Entity of the block that I'm aiming at. The GuiHandler recognizes that the Tile entity is an instance of my custom tile entity, however when I try to get data that's stored on the tile, I always get the default values of the tile, even if they're changed.

 

My code:

The GuiHandler

@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
TileEntity tile = world.getTileEntity(new BlockPos(x, y, z));
if (player != null) {
	if (ID == Reference.Guis.ElevatorLarge.getID() && tile instanceof TileEntityElevator) {
                        TileEntityElevator elevator = (TileEntityElevator) tile;
                        logger.log(tile.getYUp()) //This line always gives 0, even if there is a value stored in the TileEntityElevator.
		return new GuiElevator(world, new BlockPos(x, y, z));
	}
}
return null;
}

 

I hope this is enough information to find the problem... Thanks in advance!

Link to comment
Share on other sites

The client and server have separate instances of your

TileEntity

. The server's data is only synced to the client if you include it in the update tag/packet.

 

Override

TileEntity#getUpdateTag

to write the data that needs syncing to a compound tag and return it. Override

TileEntity#getUpdatePacket

to create and return an

SPacketUpdateTileEntity

using the compound tag returned by

TileEntity#getUpdateTag

. Override

TileEntity#onDataPacket

to read the

TileEntity

's data from the packet's compound tag.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.