Search in sources :

Example 1 with NoiseColumn

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

the class BuriableStructure method isFeatureChunk.

protected static <CC extends RSBuriableConfig> boolean isFeatureChunk(PieceGeneratorSupplier.Context<CC> context) {
    CC config = context.config();
    if (config.cannotSpawnInWater) {
        BlockPos cornerOfSpawnChunk = context.chunkPos().getWorldPosition();
        int landHeight = context.chunkGenerator().getFirstOccupiedHeight(cornerOfSpawnChunk.getX(), cornerOfSpawnChunk.getZ(), Heightmap.Types.WORLD_SURFACE_WG, context.heightAccessor());
        NoiseColumn columnOfBlocks = context.chunkGenerator().getBaseColumn(cornerOfSpawnChunk.getX(), cornerOfSpawnChunk.getZ(), context.heightAccessor());
        BlockState topBlock = columnOfBlocks.getBlock(cornerOfSpawnChunk.getY() + landHeight);
        return topBlock.getFluidState().isEmpty();
    }
    return true;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) NoiseColumn(net.minecraft.world.level.NoiseColumn) BlockPos(net.minecraft.core.BlockPos)

Example 2 with NoiseColumn

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

the class CityNetherStructure method isCityNetherFeatureChunk.

protected static <CC extends RSGenericNetherConfig> boolean isCityNetherFeatureChunk(PieceGeneratorSupplier.Context<CC> context) {
    ChunkPos chunkPos = context.chunkPos();
    // do cheaper checks first
    if (GenericJigsawStructure.isGenericFeatureChunk(context)) {
        // make sure land is open enough for city
        BlockPos.MutableBlockPos mutable = new BlockPos.MutableBlockPos();
        for (int curChunkX = chunkPos.x - 1; curChunkX <= chunkPos.x + 1; curChunkX++) {
            for (int curChunkZ = chunkPos.z - 1; curChunkZ <= chunkPos.z + 1; curChunkZ++) {
                mutable.set(curChunkX << 4, context.chunkGenerator().getSeaLevel() + 10, curChunkZ << 4);
                NoiseColumn blockView = context.chunkGenerator().getBaseColumn(mutable.getX(), mutable.getZ(), context.heightAccessor());
                int minValidSpace = 65;
                int maxHeight = Math.min(GeneralUtils.getMaxTerrainLimit(context.chunkGenerator()), context.chunkGenerator().getSeaLevel() + minValidSpace);
                while (mutable.getY() < maxHeight) {
                    BlockState state = blockView.getBlock(mutable.getY());
                    if (!state.isAir()) {
                        return false;
                    }
                    mutable.move(Direction.UP);
                }
            }
        }
    } else {
        return false;
    }
    return true;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) NoiseColumn(net.minecraft.world.level.NoiseColumn) ChunkPos(net.minecraft.world.level.ChunkPos) BlockPos(net.minecraft.core.BlockPos)

Example 3 with NoiseColumn

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

the class MineshaftEndStructure method analyzeLand.

private static void analyzeLand(ChunkGenerator chunkGenerator, int xPos, int zPos, BlockPos.MutableBlockPos islandTopBottomThickness, LevelHeightAccessor heightLimitView) {
    NoiseColumn columnOfBlocks = chunkGenerator.getBaseColumn(xPos, zPos, heightLimitView);
    int minY = chunkGenerator.getMinY();
    int rangeHeight = GeneralUtils.getMaxTerrainLimit(chunkGenerator);
    int maxY = minY + rangeHeight;
    BlockPos.MutableBlockPos currentPos = new BlockPos.MutableBlockPos(xPos, maxY, zPos);
    boolean isInIsland = false;
    while (currentPos.getY() >= minY) {
        BlockState state = columnOfBlocks.getBlock(currentPos.getY());
        // Detects top of island
        if (!state.isAir() && !isInIsland) {
            isInIsland = true;
            int topIslandY = Math.min(currentPos.getY(), islandTopBottomThickness.getX());
            islandTopBottomThickness.set(topIslandY, islandTopBottomThickness.getY(), islandTopBottomThickness.getZ());
        } else // Detects bottom of island or land
        if ((state.isAir() && isInIsland) || currentPos.getY() == minY) {
            int bottomIslandY = Math.max(currentPos.getY(), islandTopBottomThickness.getY());
            islandTopBottomThickness.set(islandTopBottomThickness.getX(), bottomIslandY, islandTopBottomThickness.getZ());
            break;
        }
        currentPos.move(Direction.DOWN);
    }
    // Never hit land since isInIsland was never set to true for terrain top.
    if (!isInIsland) {
        islandTopBottomThickness.set(0, 0, 0);
    }
    int thickness = islandTopBottomThickness.getX() - islandTopBottomThickness.getY();
    islandTopBottomThickness.set(islandTopBottomThickness.getX(), islandTopBottomThickness.getY(), thickness);
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) NoiseColumn(net.minecraft.world.level.NoiseColumn) BlockPos(net.minecraft.core.BlockPos)

