Search in sources :

Example 1 with Holder

use of net.minecraft.core.Holder in project Panthalassa by Sniffity.

the class FeaturePanthalassaAbstractCoral method place.

public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> p_159536_) {
    Random rand = p_159536_.random();
    WorldGenLevel worldgenlevel = p_159536_.level();
    Optional<Block> optional = Registry.BLOCK.getTag(BlockTags.CORAL_BLOCKS).flatMap((p_204734_) -> {
        return p_204734_.getRandomElement(rand);
    }).map(Holder::value);
    return this.placeFeature(worldgenlevel, rand, p_159536_.origin(), optional.get().defaultBlockState());
}
Also used : FeaturePlaceContext(net.minecraft.world.level.levelgen.feature.FeaturePlaceContext) NoneFeatureConfiguration(net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration) BaseCoralWallFanBlock(net.minecraft.world.level.block.BaseCoralWallFanBlock) Direction(net.minecraft.core.Direction) BlockState(net.minecraft.world.level.block.state.BlockState) Random(java.util.Random) Blocks(net.minecraft.world.level.block.Blocks) PanthalassaBlocks(com.github.sniffity.panthalassa.server.registry.PanthalassaBlocks) Registry(net.minecraft.core.Registry) Feature(net.minecraft.world.level.levelgen.feature.Feature) Codec(com.mojang.serialization.Codec) Holder(net.minecraft.core.Holder) WorldGenLevel(net.minecraft.world.level.WorldGenLevel) SeaPickleBlock(net.minecraft.world.level.block.SeaPickleBlock) BlockPos(net.minecraft.core.BlockPos) FluidState(net.minecraft.world.level.material.FluidState) BlockTags(net.minecraft.tags.BlockTags) Optional(java.util.Optional) LevelAccessor(net.minecraft.world.level.LevelAccessor) Block(net.minecraft.world.level.block.Block) Random(java.util.Random) Holder(net.minecraft.core.Holder) BaseCoralWallFanBlock(net.minecraft.world.level.block.BaseCoralWallFanBlock) SeaPickleBlock(net.minecraft.world.level.block.SeaPickleBlock) Block(net.minecraft.world.level.block.Block) WorldGenLevel(net.minecraft.world.level.WorldGenLevel)

Example 2 with Holder

use of net.minecraft.core.Holder 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)

Example 3 with Holder

use of net.minecraft.core.Holder in project Mohist by MohistMC.

the class CustomWorldChunkManager method biomeListToBiomeBaseList.

private static List<Holder<net.minecraft.world.level.biome.Biome>> biomeListToBiomeBaseList(List<Biome> biomes, net.minecraft.core.Registry<net.minecraft.world.level.biome.Biome> registry) {
    List<Holder<net.minecraft.world.level.biome.Biome>> biomeBases = new ArrayList<>();
    for (Biome biome : biomes) {
        Preconditions.checkArgument(biome != Biome.CUSTOM, "Cannot use the biome %s", biome);
        biomeBases.add(CraftBlock.biomeToBiomeBase(registry, biome));
    }
    return biomeBases;
}
Also used : Biome(org.bukkit.block.Biome) Holder(net.minecraft.core.Holder) ArrayList(java.util.ArrayList)

Example 4 with Holder

use of net.minecraft.core.Holder in project squaremap by jpenilla.

the class ChunkSnapshot method snapshot.

@SuppressWarnings({ "unchecked", "rawtypes" })
static ChunkSnapshot snapshot(final LevelChunk chunk, final boolean biomesOnly) {
    // AsyncCatcher.catchOp("Chunk Snapshot");
    final int sectionCount = chunk.getSectionsCount();
    final LevelChunkSection[] sections = chunk.getSections();
    final PalettedContainer<BlockState>[] states = new PalettedContainer[sectionCount];
    final PalettedContainer<Holder<Biome>>[] biomes = new PalettedContainer[sectionCount];
    final boolean[] empty = new boolean[sectionCount];
    final Heightmap heightmap = new Heightmap(chunk, Heightmap.Types.WORLD_SURFACE);
    if (!biomesOnly) {
        if (!chunk.hasPrimedHeightmap(Heightmap.Types.WORLD_SURFACE)) {
            throw new IllegalStateException("Expected WORLD_SURFACE heightmap to be present, but it wasn't! " + chunk.getPos());
        }
        heightmap.setRawData(chunk, Heightmap.Types.WORLD_SURFACE, chunk.getOrCreateHeightmapUnprimed(Heightmap.Types.WORLD_SURFACE).getRawData());
        for (int i = 0; i < sectionCount; i++) {
            final boolean sectionEmpty = sections[i].hasOnlyAir();
            empty[i] = sectionEmpty;
            if (sectionEmpty) {
                states[i] = ChunkSnapshotImpl.EMPTY_SECTION_BLOCK_STATES;
            } else {
                states[i] = sections[i].getStates().copy();
            }
            biomes[i] = sections[i].getBiomes().copy();
        }
    } else {
        for (int i = 0; i < sectionCount; i++) {
            biomes[i] = sections[i].getBiomes().copy();
        }
    }
    return new ChunkSnapshotImpl(LevelHeightAccessor.create(chunk.getMinBuildHeight(), chunk.getHeight()), states, biomes, Util.make(new EnumMap<>(Heightmap.Types.class), map -> map.put(Heightmap.Types.WORLD_SURFACE, heightmap)), empty, chunk.getLevel().dimensionType(), chunk.getPos());
}
Also used : BiomeManager(net.minecraft.world.level.biome.BiomeManager) LevelChunk(net.minecraft.world.level.chunk.LevelChunk) LevelHeightAccessor(net.minecraft.world.level.LevelHeightAccessor) NonNull(org.checkerframework.checker.nullness.qual.NonNull) EnumMap(java.util.EnumMap) BlockState(net.minecraft.world.level.block.state.BlockState) PalettedContainer(net.minecraft.world.level.chunk.PalettedContainer) DimensionType(net.minecraft.world.level.dimension.DimensionType) Biome(net.minecraft.world.level.biome.Biome) ChunkPos(net.minecraft.world.level.ChunkPos) Util(net.minecraft.Util) Holder(net.minecraft.core.Holder) BlockPos(net.minecraft.core.BlockPos) LevelChunkSection(net.minecraft.world.level.chunk.LevelChunkSection) FluidState(net.minecraft.world.level.material.FluidState) Heightmap(net.minecraft.world.level.levelgen.Heightmap) DefaultQualifier(org.checkerframework.framework.qual.DefaultQualifier) Heightmap(net.minecraft.world.level.levelgen.Heightmap) Biome(net.minecraft.world.level.biome.Biome) LevelChunkSection(net.minecraft.world.level.chunk.LevelChunkSection) EnumMap(java.util.EnumMap) PalettedContainer(net.minecraft.world.level.chunk.PalettedContainer)

