Search in sources :

Example 1 with MimicEntity

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);
    }
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) NoneFeatureConfiguration(net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration) Tags(net.minecraftforge.common.Tags) RandomizableContainerBlockEntity(net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity) Direction(net.minecraft.core.Direction) BlockState(net.minecraft.world.level.block.state.BlockState) Random(java.util.Random) ArrayList(java.util.ArrayList) Registry(net.minecraft.core.Registry) Holder(net.minecraft.core.Holder) WorldGenLevel(net.minecraft.world.level.WorldGenLevel) net.minecraft.world.level.block(net.minecraft.world.level.block) FeaturePlaceContext(net.minecraft.world.level.levelgen.feature.FeaturePlaceContext) BlockStateProperties(net.minecraft.world.level.block.state.properties.BlockStateProperties) BedPart(net.minecraft.world.level.block.state.properties.BedPart) BlockStateProvider(net.minecraft.world.level.levelgen.feature.stateproviders.BlockStateProvider) SimpleWeightedRandomList(net.minecraft.util.random.SimpleWeightedRandomList) Artifacts(artifacts.Artifacts) WeightedStateProvider(net.minecraft.world.level.levelgen.feature.stateproviders.WeightedStateProvider) Collectors(java.util.stream.Collectors) Feature(net.minecraft.world.level.levelgen.feature.Feature) List(java.util.List) BlockPos(net.minecraft.core.BlockPos) ModEntityTypes(artifacts.common.init.ModEntityTypes) ModConfig(artifacts.common.config.ModConfig) MimicEntity(artifacts.common.entity.MimicEntity) Collections(java.util.Collections) BlockState(net.minecraft.world.level.block.state.BlockState) Holder(net.minecraft.core.Holder) MimicEntity(artifacts.common.entity.MimicEntity)

Aggregations

Artifacts (artifacts.Artifacts)1 ModConfig (artifacts.common.config.ModConfig)1 MimicEntity (artifacts.common.entity.MimicEntity)1 ModEntityTypes (artifacts.common.init.ModEntityTypes)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Random (java.util.Random)1 Collectors (java.util.stream.Collectors)1 BlockPos (net.minecraft.core.BlockPos)1 Direction (net.minecraft.core.Direction)1 Holder (net.minecraft.core.Holder)1 Registry (net.minecraft.core.Registry)1 ResourceLocation (net.minecraft.resources.ResourceLocation)1 SimpleWeightedRandomList (net.minecraft.util.random.SimpleWeightedRandomList)1 WorldGenLevel (net.minecraft.world.level.WorldGenLevel)1 net.minecraft.world.level.block (net.minecraft.world.level.block)1 RandomizableContainerBlockEntity (net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity)1 BlockState (net.minecraft.world.level.block.state.BlockState)1 BedPart (net.minecraft.world.level.block.state.properties.BedPart)1