Skip to content

Commit

Permalink
fix: guard against #1017
Browse files Browse the repository at this point in the history
  • Loading branch information
klikli-dev committed Dec 21, 2023
1 parent 9a2ef81 commit 37741a7
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/main/java/com/klikli_dev/occultism/util/BlockEntityUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

package com.klikli_dev.occultism.util;

import com.klikli_dev.occultism.Occultism;
import com.klikli_dev.occultism.api.common.data.GlobalBlockPos;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
Expand Down Expand Up @@ -172,9 +173,14 @@ public static void onBlockChangeDropWithNbt(Block block, BlockState state, Level
public static ItemStack getItemWithNbt(Block block, BlockGetter level, BlockPos pos) {
ItemStack itemStack = new ItemStack(block);
BlockEntity blockEntity = level.getBlockEntity(pos);
CompoundTag CompoundTag = blockEntity.serializeNBT();
if (!CompoundTag.isEmpty()) {
itemStack.addTagElement("BlockEntityTag", CompoundTag);

if(blockEntity != null) {
CompoundTag CompoundTag = blockEntity.serializeNBT();
if (!CompoundTag.isEmpty()) {
itemStack.addTagElement("BlockEntityTag", CompoundTag);
}
} else {
Occultism.LOGGER.warn("BlockEntity is null for block {} at pos {}, cannot get ItemStack with NBT", block, pos);
}

return itemStack;
Expand Down

0 comments on commit 37741a7

Please sign in to comment.