Search in sources :

Example 6 with Holder

use of net.minecraft.core.Holder in project Denizen by DenizenScript.

the class ChunkHelperImpl method setAllBiomes.

@Override
public void setAllBiomes(Chunk chunk, BiomeNMS biome) {
    Holder<Biome> nmsBiome = ((BiomeNMSImpl) biome).biomeBase;
    LevelChunk nmsChunk = ((CraftChunk) chunk).getHandle();
    ChunkPos chunkcoordintpair = nmsChunk.getPos();
    int i = QuartPos.fromBlock(chunkcoordintpair.getMinBlockX());
    int j = QuartPos.fromBlock(chunkcoordintpair.getMinBlockZ());
    LevelHeightAccessor levelheightaccessor = nmsChunk.getHeightAccessorForGeneration();
    for (int k = levelheightaccessor.getMinSection(); k < levelheightaccessor.getMaxSection(); ++k) {
        LevelChunkSection chunksection = nmsChunk.getSection(nmsChunk.getSectionIndexFromSectionY(k));
        PalettedContainer<Holder<Biome>> datapaletteblock = (PalettedContainer<Holder<Biome>>) chunksection.getBiomes();
        datapaletteblock.acquire();
        for (int l = 0; l < 4; ++l) {
            for (int i1 = 0; i1 < 4; ++i1) {
                for (int j1 = 0; j1 < 4; ++j1) {
                    datapaletteblock.getAndSetUnchecked(l, i1, j1, nmsBiome);
                }
            }
        }
        datapaletteblock.release();
    }
}
Also used : LevelHeightAccessor(net.minecraft.world.level.LevelHeightAccessor) Biome(net.minecraft.world.level.biome.Biome) LevelChunk(net.minecraft.world.level.chunk.LevelChunk) LevelChunkSection(net.minecraft.world.level.chunk.LevelChunkSection) Holder(net.minecraft.core.Holder) ChunkPos(net.minecraft.world.level.ChunkPos) CraftChunk(org.bukkit.craftbukkit.v1_19_R1.CraftChunk) BiomeNMSImpl(com.denizenscript.denizen.nms.v1_19.impl.BiomeNMSImpl) PalettedContainer(net.minecraft.world.level.chunk.PalettedContainer)

Example 7 with Holder

use of net.minecraft.core.Holder in project Denizen by DenizenScript.

the class ChunkHelperImpl method setAllBiomes.

@Override
public void setAllBiomes(Chunk chunk, BiomeNMS biome) {
    Holder<Biome> nmsBiome = ((BiomeNMSImpl) biome).biomeBase;
    LevelChunk nmsChunk = ((CraftChunk) chunk).getHandle();
    ChunkPos chunkcoordintpair = nmsChunk.getPos();
    int i = QuartPos.fromBlock(chunkcoordintpair.getMinBlockX());
    int j = QuartPos.fromBlock(chunkcoordintpair.getMinBlockZ());
    LevelHeightAccessor levelheightaccessor = nmsChunk.getHeightAccessorForGeneration();
    for (int k = levelheightaccessor.getMinSection(); k < levelheightaccessor.getMaxSection(); ++k) {
        LevelChunkSection chunksection = nmsChunk.getSection(nmsChunk.getSectionIndexFromSectionY(k));
        PalettedContainer<Holder<Biome>> datapaletteblock = chunksection.getBiomes();
        datapaletteblock.acquire();
        for (int l = 0; l < 4; ++l) {
            for (int i1 = 0; i1 < 4; ++i1) {
                for (int j1 = 0; j1 < 4; ++j1) {
                    datapaletteblock.getAndSetUnchecked(l, i1, j1, nmsBiome);
                }
            }
        }
        datapaletteblock.release();
    }
}
Also used : LevelHeightAccessor(net.minecraft.world.level.LevelHeightAccessor) Biome(net.minecraft.world.level.biome.Biome) LevelChunk(net.minecraft.world.level.chunk.LevelChunk) LevelChunkSection(net.minecraft.world.level.chunk.LevelChunkSection) Holder(net.minecraft.core.Holder) ChunkPos(net.minecraft.world.level.ChunkPos) CraftChunk(org.bukkit.craftbukkit.v1_18_R2.CraftChunk) BiomeNMSImpl(com.denizenscript.denizen.nms.v1_18.impl.BiomeNMSImpl)

Example 8 with Holder

use of net.minecraft.core.Holder in project PrimalMagick by daedalus4096.

the class AbstractPhasingTree method growTree.

