Jump to content

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


Recommended Posts

Posted

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?

Posted

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.

Posted

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!)

Posted

Well, the wiki wasn't really helpful this time :-\

 

Anyway, after an extensive google search I got it to work by using the PacketDispatcher.sendPacketToAllPlayers in tickEnd, now it is updating as it should. Thanks for pointing me in the right direction.

Posted

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).

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Please read the FAQ and post logs as described there.
    • Upon starting the server I get; [main/ERROR] [minecraft/Main]: Failed to start the minecraft server net.minecraftforge.fml.LoadingFailedException: Loading errors encountered: [     Framework (framework) has failed to load correctly §7java.lang.NoClassDefFoundError: net/minecraft/client/gui/components/toasts/Toast ] I suspect there is a (possibly a few) client-only mods installed on my server. Any help would be appreciated! (Yes I know there are a lot of mods...) Here is the crash log:   https://paste.ee/p/pRz5mhMl#s=0
    • That's basically what the failure does, my apologies for failing to specify.  It just tries again on the next tick until it detects the entities for that chunk are loaded, and then tries to load the entity.  From there it gets into different failure states depending on what goes wrong, but in short, if the entity fails to load once the entity list becomes available, the request is cleared and must be resubmitted by the end user.  There should be few cases where that actually happens. Yes, that is my understanding of forceloading.  That's why on a successful summon, it removes the forceload.  Otherwise it does just leave the chunks loaded long term. Thank you for your help, any knowledge is useful!  I don't often mess with forceloading and my prior experience is 1.16 so I'm also a bit out of my depth haha.
    • I will have to do more research about 1.18 chunk loading. You were unclear about how your code manages with the entity load failure. If you simply used a loop, I suggest submitting a tick task to the next tick which does the same thing, checking if the entities are loaded and if so teleporting the right one else submitting another tick task etc. Also I think forceloading permanently force loads the chunk, and it only starts to unload when you make a subsequent call to mark the chunk as not forceloaded. I may be completely wrong, I dont know much about 1.18, most of my experience is 1.20. Good luck I hope you figure it out after all this time 😅
    • i managed to fix it by reinstalling the modpack and re-add all the extra mods I've had previously.
  • Topics

×
×
  • Create New...

Important Information

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