Example 5 with Holder

use of net.minecraft.core.Holder in project AlexsMobs by Alex-the-666.

the class EntityMungus method transformBiome.

private void transformBiome(BlockPos pos, Holder<Biome> biome) {
    LevelChunk chunk = level.getChunkAt(pos);
    PalettedContainer<Holder<Biome>> container = getChunkBiomes(chunk);
    if (this.entityData.get(REVERTING)) {
        int lvt_4_1_ = chunk.getPos().getMinBlockX() >> 2;
        int yChunk = (int) this.getY() >> 2;
        int lvt_5_1_ = chunk.getPos().getMinBlockZ() >> 2;
        ChunkGenerator chunkgenerator = ((ServerLevel) level).getChunkSource().getGenerator();
        Biome b = null;
        for (int k = 0; k < 4; ++k) {
            for (int l = 0; l < 4; ++l) {
                for (int i1 = 0; i1 < 4; ++i1) {
                    container.getAndSetUnchecked(k, l, i1, chunkgenerator.getBiomeSource().getNoiseBiome(lvt_4_1_ + k, yChunk + l, lvt_5_1_ + i1, chunkgenerator.climateSampler()));
                }
            }
        }
        if (b != null && !level.isClientSide) {
            AlexsMobs.sendMSGToAll(new MessageMungusBiomeChange(this.getId(), pos.getX(), pos.getZ(), b.getRegistryName().toString()));
        }
    } else {
        if (biome == null) {
            return;
        }
        if (container != null && !level.isClientSide) {
            for (int biomeX = 0; biomeX < 4; ++biomeX) {
                for (int biomeY = 0; biomeY < 4; ++biomeY) {
                    for (int biomeZ = 0; biomeZ < 4; ++biomeZ) {
                        container.getAndSetUnchecked(biomeX, biomeY, biomeZ, biome);
                    }
                }
            }
            int id = this.getId();
            AlexsMobs.sendMSGToAll(new MessageMungusBiomeChange(this.getId(), pos.getX(), pos.getZ(), biome.value().getRegistryName().toString()));
        }
    }
}
Also used : MessageMungusBiomeChange(com.github.alexthe666.alexsmobs.message.MessageMungusBiomeChange) LevelChunk(net.minecraft.world.level.chunk.LevelChunk) Biome(net.minecraft.world.level.biome.Biome) Holder(net.minecraft.core.Holder) ChunkGenerator(net.minecraft.world.level.chunk.ChunkGenerator)

Aggregations

Holder (net.minecraft.core.Holder)19 BlockPos (net.minecraft.core.BlockPos)10 Biome (net.minecraft.world.level.biome.Biome)9 ArrayList (java.util.ArrayList)5 ChunkPos (net.minecraft.world.level.ChunkPos)5 Random (java.util.Random)4 Registry (net.minecraft.core.Registry)4 LevelChunk (net.minecraft.world.level.chunk.LevelChunk)4 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 ResourceLocation (net.minecraft.resources.ResourceLocation)3 LevelHeightAccessor (net.minecraft.world.level.LevelHeightAccessor)3 BlockState (net.minecraft.world.level.block.state.BlockState)3 LevelChunkSection (net.minecraft.world.level.chunk.LevelChunkSection)3 BiomeNMSImpl (com.denizenscript.denizen.nms.v1_18.impl.BiomeNMSImpl)2 Codec (com.mojang.serialization.Codec)2 Collections (java.util.Collections)2 Direction (net.minecraft.core.Direction)2 ResourceKey (net.minecraft.resources.ResourceKey)2