Jump to content

[Solved] [1.13.2] Sync Capability on Spawn


Recommended Posts

I have a capability attached to an entity. It's saved to nbt when you exit the world. When I next load the world I want that capability to be synced to the client (after it has loaded the data back from the serialised nbt).


I have tried sending a packet to the client using the EntityJoinWorldEvent, however, at this point the capability hasn't been attached to the entity on client, so the packet is useless.


At what point can I send a packet to sync the client and server? Is this the correct way to sync the two on the world load?

Edited by harison513
Link to comment
Share on other sites

37 minutes ago, diesieben07 said:

To keep entity data up to date on the client you must sync in the following places:

  • PlayerEvent.StartTracking when PlayerEvent.StartTracking#getTarget is your entity (or has your capability in this case). Send the packet to PlayerEvent.StartTracking#getEntityPlayer.
  • EntityJoinWorldEvent when EntityJoinWorldEvent#getEntity is your entity (or has your capability in this case). Send the packet to all players tracking the entity (EntityTracker#getTrackingPlayers or use PacketDistributor.TRACKING_ENTITY when using NetworkRegistry.newSimpleChannel).
  • Whenever the data changes send the packet to all players tracking the entity (see above).

Didn't know PlayerEvent.StartTracking existed so thanks, that has solved my problem.

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.