diff --git a/src/main/java/com/atsuishio/superbwarfare/block/ContainerBlock.java b/src/main/java/com/atsuishio/superbwarfare/block/ContainerBlock.java index 867ca8137..314db7474 100644 --- a/src/main/java/com/atsuishio/superbwarfare/block/ContainerBlock.java +++ b/src/main/java/com/atsuishio/superbwarfare/block/ContainerBlock.java @@ -149,5 +149,12 @@ public class ContainerBlock extends BaseEntityBlock { return this.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite()).setValue(OPENED, false); } + @Override + public ItemStack getCloneItemStack(BlockGetter pLevel, BlockPos pPos, BlockState pState) { + ItemStack itemstack = super.getCloneItemStack(pLevel, pPos, pState); + pLevel.getBlockEntity(pPos, ModBlockEntities.CONTAINER.get()).ifPresent((blockEntity) -> blockEntity.saveToItem(itemstack)); + return itemstack; + } + } diff --git a/src/main/java/com/atsuishio/superbwarfare/block/entity/ContainerBlockEntity.java b/src/main/java/com/atsuishio/superbwarfare/block/entity/ContainerBlockEntity.java index 0efdf0fd9..5c7f71cfc 100644 --- a/src/main/java/com/atsuishio/superbwarfare/block/entity/ContainerBlockEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/block/entity/ContainerBlockEntity.java @@ -12,6 +12,8 @@ import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundSource; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.entity.BlockEntity; @@ -117,4 +119,12 @@ public class ContainerBlockEntity extends BlockEntity implements GeoBlockEntity return this.saveWithFullMetadata(); } + @Override + public void saveToItem(ItemStack pStack) { + CompoundTag tag = new CompoundTag(); + if (this.entityType != null) { + tag.putString("EntityType", EntityType.getKey(this.entityType).toString()); + } + BlockItem.setBlockEntityData(pStack, this.getType(), tag); + } }