use of artifacts.common.entity.MimicEntity in project artifacts by ochotonida.
the class CampsiteFeature method placeChest.
public void placeChest(WorldGenLevel level, BlockPos pos, Random random, Direction facing) {
if (random.nextFloat() < ModConfig.common.campsiteMimicChance.get()) {
MimicEntity mimic = ModEntityTypes.MIMIC.get().create(level.getLevel());
if (mimic != null) {
mimic.setDormant(true);
mimic.setFacing(facing);
mimic.setPos(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
level.addFreshEntity(mimic);
}
} else {
BlockState chest;
if (random.nextInt(8) == 0) {
setBlock(level, pos.below(), Blocks.TNT.defaultBlockState());
chest = Blocks.TRAPPED_CHEST.defaultBlockState();
setBlock(level, pos, Blocks.TRAPPED_CHEST.defaultBlockState().setValue(ChestBlock.FACING, Direction.Plane.HORIZONTAL.getRandomDirection(random)));
} else if (ModConfig.common.useModdedChests.get()) {
// noinspection deprecation
chest = Registry.BLOCK.getTag(Tags.Blocks.CHESTS_WOODEN).flatMap((set) -> set.getRandomElement(random)).map(Holder::value).orElse(Blocks.CHEST).defaultBlockState();
} else {
chest = Blocks.CHEST.defaultBlockState();
}
if (chest.hasProperty(BlockStateProperties.HORIZONTAL_FACING)) {
chest = chest.setValue(BlockStateProperties.HORIZONTAL_FACING, facing);
}
setBlock(level, pos, chest);
RandomizableContainerBlockEntity.setLootTable(level, random, pos, CHEST_LOOT);
}
}
Aggregations