Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

  • Author
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.

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.