Tsuk1 Posted January 2 Posted January 2 (edited) Hello! So, I'm having a problem where I always lose the data when I exit and rejoin a world, I think my problem is with the deserialization and serialization of the NBT, but i'm not sure and i don't know how to fix it. I think my error is somewhere here: import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.CapabilityManager; import net.minecraftforge.common.capabilities.CapabilityToken; import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.common.util.INBTSerializable; import net.minecraftforge.common.util.LazyOptional; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public class PlayerGodParentProvider implements ICapabilityProvider, INBTSerializable<CompoundTag> { public static Capability<PlayerGodParent> PLAYER_GOD_PARENT = CapabilityManager.get(new CapabilityToken<PlayerGodParent>() { }); private PlayerGodParent godParent = null; private final LazyOptional<PlayerGodParent> optional = LazyOptional.of(this::createPlayerGodParent); private PlayerGodParent createPlayerGodParent() { if(this.godParent == null) { this.godParent = new PlayerGodParent(); } return this.godParent; } @Override public @NotNull <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side) { if(cap == PLAYER_GOD_PARENT) { return optional.cast(); } return LazyOptional.empty(); } @Override public CompoundTag serializeNBT() { CompoundTag nbt = new CompoundTag(); createPlayerGodParent().saveNBTData(nbt); return nbt; } @Override public void deserializeNBT(CompoundTag nbt) { createPlayerGodParent().loadNBTData(nbt); } } The whole repo is here: https://github.com/P3terD/myths-mod/tree/main Edited January 2 by Tsuk1 Quote
Tsuk1 Posted January 2 Author Posted January 2 Solved, I was just saving the wrong value on the nbt Quote
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.