@Override
public boolean growTree(ServerLevel world, ChunkGenerator chunkGenerator, BlockPos pos, BlockState state, Random rand) {
    Map<TimePhase, Holder<ConfiguredFeature<TreeConfiguration, ?>>> featureMap = this.getTreeFeaturesByPhase(rand, false);
    TimePhase currentPhase = this.getCurrentPhase(world);
    ConfiguredFeature<TreeConfiguration, ?> configuredFeature = featureMap.get(currentPhase).value();
    if (configuredFeature == null) {
        return false;
    } else {
        world.setBlock(pos, Blocks.AIR.defaultBlockState(), Block.UPDATE_INVISIBLE);
        if (configuredFeature.place(world, chunkGenerator, rand, pos)) {
            return true;
        } else {
            world.setBlock(pos, state, Block.UPDATE_INVISIBLE);
            return false;
        }
    }
}
Also used : TimePhase(com.verdantartifice.primalmagick.common.blockstates.properties.TimePhase) Holder(net.minecraft.core.Holder) TreeConfiguration(net.minecraft.world.level.levelgen.feature.configurations.TreeConfiguration)

Example 9 with Holder

use of net.minecraft.core.Holder in project BYG by AOCAWOL.

the class BYGUtil method createBiomesFromBiomeData.

@SuppressWarnings("unchecked")
public static List<Holder<Biome>> createBiomesFromBiomeData(Registry<Biome> biomeRegistry, LayersBiomeData... layersBiomeDatas) {
    List<Holder<Biome>> biomes = new ArrayList<>();
    for (LayersBiomeData layersBiomeData : layersBiomeDatas) {
        ImmutableList<WeightedEntry.Wrapper<ResourceKey<Biome>>> items = ((WeightedListAccess<WeightedEntry.Wrapper<ResourceKey<Biome>>>) layersBiomeData.biomeWeights()).byg_getItems();
        for (WeightedEntry.Wrapper<ResourceKey<Biome>> key : items) {
            ResourceKey<Biome> resourceKey = key.getData();
            Optional<Holder<Biome>> biome = biomeRegistry.getHolder(resourceKey);
            if (biome.isPresent()) {
                biomes.add(biome.get());
            } else {
                BYG.LOGGER.info("\"" + resourceKey.location() + "\" is not a value in the biome registry at this point, ignore this warning if the data pack containing this biome is not yet added during world creation.");
            }
        }
    }
    return biomes;
}
Also used : LayersBiomeData(potionstudios.byg.common.world.biome.LayersBiomeData) Holder(net.minecraft.core.Holder) WeightedListAccess(potionstudios.byg.mixin.access.WeightedListAccess) ResourceKey(net.minecraft.resources.ResourceKey) Biome(net.minecraft.world.level.biome.Biome) WeightedEntry(net.minecraft.util.random.WeightedEntry)

Example 10 with Holder

use of net.minecraft.core.Holder in project BYG by AOCAWOL.

the class LargeLakeFeature method place.

