Search in sources :

Example 11 with NoiseColumn

use of net.minecraft.world.level.NoiseColumn in project Bumblezone by TelepathicGrunt.

the class HoneyCaveRoomStructure method validSpot.

private static boolean validSpot(ChunkGenerator chunkGenerator, BlockPos centerPos, LevelHeightAccessor heightLimitView) {
    BlockPos.MutableBlockPos mutable = new BlockPos.MutableBlockPos();
    int radius = 24;
    for (int x = -radius; x <= radius; x += radius) {
        for (int z = -radius; z <= radius; z += radius) {
            mutable.set(centerPos).move(x, 0, z);
            NoiseColumn columnOfBlocks = chunkGenerator.getBaseColumn(mutable.getX(), mutable.getZ(), heightLimitView);
            BlockState state = columnOfBlocks.getBlock(mutable.getY());
            BlockState aboveState = columnOfBlocks.getBlock(mutable.getY() + 15);
            if (state.isAir() || !state.getFluidState().isEmpty() || aboveState.isAir() || !aboveState.getFluidState().isEmpty()) {
                return false;
            }
        }
    }
    return true;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) NoiseColumn(net.minecraft.world.level.NoiseColumn) BlockPos(net.minecraft.core.BlockPos)

Example 12 with NoiseColumn

use of net.minecraft.world.level.NoiseColumn in project Bumblezone by TelepathicGrunt.

the class PollinatedStreamStructure method validSpot.

private static boolean validSpot(ChunkGenerator chunkGenerator, BlockPos centerPos, LevelHeightAccessor heightLimitView) {
    BlockPos.MutableBlockPos mutable = new BlockPos.MutableBlockPos();
    mutable.set(centerPos);
    NoiseColumn columnOfBlocks;
    for (Direction direction : Direction.Plane.HORIZONTAL) {
        mutable.set(centerPos).move(direction, 12);
        columnOfBlocks = chunkGenerator.getBaseColumn(mutable.getX(), mutable.getZ(), heightLimitView);
        BlockState state = columnOfBlocks.getBlock(41);
        if (!state.getMaterial().blocksMotion()) {
            return false;
        }
        mutable.set(centerPos).move(direction, 55);
        columnOfBlocks = chunkGenerator.getBaseColumn(mutable.getX(), mutable.getZ(), heightLimitView);
        state = columnOfBlocks.getBlock(41);
        if (!state.getMaterial().blocksMotion()) {
            return false;
        }
    }
    return true;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) NoiseColumn(net.minecraft.world.level.NoiseColumn) BlockPos(net.minecraft.core.BlockPos) Direction(net.minecraft.core.Direction)

Example 13 with NoiseColumn

use of net.minecraft.world.level.NoiseColumn in project Supplementaries by MehVahdJukaar.

the class WaySignStructure method isPosNotValid.

/**
 * This is where extra checks can be done to determine if the structure can spawn here.
 * This only needs to be overridden if you're adding additional spawn conditions.
 * <p>
 * Fun fact, if you set your structure separation/spacing to be 0/1, you can use
 * func_230363_a_ to return true only if certain chunk coordinates are passed in
 * which allows you to spawn structures only at certain coordinates in the world.
 * <p>
 * Notice how the biome is also passed in. Though, you are not going to
 * do any biome checking here as you should've added this structure to
 * the biomes you wanted already with the biome load event.
 * <p>
 * Basically, this method is used for determining if the land is at a suitable height,
 * if certain other structures are too close or not, or some other restrictive condition.
 * <p>
 * For example, Pillager Outposts added a check to make sure it cannot spawn within 10 chunk of a Village.
 * (Bedrock Edition seems to not have the same check)
 * <p>
 * <p>
 * Also, please for the love of god, do not do dimension checking here. If you do and
 * another mod's dimension is trying to spawn your structure, the locate
 * command will make minecraft hang forever and break the game.
 * <p>
 * Instead, use the addDimensionalSpacing method in StructureTutorialMain class.
 * If you check for the dimension there and do not add your structure's
 * spacing into the chunk generator, the structure will not spawn in that dimension!
 */
