Jump to content

Recommended Posts

Posted

I have been working on a custom tile entity, and implemented some custom effects using a custom tile entity renderer.

 

However now I have realised that minecraft is only synchronising the tile entities when the player opens the container gui, with Container syncing an IInventory automatically, and things like the furnace container using ICrading.sendProgressBarUpdate and Container.updateProgressBar.

 

However this breaks my TileEntity on the client side until the client first opens it. I had initially thought the writeToNBT/readFromNBT would be used, but it seems even when the chunk is first loaded by the client this is not used.

 

So for tile entities that have visual effects beyond what a block id & meta value can convey (which appears to be how the furnace works visually), what exactly is the standard practice to send the data from the server to the client?

Posted
	public Packet getDescriptionPacket() {
NBTTagCompound nbtTag = new NBTTagCompound();
this.writeToNBT(nbtTag);
return new Packet132TileEntityData(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag);
}

public void onDataPacket(INetworkManager net, Packet132TileEntityData packet) {
readFromNBT(packet.data);
}

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

So if I understand correctly from looking through that code, once the chunk should be loaded for a client, it gets put into the EntityPlayerMP.loadedChunks list, and the description packet will get sent sometime soon after then, removing the chunk from that list.

 

So if a different player modifies the tileentity, or something else on the server but not the client (buildcraft pipes etc come to mind, but not got round to looking into that at all yet), I need to manually trigger the packet. I assume calling PlayerInstance.sendTileToAllPlayersWatchingChunk(myentity) using the instance from PlayerManager.getOrCreateChunkWatcher(chunkX,chunkZ,false) is the way to go?

Posted

Nope.  You don't need to manually do anything.  I use it for a chest-like object that displays its contents as part of the renderer.

 

There are some that generate as part of worldgen (so nothing involved clientside) and the item is already being displayed when I come across it.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Well I just did a multiplayer LAN test and it still not quite working.

 

[*]Player 1 creates the world

[*]Player 1 places my entity, and interacts with it to turn it on (provides fuel). The client and server state is synced at this point

[*]Player 2 joins the world, gets the description packet, with the entity being properly synced between server & 2 clients

[*]Player 2 interacts with the entity to disable it (removes all the fuel items)

[*]Player 2 and server state is synced, but the change is not sent to player 1 who still sees the enabled state (at least until the initial fuel would have run out, they interact with it and the Container instance syncs it since that covers the entire state at this time, or the entire chunk gets reloaded from scratch)

Posted

Admittedly I haven't actually tried that, for whatever reason my PC can't handle two clients and a server simultaneously.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Yes that causes the packet to be resent. Putting it in onInventoryUpdate seems to cover all the cases I can think of just now (not tested with buildcraft or other mods, but worked with a hopper so hopefully that means everything else will work, since the hopper will try and cast the tile entity to IInventory or ISidedInventory and work with that directly).

 

Only concern is the frequency and size of the packet especially when automation gets involved since that can practically add/remove an item every tick. But think I can reduce that a little with some effort.

 

I did take a peek at the Buildcraft code, but that has a massive amount of its own infrastructure and so would take me some time to figure out what its doing conceptually. But I think the stirling and combustion engines are pretty near to the same problem as my TileEntity (in that they respond visually to the state of their inventories and so need to keep some form of state synced all the time, not just on player GUI/Container interaction).

Posted

Packets are tiny as mouseballs.  I have an addon mod for Mystcraft that sends four max-sized packets to the server (and later retrieves them) and the delay is pretty small.

 

I mean, it's large enough to be noticed, but there's also a lot that goes on in order to retrieve the info.

 

Basically I'm saving and retrieving screen renders from the player.  The upper right corner is just a black box normally.

 

width=800 height=449http://s23.postimg.org/4az5t711n/2013_11_08_22_23_39.png[/img]

 

The retrieval takes about 1 second (even with the client and server on the same machine), so I suspect it's mostly due to disk IO.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.