Jump to content

A question on syncing tile entites between client and server


Recommended Posts

I apologize that I'm posting something similar to what's been asked before, but I've seen a few other topics on this and I've looked at the tutorials, but the tutorials feel kind of incomplete and the forum topics seem to assume more knowledge on this than I have.


I'm trying to build a mod called Deep Storage Tanks, which provides a single block liquid tank that holds up to 2 billion millibuckets (similar to the way a Deep Storage Unit from MFR works, but for liquid).  Storing and removing the liquid from the tank works fine, but I'm trying to build a simple GUI that will tell you what liquid is in the tank and how much of it is there, and the GUI always says that the tank is empty regardless of what's in it.  As far as I can tell, this is an issue of syncing the tile entity between the client and the server -- that is, the server has the correct amount of fluid in it, but the tile entity on the client side just has an empty tank.  Note that at the moment I'm not trying to allow the player to do anything to the block from the GUI, so the sync only needs to be from the server to the player, and not vice-versa (most examples seem to center around sending a packet from the player to the server).


I'm also a bit confused about how exactly markBlockForUpdate (or whatever that function is called) works.  What mechanism does it actually use to send a data packet?


I've inspected the source to some other modules, but it hasn't been particularly helpful.  Buildcraft, for instance, has multiple layers of abstraction, so it's difficult to tell what's going on in terms of network packets without poking through a ton of different files and getting lost.


Looking around, I'm getting some conflicting information about how to deal with this.  One forum post seemed to suggest that I only need to override TileEntity.getDescriptionPacket() and TileEntity.onDataPacket(), while the tutorials seem to indicate that I need a packet handler class.  It's also not clear whether I should use Packet250CustomPayload or the packet class that appears to be meant for TileEntities.  I'm also curious if there's some standard way to send a data packet about a LiquidStack or if I need to build that myself (which is what I'm trying to do at the moment, but I'd perfer to avoid reinventing the wheel if possible).


Here's my code if anyone wants to look at it.  It's MIT licensed, so feel free to use it for whatever.




Link to comment
Share on other sites

i imagine that when you say the tutorial seems unfinished its because at the begining it says :"THIS PAGE IS UNDER CONSTRUCTION"




yeah sorry about that i just never took time to actually finish that one. But hum yeah basicly markBlockForUpdate called on server side will send a Packet32TileEntity to aaaaall clients in range , while calling it client side will request a re-render of the chunk (since chunk are rendered in bulk) btw when the client receive a Packet32TE he will re-render anyway.


the only thing you should have to do to actually sync is server side call markBlockForUpdate and override read/write to/from nbt (the method inherited from TileEntity) and also override this function:



public void onDataPacket(INetworkManager net, Packet132TileEntityData packet) {




im not sure why TileEntity is not overriding it himself cuz that seems kindof necessary but wtv

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

That worked, thank you. :)


One other question:  When I have a liquid flowing into the tank, the amount of liquid in the tank changes every tick, which means I'm sending an update packet every tick.  This is a huge waste of bandwidth, as I think the GUI could update once per second and be perfectly usable.  Is there some standard way of scheduling update packets?

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.