private static boolean isPosNotValid(ChunkGenerator gen, int x, int z, Set<Integer> heightMap, LevelHeightAccessor heightLimitView) {
    // Grab height of land. Will stop at first non-air block.
    int y = gen.getFirstOccupiedHeight(x, z, Heightmap.Types.WORLD_SURFACE_WG, heightLimitView);
    NoiseColumn noisecolumn = gen.getBaseColumn(x, z, heightLimitView);
    // Grabs column of blocks at given position. In overworld, this column will be made of stone, water, and air.
    // In nether, it will be netherrack, lava, and air. End will only be endstone and air. It depends on what block
    // the chunk generator will place for that dimension.
    // Combine the column of blocks with land height and you get the top block itself which you can spawnParticleOnBoundingBox.
    BlockState state = noisecolumn.getBlock(y);
    /*
        if (types.isOpaque().test(state)){
            heightMap.add(y);
            return true;
        }
        */
    try {
        if (state.getFluidState().isEmpty()) {
            heightMap.add(y);
            return false;
        }
    } catch (Exception e) {
        return true;
    }
    return true;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) NoiseColumn(net.minecraft.world.level.NoiseColumn)

Example 14 with NoiseColumn

use of net.minecraft.world.level.NoiseColumn in project TutorialV3 by McJty.

the class PortalStructure method findSuitableSpot.

@NotNull
private static BlockPos findSuitableSpot(PieceGeneratorSupplier.Context<JigsawConfiguration> context, BlockPos blockpos) {
    LevelHeightAccessor heightAccessor = context.heightAccessor();
    // Get the top y location that is solid
    int y = context.chunkGenerator().getBaseHeight(blockpos.getX(), blockpos.getZ(), Heightmap.Types.WORLD_SURFACE_WG, heightAccessor);
    // Create a randomgenerator that depends on the current chunk location. That way if the world is recreated
    // with the same seed the feature will end up at the same spot
    WorldgenRandom worldgenrandom = new WorldgenRandom(new LegacyRandomSource(context.seed()));
    worldgenrandom.setLargeFeatureSeed(context.seed(), context.chunkPos().x, context.chunkPos().z);
    // Pick a random y location between a low and a high point
    y = worldgenrandom.nextIntBetweenInclusive(heightAccessor.getMinBuildHeight() + 20, y - 10);
    // Go down until we find a spot that has air. Then go down until we find a spot that is solid again
    NoiseColumn baseColumn = context.chunkGenerator().getBaseColumn(blockpos.getX(), blockpos.getZ(), heightAccessor);
    // Remember 'y' because we will just use this if we can't find an air bubble
    int yy = y;
    // Lower limit, don't go below this
    int lower = heightAccessor.getMinBuildHeight() + 3;
    while (yy > lower && !baseColumn.getBlock(yy).isAir()) {
        yy--;
    }
    // If we found air we go down until we find a non-air block
    if (yy > lower) {
        while (yy > lower && baseColumn.getBlock(yy).isAir()) {
            yy--;
        }
        if (yy > lower) {
            // We found a possible spawn spot
            y = yy + 1;
        }
    }
    return blockpos.atY(y);
}
Also used : LevelHeightAccessor(net.minecraft.world.level.LevelHeightAccessor) LegacyRandomSource(net.minecraft.world.level.levelgen.LegacyRandomSource) NoiseColumn(net.minecraft.world.level.NoiseColumn) WorldgenRandom(net.minecraft.world.level.levelgen.WorldgenRandom) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with NoiseColumn

use of net.minecraft.world.level.NoiseColumn in project RepurposedStructures by TelepathicGrunt.

the class GenericJigsawStructure method isGenericFeatureChunk.

