Search in sources :

Example 6 with LegacyRandomSource

use of net.minecraft.world.level.levelgen.LegacyRandomSource in project Valhelsia-Structures by ValhelsiaTeam.

the class AbstractValhelsiaStructure method isFeatureChunk.

protected boolean isFeatureChunk(PieceGeneratorSupplier.Context<JigsawConfiguration> context) {
    ChunkPos chunkPos = context.chunkPos();
    BlockPos pos = chunkPos.getWorldPosition();
    ChunkGenerator generator = context.chunkGenerator();
    WorldgenRandom random = new WorldgenRandom(new LegacyRandomSource(0L));
    // Check if the surface is flat
    if (this.checkSurface() && !StructureUtils.isSurfaceFlat(context, this.getSize())) {
        return false;
    }
    // Check for water
    if (!this.canGenerateOnWater()) {
        int landHeight = generator.getFirstOccupiedHeight(pos.getX(), pos.getZ(), Heightmap.Types.WORLD_SURFACE_WG, context.heightAccessor());
        NoiseColumn columnOfBlocks = generator.getBaseColumn(pos.getX(), pos.getZ(), context.heightAccessor());
        BlockState topBlock = columnOfBlocks.getBlock(landHeight);
        if (!topBlock.getFluidState().isEmpty()) {
            return false;
        }
    }
    // Check for other structures
    List<ResourceKey<StructureSet>> structures = ModStructures.MOD_STRUCTURES.stream().filter(structure -> structure.step() == this.step() && structure.getStructureSetResourceKey() != this.getStructureSetResourceKey()).map(AbstractValhelsiaStructure::getStructureSetResourceKey).toList();
    if (StructureUtils.isStructureInDistance(generator, context.seed(), context.chunkPos(), structures)) {
        return false;
    }
    // Check the spawn chance
    random.setSeed((long) (chunkPos.x >> 4 ^ chunkPos.z >> 4 << 4) ^ context.seed());
    return random.nextDouble() < this.getSpawnChance();
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) LegacyRandomSource(net.minecraft.world.level.levelgen.LegacyRandomSource) NoiseColumn(net.minecraft.world.level.NoiseColumn) ChunkPos(net.minecraft.world.level.ChunkPos) BlockPos(net.minecraft.core.BlockPos) WorldgenRandom(net.minecraft.world.level.levelgen.WorldgenRandom) ChunkGenerator(net.minecraft.world.level.chunk.ChunkGenerator) ResourceKey(net.minecraft.resources.ResourceKey)

Example 7 with LegacyRandomSource

use of net.minecraft.world.level.levelgen.LegacyRandomSource in project bygone-nether by izofar.

the class NetherFortressStructure method checkChunk.

private static boolean checkChunk(PieceGeneratorSupplier.Context<JigsawConfiguration> context) {
    WorldgenRandom worldgenrandom = new WorldgenRandom(new LegacyRandomSource(0L));
    worldgenrandom.setLargeFeatureSeed(context.seed(), context.chunkPos().x, context.chunkPos().z);
    return context.validBiome().test(context.chunkGenerator().getNoiseBiome(QuartPos.fromBlock(context.chunkPos().getMiddleBlockX()), QuartPos.fromBlock(64), QuartPos.fromBlock(context.chunkPos().getMiddleBlockZ())));
}
Also used : LegacyRandomSource(net.minecraft.world.level.levelgen.LegacyRandomSource) WorldgenRandom(net.minecraft.world.level.levelgen.WorldgenRandom)

Example 8 with LegacyRandomSource

use of net.minecraft.world.level.levelgen.LegacyRandomSource in project Applied-Energistics-2 by AppliedEnergistics.

the class MeteoriteStructure method checkLocation.

private static boolean checkLocation(PieceGeneratorSupplier.Context<NoneFeatureConfiguration> context) {
    if (!context.validBiomeOnTop(Heightmap.Types.WORLD_SURFACE_WG)) {
        return false;
    }
    WorldgenRandom worldgenRandom = new WorldgenRandom(new LegacyRandomSource(0L));
    worldgenRandom.setLargeFeatureSeed(context.seed(), context.chunkPos().x, context.chunkPos().z);
    return worldgenRandom.nextBoolean();
}
Also used : LegacyRandomSource(net.minecraft.world.level.levelgen.LegacyRandomSource) WorldgenRandom(net.minecraft.world.level.levelgen.WorldgenRandom)

Example 9 with LegacyRandomSource

use of net.minecraft.world.level.levelgen.LegacyRandomSource 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 10 with LegacyRandomSource

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

the class AdvancedDistanceJigsawStructure method generateDistancePieces.