public boolean place(WorldGenLevel world, ChunkGenerator chunkGenerator, Random random, BlockPos blockPos, LargeLakeFeatureConfig config) {
    setSeed(world.getSeed());
    BlockPos.MutableBlockPos mutable = new BlockPos.MutableBlockPos().set(blockPos);
    BlockPos.MutableBlockPos mutable2 = new BlockPos.MutableBlockPos().set(mutable);
    int xRadius = config.getRandomRadius(random) / 2;
    int yRadius = config.getRandomDepth(random);
    int zRadius = config.getRandomRadius(random) / 2;
    List<BlockPos> positions = new ArrayList<>();
    List<BlockPos> edgePositions = new ArrayList<>();
    Function<BlockPos, BlockState> lakeBorderStateFunction = (blockPos3) -> config.borderStateProvider().getState(random, blockPos3);
    Function<BlockPos, BlockState> lakeFloorStateFunction = (blockPos3) -> config.lakeFloorStateProvider().getState(random, blockPos3);
    for (int x = -xRadius; x <= xRadius; x++) {
        for (int z = -zRadius; z <= zRadius; z++) {
            for (int y = -yRadius; y <= 0; y++) {
                mutable2.set(mutable).move(x, y, z);
                // Credits to Hex_26 for this equation!
                double xSquared = Math.pow(x, 2);
                double ySquared = Math.pow(y, 2);
                double zSquared = Math.pow(z, 2);
                double squaredDistance = xSquared + ySquared + zSquared;
                double equationResult = xSquared / Math.pow(xRadius, 2) + ySquared / Math.pow(yRadius, 2) + zSquared / Math.pow(zRadius, 2);
                double threshold = 1 + 1.4 * fastNoise.GetNoise(mutable2.getX(), mutable2.getY() * 2, mutable2.getZ());
                if (equationResult >= threshold) {
                    continue;
                }
                if (squaredDistance <= xRadius * zRadius) {
                    BlockPos immutable = mutable2.immutable();
                    if (y < 0) {
                        positions.add(immutable);
                    }
                } else {
                    double sizeAmplifier = 1.6;
                    if (y >= 0 && squaredDistance <= ((xRadius + (xRadius * sizeAmplifier)) * (zRadius + (zRadius * sizeAmplifier)))) {
                        edgePositions.add(mutable2.immutable());
                    }
                }
            }
        }
    }
    int waterLevel = blockPos.getY();
    for (BlockPos position : positions) {
        waterLevel = Math.min(world.getHeight(Heightmap.Types.WORLD_SURFACE, position.getX(), position.getZ()) - 1, waterLevel);
    }
    ArrayList<Pair<BlockPos, BlockState>> fallingBlocks = new ArrayList<>();
    ArrayList<BlockPos> lakeSurfacePositions = new ArrayList<>();
    BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos();
    for (BlockPos position : positions) {
        BlockPos.MutableBlockPos mutable3 = mutableBlockPos.set(position.getX(), Math.min(position.getY(), waterLevel), position.getZ());
        for (int i = mutable3.getY(); i <= waterLevel; i++) {
            setLakeBlocks(world, mutable3.getY() == waterLevel ? lakeBorderStateFunction : lakeFloorStateFunction, mutable3);
            mutable3.move(Direction.UP);
        }
        lakeSurfacePositions.add(mutable3.immutable());
        BlockPos.MutableBlockPos mutable4 = new BlockPos.MutableBlockPos().set(mutable3);
        for (int i = 0; i < 10; i++) {
            BlockState blockStateAbove = world.getBlockState(mutable4);
            Block stateAboveBlock = blockStateAbove.getBlock();
            if (stateAboveBlock instanceof FallingBlock) {
                fallingBlocks.add(new Pair<>(mutable4.immutable(), blockStateAbove));
                world.removeBlock(mutable4, false);
            } else if (canReplace(blockStateAbove)) {
                world.removeBlock(mutable4, false);
            } else {
                break;
            }
            mutable4.move(Direction.UP);
        }
    }
    for (BlockPos lakeSurfacePosition : lakeSurfacePositions) {
        for (Holder<PlacedFeature> lakeSurfaceFeature : config.lakeSurfaceFeatures()) {
            lakeSurfaceFeature.value().place(world, chunkGenerator, random, lakeSurfacePosition);
        }
    }
    for (BlockPos lakeEdgePosition : edgePositions) {
        for (Holder<PlacedFeature> lakeSurfaceFeature : config.lakeEdgeFeatures()) {
            lakeSurfaceFeature.value().place(world, chunkGenerator, random, lakeEdgePosition);
        }
        if (DEBUG) {
            world.setBlock(lakeEdgePosition.offset(0, 6, 0), Blocks.GLOWSTONE.defaultBlockState(), 2);
        }
    }
    return true;
}
Also used : MLBlockTags(potionstudios.byg.util.MLBlockTags) Direction(net.minecraft.core.Direction) FallingBlock(net.minecraft.world.level.block.FallingBlock) BlockState(net.minecraft.world.level.block.state.BlockState) FastNoise(potionstudios.byg.common.world.math.noise.fastnoise.FastNoise) Random(java.util.Random) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Holder(net.minecraft.core.Holder) WorldGenLevel(net.minecraft.world.level.WorldGenLevel) BlockTags(net.minecraft.tags.BlockTags) Fluids(net.minecraft.world.level.material.Fluids) FeaturePlaceContext(net.minecraft.world.level.levelgen.feature.FeaturePlaceContext) Pair(com.mojang.datafixers.util.Pair) Material(net.minecraft.world.level.material.Material) Blocks(net.minecraft.world.level.block.Blocks) ChunkGenerator(net.minecraft.world.level.chunk.ChunkGenerator) Feature(net.minecraft.world.level.levelgen.feature.Feature) List(java.util.List) Codec(com.mojang.serialization.Codec) BlockPos(net.minecraft.core.BlockPos) LargeLakeFeatureConfig(potionstudios.byg.common.world.feature.config.LargeLakeFeatureConfig) PlacedFeature(net.minecraft.world.level.levelgen.placement.PlacedFeature) Heightmap(net.minecraft.world.level.levelgen.Heightmap) Block(net.minecraft.world.level.block.Block) ArrayList(java.util.ArrayList) FallingBlock(net.minecraft.world.level.block.FallingBlock) BlockState(net.minecraft.world.level.block.state.BlockState) FallingBlock(net.minecraft.world.level.block.FallingBlock) Block(net.minecraft.world.level.block.Block) BlockPos(net.minecraft.core.BlockPos) PlacedFeature(net.minecraft.world.level.levelgen.placement.PlacedFeature) Pair(com.mojang.datafixers.util.Pair)

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