Example 4 with NoiseColumn

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

the class ShipwreckNetherStructure method isShipwreckNetherFeatureChunk.

protected static <CC extends RSShipwreckNetherConfig> boolean isShipwreckNetherFeatureChunk(PieceGeneratorSupplier.Context<CC> context) {
    // Check to see if there some air where the structure wants to spawn.
    // Doesn't account for rotation of structure.
    ChunkPos chunkPos = context.chunkPos();
    BlockPos blockPos = new BlockPos(chunkPos.getMinBlockX(), context.chunkGenerator().getSeaLevel() + 1, chunkPos.getMinBlockZ());
    CC config = context.config();
    int checkRadius = 16;
    BlockPos.MutableBlockPos mutable = new BlockPos.MutableBlockPos();
    for (int xOffset = -checkRadius; xOffset <= checkRadius; xOffset += 8) {
        for (int zOffset = -checkRadius; zOffset <= checkRadius; zOffset += 8) {
            NoiseColumn blockView = context.chunkGenerator().getBaseColumn(xOffset + blockPos.getX(), zOffset + blockPos.getZ(), context.heightAccessor());
            for (int yOffset = 0; yOffset <= 30; yOffset += 5) {
                mutable.set(blockPos).move(xOffset, yOffset, zOffset);
                if (!blockView.getBlock(mutable.getY()).isAir()) {
                    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;
        }
    }
    return true;
}
Also used : StructureSet(net.minecraft.world.level.levelgen.structure.StructureSet) NoiseColumn(net.minecraft.world.level.NoiseColumn) ChunkPos(net.minecraft.world.level.ChunkPos) BlockPos(net.minecraft.core.BlockPos)

Example 5 with NoiseColumn

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

the class ThiefDenStructure method isFeatureChunk.

// Test if the current chunk (from context) has a valid location for our structure
private static boolean isFeatureChunk(PieceGeneratorSupplier.Context<JigsawConfiguration> context) {
    BlockPos pos = context.chunkPos().getWorldPosition();
    // Get height of land (stops at first non-air block)
    int landHeight = context.chunkGenerator().getFirstOccupiedHeight(pos.getX(), pos.getZ(), Heightmap.Types.WORLD_SURFACE_WG, context.heightAccessor());
    // 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.
    NoiseColumn columnOfBlocks = context.chunkGenerator().getBaseColumn(pos.getX(), pos.getZ(), context.heightAccessor());
    // Combine the column of blocks with land height and you get the top block itself which you can test.
    BlockState topBlock = columnOfBlocks.getBlock(landHeight);
    // landHeight > 100;
    return topBlock.getFluidState().isEmpty();
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) NoiseColumn(net.minecraft.world.level.NoiseColumn) BlockPos(net.minecraft.core.BlockPos)

Aggregations

NoiseColumn (net.minecraft.world.level.NoiseColumn)22 BlockPos (net.minecraft.core.BlockPos)20 BlockState (net.minecraft.world.level.block.state.BlockState)14 ChunkPos (net.minecraft.world.level.ChunkPos)5 StructureSet (net.minecraft.world.level.levelgen.structure.StructureSet)3 ArrayList (java.util.ArrayList)2 LegacyRandomSource (net.minecraft.world.level.levelgen.LegacyRandomSource)2 WorldgenRandom (net.minecraft.world.level.levelgen.WorldgenRandom)2 NotNull (org.jetbrains.annotations.NotNull)2 Random (java.util.Random)1 ResourceKey (net.minecraft.resources.ResourceKey)1 LevelHeightAccessor (net.minecraft.world.level.LevelHeightAccessor)1 Biome (net.minecraft.world.level.biome.Biome)1 CheckerboardColumnBiomeSource (net.minecraft.world.level.biome.CheckerboardColumnBiomeSource)1 ChunkGenerator (net.minecraft.world.level.chunk.ChunkGenerator)1