public static <CC extends RSAdvancedDistanceConfig> Optional<PieceGenerator<CC>> generateDistancePieces(PieceGeneratorSupplier.Context<CC> context) {
    BlockPos.MutableBlockPos blockpos = new BlockPos.MutableBlockPos(context.chunkPos().getMinBlockX(), 0, context.chunkPos().getMinBlockZ());
    CC config = context.config();
    if (config.maxY - config.minY <= 0) {
        RepurposedStructures.LOGGER.error("MinY should always be less than MaxY or else a crash will occur or no pieces will spawn. Problematic structure is:" + config.startPool.unwrapKey().get().location());
    }
    WorldgenRandom random = new WorldgenRandom(new LegacyRandomSource(0L));
    random.setLargeFeatureSeed(context.seed(), context.chunkPos().x, context.chunkPos().z);
    int structureStartHeight = random.nextInt(config.maxY - config.minY) + config.minY;
    blockpos.move(Direction.UP, structureStartHeight);
    int topClipOff;
    int bottomClipOff;
    if (config.verticalRange.isEmpty()) {
        // Help make sure the Jigsaw Blocks have room to spawn new pieces if structure is right on edge of maxY or topYLimit
        topClipOff = config.clipOutOfBoundsPieces ? config.maxY + 5 : Integer.MAX_VALUE;
        bottomClipOff = config.clipOutOfBoundsPieces ? config.minY - 5 : Integer.MIN_VALUE;
    } else {
        topClipOff = structureStartHeight + config.verticalRange.get();
        bottomClipOff = structureStartHeight - config.verticalRange.get();
    }
    return PieceLimitedJigsawManager.assembleJigsawStructure(context, new JigsawConfiguration(config.startPool, config.size), GeneralUtils.getCsfNameForConfig(config, context.registryAccess()), blockpos, false, false, topClipOff, bottomClipOff, config.poolsThatIgnoreBoundaries, (structurePiecesBuilder, pieces) -> {
        Optional<PoolElementStructurePiece> lowestPiece = pieces.stream().min(Comparator.comparingInt(p -> p.getBoundingBox().minY()));
        int minY = lowestPiece.map(poolElementStructurePiece -> poolElementStructurePiece.getBoundingBox().minY()).orElseGet(blockpos::getY);
        if (minY < context.chunkGenerator().getMinY()) {
            int newOffset = context.chunkGenerator().getMinY() - minY;
            for (StructurePiece piece : pieces) {
                piece.move(0, newOffset, 0);
            }
        }
    });
}
Also used : GeneralUtils(com.telepathicgrunt.repurposedstructures.utils.GeneralUtils) PieceGeneratorSupplier(net.minecraft.world.level.levelgen.structure.pieces.PieceGeneratorSupplier) Direction(net.minecraft.core.Direction) Predicate(java.util.function.Predicate) WorldgenRandom(net.minecraft.world.level.levelgen.WorldgenRandom) RepurposedStructures(com.telepathicgrunt.repurposedstructures.RepurposedStructures) LegacyRandomSource(net.minecraft.world.level.levelgen.LegacyRandomSource) Function(java.util.function.Function) PieceLimitedJigsawManager(com.telepathicgrunt.repurposedstructures.world.structures.pieces.PieceLimitedJigsawManager) RSAdvancedDistanceConfig(com.telepathicgrunt.repurposedstructures.world.structures.configs.RSAdvancedDistanceConfig) PieceGenerator(net.minecraft.world.level.levelgen.structure.pieces.PieceGenerator) Codec(com.mojang.serialization.Codec) BlockPos(net.minecraft.core.BlockPos) PoolElementStructurePiece(net.minecraft.world.level.levelgen.structure.PoolElementStructurePiece) Optional(java.util.Optional) JigsawConfiguration(net.minecraft.world.level.levelgen.feature.configurations.JigsawConfiguration) StructurePiece(net.minecraft.world.level.levelgen.structure.StructurePiece) Comparator(java.util.Comparator) PoolElementStructurePiece(net.minecraft.world.level.levelgen.structure.PoolElementStructurePiece) PoolElementStructurePiece(net.minecraft.world.level.levelgen.structure.PoolElementStructurePiece) StructurePiece(net.minecraft.world.level.levelgen.structure.StructurePiece) LegacyRandomSource(net.minecraft.world.level.levelgen.LegacyRandomSource) JigsawConfiguration(net.minecraft.world.level.levelgen.feature.configurations.JigsawConfiguration) BlockPos(net.minecraft.core.BlockPos) WorldgenRandom(net.minecraft.world.level.levelgen.WorldgenRandom)

Aggregations

LegacyRandomSource (net.minecraft.world.level.levelgen.LegacyRandomSource)18 WorldgenRandom (net.minecraft.world.level.levelgen.WorldgenRandom)18 BlockPos (net.minecraft.core.BlockPos)11 JigsawConfiguration (net.minecraft.world.level.levelgen.feature.configurations.JigsawConfiguration)6 Direction (net.minecraft.core.Direction)5 Random (java.util.Random)4 LevelHeightAccessor (net.minecraft.world.level.LevelHeightAccessor)4 BlockState (net.minecraft.world.level.block.state.BlockState)4 ChunkGenerator (net.minecraft.world.level.chunk.ChunkGenerator)4 PoolElementStructurePiece (net.minecraft.world.level.levelgen.structure.PoolElementStructurePiece)4 Codec (com.mojang.serialization.Codec)3 GeneralUtils (com.telepathicgrunt.repurposedstructures.utils.GeneralUtils)3 PieceLimitedJigsawManager (com.telepathicgrunt.repurposedstructures.world.structures.pieces.PieceLimitedJigsawManager)3 Comparator (java.util.Comparator)3 Optional (java.util.Optional)3 NoiseColumn (net.minecraft.world.level.NoiseColumn)3 Biome (net.minecraft.world.level.biome.Biome)3 Heightmap (net.minecraft.world.level.levelgen.Heightmap)3 StructurePiece (net.minecraft.world.level.levelgen.structure.StructurePiece)3 PieceGenerator (net.minecraft.world.level.levelgen.structure.pieces.PieceGenerator)3