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.

[1.19.4, SOLVED] Synched entity data does not persist after player dies and respawns

Featured Replies

Posted

I am implementing a custom entity, and so far I had to add synched entity data to it. For example:

private static final EntityDataAccessor<Boolean> DATA_IS_SOMETHING = SynchedEntityData.defineId(CustomEntity.class, EntityDataSerializers.BOOLEAN);

@Override
protected void defineSynchedData() {
    super.defineSynchedData();
    this.entityData.define(DATA_IS_SOMETHING, false);
}

Under certain conditions, the DATA_IS_SOMETHING of my entity will change to true. To my dismay though, when the player dies and then respawns, that entity's DATA_IS_SOMETHING resets back to false. Is this normal behavior? If so, then should I use capabilities instead? FYI I need the data to be synced between the server and client. 

Edited by LeeCrafts

  • 2 weeks later...

Did you saved the value of DATA_IS_SOMETHING to disk when the Entity is unloaded in addAdditionalSaveData and load it in readAdditionalSaveData?

  • Author

Wow, I didn't know that I had to do that, thank you!

This is my code, if any of you are curious:

// getter and setter methods that i already had
public boolean isSomething() {
    return this.entityData.get(DATA_IS_SOMETHING);
}

public void setSomething(boolean isSomething) {
    this.entityData.set(DATA_IS_SOMETHING, isSomething);
}

...

// what solved my issue
@Override
public void addAdditionalSaveData(@NotNull CompoundTag pCompound) {
    super.addAdditionalSaveData(pCompound);
    pCompound.putBoolean("IsSomething", this.isSomething());
}

@Override
public void readAdditionalSaveData(@NotNull CompoundTag pCompound) {
    super.readAdditionalSaveData(pCompound);
    this.setSomething(pCompound.getBoolean("IsSomething"));
}

 

  • LeeCrafts changed the title to [1.19.4, SOLVED] Synched entity data does not persist after player dies and respawns

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.