Skip to content

Commit

Permalink
fix: Fix BalmData not persisting after death on Forge
Browse files Browse the repository at this point in the history
  • Loading branch information
BlayTheNinth committed Jun 24, 2024
1 parent 187d48d commit 3b12ee5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.core.component.DataComponents;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.RandomSource;
import net.minecraft.world.Container;
import net.minecraft.world.InteractionHand;
Expand Down Expand Up @@ -49,6 +50,12 @@ public boolean growCrop(ItemStack itemStack, Level level, BlockPos pos, Player p
@Override
public CompoundTag getPersistentData(Entity entity) {
CompoundTag persistentData = entity.getPersistentData();
if (entity instanceof ServerPlayer) {
CompoundTag persistedTag = persistentData.getCompound(ServerPlayer.PERSISTED_NBT_TAG);
persistentData.put(ServerPlayer.PERSISTED_NBT_TAG, persistedTag);
persistentData = persistedTag;
}

CompoundTag balmData = persistentData.getCompound("BalmData");
if (balmData.isEmpty()) {
// If we have no data, try to import from Fabric in case the world was migrated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ public CompoundTag getPersistentData(Entity entity) {
}

CompoundTag balmData = persistentData.getCompound("BalmData");
if (balmData.size() == 0) {
if (balmData.isEmpty()) {
// If we have no data, try to import from Fabric in case the world was migrated
balmData = ((BalmEntity) entity).getFabricBalmData();
}
persistentData.put("BalmData", balmData);
if (!balmData.isEmpty()) {
persistentData.put("BalmData", balmData);
}

return balmData;
}
Expand Down

0 comments on commit 3b12ee5

Please sign in to comment.