添加集装箱clone机制
This commit is contained in:
parent
38c751818d
commit
f0b1d5f2c8
2 changed files with 17 additions and 0 deletions
|
@ -149,5 +149,12 @@ public class ContainerBlock extends BaseEntityBlock {
|
||||||
return this.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite()).setValue(OPENED, false);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,8 @@ import net.minecraft.sounds.SoundEvents;
|
||||||
import net.minecraft.sounds.SoundSource;
|
import net.minecraft.sounds.SoundSource;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.EntityType;
|
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.Level;
|
||||||
import net.minecraft.world.level.block.Blocks;
|
import net.minecraft.world.level.block.Blocks;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
|
@ -117,4 +119,12 @@ public class ContainerBlockEntity extends BlockEntity implements GeoBlockEntity
|
||||||
return this.saveWithFullMetadata();
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue