Jump to content

[Solved] Keeping TileEntity client-side in sync every second


Narrakan

Recommended Posts

So here's the scenario:

I have a TileEntity which stores, among other things, four float variables. These variables should be processed (incremented, decremented) server-side, and should be kept in sync with the client every few ticks. I need to do that because the variables should be showed in a GUI to the player (similar to a furnace, but with additional stats).

 

This is what I've tried in the last couple of hours:

  • Keeping the container class and the GUI class in sync using updateCraftingResults + sendProgressBarUpdate (following the furnace example), but the problem is, I need to keep track of float types, and in non-local SMP these functions only use shorts, so I don't think that's really helpful
  • Adding getDescriptionPacket and onDataPacket as in the TileEntitySign and in other discussions I've checked, but from what I've seen, these functions only get called when the entity is first initialized, and unloaded, so they don't serve the purpose
  • Routing my packets through a PacketHandler, to deliver them to the client side, simply by decrementing a tickCounter and firing a PacketHandler.sendPacketToClient function when it reached 0. I don't know if there were any errors in the function, but the result is, it only was called on the server, so no effect on the client

 

I find myself stuck in this thing. Does any of you have some suggestions about this issue? Is there a way to keep the server and client side of a TileEntity in sync every second or so?

Link to comment
Share on other sites

use an IScheduledTickHandler with a schedule of 20 ticks?

Protip: try and find answers yourself before asking on the forum.

It's pretty likely that there is an answer.

 

Was I helpful? Give me a thank you!

 

 

width=635 height=903http://bit.ly/HZ03zy[/img]

 

 

Tired of waiting for mods to port to bukkit?

use BukkitForge! (now with a working version of WorldEdit!)

Link to comment
Share on other sites

Thanks for answering! I've had a look at the IScheduledTickHandler, and from what I've seen, I should set the TickType to SERVER, netTickSpacing to return 20 or so, and I should do something in the method tickEnd, am I right?

 

The problem is, I really don't know WHAT to do in this method. I mean, should I simply call getDescriptionPacket? Doesn't that function only return a well-formed packet and nothing else? My main problem is to allow the server entity to communicate somehow with the client entity.

Link to comment
Share on other sites

So you'd run whatever code you wanted to in tickEnd (or tickStart, doesn't matter), look at the wiki for a tutorial on how to use packets.

Protip: try and find answers yourself before asking on the forum.

It's pretty likely that there is an answer.

 

Was I helpful? Give me a thank you!

 

 

width=635 height=903http://bit.ly/HZ03zy[/img]

 

 

Tired of waiting for mods to port to bukkit?

use BukkitForge! (now with a working version of WorldEdit!)

Link to comment
Share on other sites

I think the cleaner solution is to use the built-in tile-entity packet sending stuff---you were on the right track.

 

The trick is, on server side when you need to send updates to clients, do world.markblocksasneedsupdate(x,y,z)  <sp? don't have my source ATM>, and it will force-resend the TE NBT tag/packet, just as if it was first initialized/sent to the client.  Run a counter in the TE entityUpdate method to mark as dirty every second (or just mark as dirty whenever you actually need to send the info).

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.