Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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!

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.

  • Author

Wow, that actually worked on the first time!  ;D

Thanks a lot! I still have a few things I need to learn about client-server handling - what happens automatically and what doesn't (for example: this  ;))

Thanks!

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.