Jump to content

[1.7/1.8] Update TileEntity from GUI?


zerofall

Recommended Posts

I have a TileEntity that I need to update from the GUI. I simply need to send an Integer from the client to the server-side TileEntity. I assume I need to use packets to do this, but I'm not sure how. My TileEntity can already handle packets:

 

     

        @Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
	readFromNBT(pkt.getNbtCompound());
}

 

which works fine. I guess I need to figure out how to send a packet to the tile entity from the GUI. I tried this:

 

        NBTTagCompound nbtTag = new NBTTagCompound();
        nbtTag.setInteger("MyInteger", myInteger);
S35PacketUpdateTileEntity packet = new S35PacketUpdateTileEntity(this.tileEntity.getPos(), 1, nbtTag);
this.mc.thePlayer.sendQueue.addToSendQueue(packet);

 

but this doesn't work. What is the best way to do this?

Link to comment
Share on other sites

Ok, I think I am close... but I am stuck on something. On the thread you linked is this message:

 

@Ives: That is more or less correct, but you don't need to send the coordinates of the TileEntity, as the server knows which TE the player is interacting with through the player's current Container. That also ensures that they cannot just change the values in any arbitrary TileEntity (prevents possible hacks).

If you have further questions, please open a new Thread.

 

On the packet handler, how can I access the current TileEntity/Container the player is interacting with without sending the coordinates through the packet? I assume is must be ctx.getServerHandler().playerEntity.something?

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.