Jump to content

Synchronizing client TileEntity to server?


Recommended Posts

Hi all,


How can I (with 1.7.10) synchronize changes to the client TileEntity to the server? I have a GUI where I want to modify some settings in my tileentity and I want it to be saved on the server side. I found some tutorials on the web but they are for older versions and I have trouble adapting them to latest forge.


Any help here?



Link to comment
Share on other sites

Don't modify the client TE from the GUI. Send a (custom) packet to the server to notify it that the user e.g. pressed a button and then let the server update the data.


Yes I gathered that. But how? I can't find example code on this (at least example code that still works in this version of forge)

Link to comment
Share on other sites

Ok, thanks to your help I managed to get a bit further but I'm still stuck with a problem. The problem I have now is that when my GUI updates a value in the tile entity (does this by sending a message) the server version of the tile entity is updated correctly (and saved when I exit the game) but the client tile entity does not reflect this change (even though I call markBlockForUpdate). I have to save and load the world again before the client tile entity is updated.


Here is (in summary) what I have done:


I made a simple message channel and registered my message with:


        INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel("rftools");
        INSTANCE.registerMessage(PacketRFMonitor.class, PacketRFMonitor.class, nextID(), Side.SERVER);


PacketRFMonitor basically looks like this:


public class PacketRFMonitor implements IMessage, IMessageHandler<PacketRFMonitor, IMessage> {

    public void fromBytes(ByteBuf buf) {

    public void toBytes(ByteBuf buf) {

    public IMessage onMessage(PacketRFMonitor message, MessageContext ctx) {
        EntityPlayer player = ctx.getServerHandler().playerEntity;
        TileEntity te = player.worldObj.getTileEntity(message.x, message.y, message.z);
        if(!(te instanceof RFMonitorBlockTileEntity)) {
            System.out.println("createPowerMonitotPacket: TileEntity is not a RFMonitorBlockTileEntity!");
            return null;
        RFMonitorBlockTileEntity monitorBlockTileEntity = (RFMonitorBlockTileEntity) te;
        player.worldObj.markBlockForUpdate(x, y, z);
        return null;


In my tile entity class I have the following:


public class RFMonitorBlockTileEntity extends TileEntity {
    private int monitorX = -1;
    private int monitorY = -1;  // Invalid y coordinate so we know it is not initialized yet
    private int monitorZ = -1;

    ... setters and getters ....

    public Packet getDescriptionPacket() {
        NBTTagCompound nbtTag = new NBTTagCompound();
        return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag);

    public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) {

    public void readFromNBT(NBTTagCompound tagCompound) {
        monitorX = tagCompound.getInteger("monitorX");
        monitorY = tagCompound.getInteger("monitorY");
        monitorZ = tagCompound.getInteger("monitorZ");

    public void writeToNBT(NBTTagCompound tagCompound) {
        tagCompound.setInteger("monitorX", monitorX);
        tagCompound.setInteger("monitorY", monitorY);
        tagCompound.setInteger("monitorZ", monitorZ);


Then in my GUI code I have this:


    private void sendChangeToServer(Coordinate c) {
        PacketHandler.INSTANCE.sendToServer(new PacketRFMonitor(monitorBlockTileEntity.xCoord, monitorBlockTileEntity.yCoord, monitorBlockTileEntity.zCoord, c));


My full source code can be seen on github:




As far as I know I have done everything correctly but apparently not. I can of course manually change the client tile entity in the gui code but I have been told not to do that and I prefer to do things the proper way.


Any ideas what could be wrong here?




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.

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.

  • Create New...

Important Information

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