protected static <CC extends RSGenericConfig> boolean isGenericFeatureChunk(PieceGeneratorSupplier.Context<CC> context) {
    ChunkPos chunkPos = context.chunkPos();
    CC config = context.config();
    if (!(context.biomeSource() instanceof CheckerboardColumnBiomeSource)) {
        for (int curChunkX = chunkPos.x - config.biomeRadius; curChunkX <= chunkPos.x + config.biomeRadius; curChunkX++) {
            for (int curChunkZ = chunkPos.z - config.biomeRadius; curChunkZ <= chunkPos.z + config.biomeRadius; curChunkZ++) {
                int yValue = config.doNotUseHeightmap ? config.setFixedYSpawn : config.setFixedYSpawn + context.chunkGenerator().getFirstFreeHeight(curChunkX << 4, curChunkZ << 4, Heightmap.Types.WORLD_SURFACE_WG, context.heightAccessor());
                Holder<Biome> biome = context.biomeSource().getNoiseBiome(curChunkX << 2, yValue >> 2, curChunkZ << 2, context.chunkGenerator().climateSampler());
                if (!context.validBiome().test(biome)) {
                    return false;
                }
            }
        }
    }
    if (config.cannotSpawnInLiquid) {
        BlockPos centerOfChunk = chunkPos.getMiddleBlockPosition(0);
        int landHeight = context.chunkGenerator().getFirstOccupiedHeight(centerOfChunk.getX(), centerOfChunk.getZ(), Heightmap.Types.WORLD_SURFACE_WG, context.heightAccessor());
        NoiseColumn columnOfBlocks = context.chunkGenerator().getBaseColumn(centerOfChunk.getX(), centerOfChunk.getZ(), context.heightAccessor());
        BlockState topBlock = columnOfBlocks.getBlock(centerOfChunk.getY() + landHeight);
        if (!topBlock.getFluidState().isEmpty()) {
            return false;
        }
    }
    // cannot be near other specified structure
    for (ResourceKey<StructureSet> structureSetToAvoid : config.structureSetToAvoid) {
        if (context.chunkGenerator().hasFeatureChunkInRange(structureSetToAvoid, context.seed(), chunkPos.x, chunkPos.z, config.structureAvoidRadius)) {
            return false;
        }
    }
    if (config.allowedTerrainHeightRange != -1) {
        int maxTerrainHeight = Integer.MIN_VALUE;
        int minTerrainHeight = Integer.MAX_VALUE;
        for (int curChunkX = chunkPos.x - config.terrainHeightCheckRadius; curChunkX <= chunkPos.x + config.terrainHeightCheckRadius; curChunkX++) {
            for (int curChunkZ = chunkPos.z - config.terrainHeightCheckRadius; curChunkZ <= chunkPos.z + config.terrainHeightCheckRadius; curChunkZ++) {
                int height = context.chunkGenerator().getBaseHeight((curChunkX << 4) + 7, (curChunkZ << 4) + 7, Heightmap.Types.WORLD_SURFACE_WG, context.heightAccessor());
                maxTerrainHeight = Math.max(maxTerrainHeight, height);
                minTerrainHeight = Math.min(minTerrainHeight, height);
                if (minTerrainHeight < config.minYAllowed) {
                    return false;
                }
            }
        }
        if (maxTerrainHeight - minTerrainHeight > config.allowedTerrainHeightRange) {
            return false;
        }
    }
    return true;
}
Also used : Biome(net.minecraft.world.level.biome.Biome) BlockState(net.minecraft.world.level.block.state.BlockState) StructureSet(net.minecraft.world.level.levelgen.structure.StructureSet) NoiseColumn(net.minecraft.world.level.NoiseColumn) CheckerboardColumnBiomeSource(net.minecraft.world.level.biome.CheckerboardColumnBiomeSource) ChunkPos(net.minecraft.world.level.ChunkPos) BlockPos(net.minecraft.core.BlockPos)

Aggregations

NoiseColumn (net.minecraft.world.level.NoiseColumn)21 BlockPos (net.minecraft.core.BlockPos)19 BlockState (net.minecraft.world.level.block.state.BlockState)18 ChunkPos (net.minecraft.world.level.ChunkPos)4 LegacyRandomSource (net.minecraft.world.level.levelgen.LegacyRandomSource)3 WorldgenRandom (net.minecraft.world.level.levelgen.WorldgenRandom)3 StructureSet (net.minecraft.world.level.levelgen.structure.StructureSet)3 ArrayList (java.util.ArrayList)2 PoolElementStructurePiece (net.minecraft.world.level.levelgen.structure.PoolElementStructurePiece)2 Direction (net.minecraft.core.Direction)1 LevelHeightAccessor (net.minecraft.world.level.LevelHeightAccessor)1 Biome (net.minecraft.world.level.biome.Biome)1 CheckerboardColumnBiomeSource (net.minecraft.world.level.biome.CheckerboardColumnBiomeSource)1 PieceGenerator (net.minecraft.world.level.levelgen.structure.pieces.PieceGenerator)1 NotNull (org.jetbrains.annotations.NotNull)1