LeeCrafts Posted October 6, 2023 Share Posted October 6, 2023 (edited) 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 November 2, 2023 by LeeCrafts Quote Link to comment Share on other sites More sharing options...
LeeCrafts Posted October 20, 2023 Author Share Posted October 20, 2023 bump Quote Link to comment Share on other sites More sharing options...
Luis_ST Posted October 28, 2023 Share Posted October 28, 2023 Did you saved the value of DATA_IS_SOMETHING to disk when the Entity is unloaded in addAdditionalSaveData and load it in readAdditionalSaveData? Quote Link to comment Share on other sites More sharing options...
LeeCrafts Posted November 2, 2023 Author Share Posted November 2, 2023 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")); } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.