Search in sources :

Example 11 with LegacyRandomSource

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

the class AdvancedJigsawStructure method generateAdvancedPieces.

public static <CC extends RSAdvancedConfig> Optional<PieceGenerator<CC>> generateAdvancedPieces(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) -> {
    });
}
Also used : 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)

Example 12 with LegacyRandomSource

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

the class AdvancedJigsawStructure method isAdvancedFeatureChunk.

protected static <CC extends RSAdvancedConfig> boolean isAdvancedFeatureChunk(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++) {
                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;
                if (!context.validBiome().test(context.biomeSource().getNoiseBiome(curChunkX << 2, structureStartHeight >> 2, curChunkZ << 2, context.chunkGenerator().climateSampler()))) {
                    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 : LegacyRandomSource(net.minecraft.world.level.levelgen.LegacyRandomSource) StructureSet(net.minecraft.world.level.levelgen.structure.StructureSet) CheckerboardColumnBiomeSource(net.minecraft.world.level.biome.CheckerboardColumnBiomeSource) ChunkPos(net.minecraft.world.level.ChunkPos) WorldgenRandom(net.minecraft.world.level.levelgen.WorldgenRandom)

Example 13 with LegacyRandomSource

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

the class MineshaftStructure method generateMineshaftPieces.

public static <CC extends RSMineshaftConfig> Optional<PieceGenerator<CC>> generateMineshaftPieces(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) -> {
        int justBelowTerrain = getTerrainHeight(context.chunkPos().getMiddleBlockPosition(0), context.chunkGenerator(), context.heightAccessor()) - 15;
        int finalJustBelowTerrain = Math.max(justBelowTerrain, bottomClipOff);
        Optional<PoolElementStructurePiece> topPiece = pieces.stream().max(Comparator.comparingInt(piece -> piece.getBoundingBox().maxY()));
        if (topPiece.isPresent() && finalJustBelowTerrain < topClipOff && finalJustBelowTerrain < topPiece.get().getBoundingBox().maxY()) {
            int topPieceMaxY = topPiece.get().getBoundingBox().maxY();
            pieces.forEach(piece -> piece.move(0, finalJustBelowTerrain - topPieceMaxY, 0));
        }
    });
}
Also used : GeneralUtils(com.telepathicgrunt.repurposedstructures.utils.GeneralUtils) LevelHeightAccessor(net.minecraft.world.level.LevelHeightAccessor) 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) Biome(net.minecraft.world.level.biome.Biome) Function(java.util.function.Function) PieceLimitedJigsawManager(com.telepathicgrunt.repurposedstructures.world.structures.pieces.PieceLimitedJigsawManager) ChunkGenerator(net.minecraft.world.level.chunk.ChunkGenerator) PieceGenerator(net.minecraft.world.level.levelgen.structure.pieces.PieceGenerator) Codec(com.mojang.serialization.Codec) Holder(net.minecraft.core.Holder) RSMineshaftConfig(com.telepathicgrunt.repurposedstructures.world.structures.configs.RSMineshaftConfig) BlockPos(net.minecraft.core.BlockPos) PoolElementStructurePiece(net.minecraft.world.level.levelgen.structure.PoolElementStructurePiece) Heightmap(net.minecraft.world.level.levelgen.Heightmap) Optional(java.util.Optional) QuartPos(net.minecraft.core.QuartPos) JigsawConfiguration(net.minecraft.world.level.levelgen.feature.configurations.JigsawConfiguration) Comparator(java.util.Comparator) PoolElementStructurePiece(net.minecraft.world.level.levelgen.structure.PoolElementStructurePiece) 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)

Example 14 with LegacyRandomSource

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

the class MineshaftStructure method isMineshaftFeatureChunk.

protected static <CC extends RSMineshaftConfig> boolean isMineshaftFeatureChunk(PieceGeneratorSupplier.Context<CC> context) {
    WorldgenRandom worldgenRandom = new WorldgenRandom(new LegacyRandomSource(0L));
    worldgenRandom.setLargeFeatureSeed(context.seed(), context.chunkPos().x, context.chunkPos().z);
    double chance = (context.config()).probability;
    if (worldgenRandom.nextDouble() >= chance) {
        return false;
    }
    Holder<Biome> biomeAtSpot = context.chunkGenerator().getNoiseBiome(QuartPos.fromBlock(context.chunkPos().getMiddleBlockX()), QuartPos.fromBlock(50), QuartPos.fromBlock(context.chunkPos().getMiddleBlockZ()));
    return context.validBiome().test(biomeAtSpot) && AdvancedJigsawStructure.isAdvancedFeatureChunk(context);
}
Also used : Biome(net.minecraft.world.level.biome.Biome) LegacyRandomSource(net.minecraft.world.level.levelgen.LegacyRandomSource) WorldgenRandom(net.minecraft.world.level.levelgen.WorldgenRandom)

Example 15 with LegacyRandomSource

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

the class CeilingVinePostProcessor method processBlock.

@Override
public StructureTemplate.StructureBlockInfo processBlock(LevelReader worldView, BlockPos pos, BlockPos blockPos, StructureTemplate.StructureBlockInfo structureBlockInfoLocal, StructureTemplate.StructureBlockInfo structureBlockInfoWorld, StructurePlaceSettings structurePlacementData) {
    // Place vines only in air space
    if (structureBlockInfoWorld.state.isAir()) {
        Random random = new WorldgenRandom(new LegacyRandomSource(0L));
        random.setSeed(structureBlockInfoWorld.pos.asLong() * structureBlockInfoWorld.pos.getY());
        ChunkAccess centerChunk = worldView.getChunk(structureBlockInfoWorld.pos);
        BlockState centerState = centerChunk.getBlockState(structureBlockInfoWorld.pos);
        BlockPos abovePos = structureBlockInfoWorld.pos.above();
        BlockState aboveState = centerChunk.getBlockState(abovePos);
        if (random.nextFloat() < probability && centerState.isAir() && Block.isFaceFull(aboveState.getCollisionShape(worldView, abovePos), Direction.DOWN)) {
            BlockPos.MutableBlockPos mutable = new BlockPos.MutableBlockPos();
            List<Direction> shuffledDirectionList = Direction.Plane.HORIZONTAL.stream().collect(Collectors.toList());
            Collections.shuffle(shuffledDirectionList);
            for (Direction facing : shuffledDirectionList) {
                mutable.set(structureBlockInfoWorld.pos).move(facing);
                BlockState worldState = worldView.getChunk(mutable).getBlockState(mutable);
                // Vines only get placed if side block is empty and top block is solid.
                if (!worldState.canOcclude()) {
                    // side block to hold vine
                    worldView.getChunk(mutable).setBlockState(mutable, blockState, false);
                    // ceiling vine
                    BlockState vineBlock = Blocks.VINE.defaultBlockState().setValue(VineBlock.getPropertyForFace(facing), true).setValue(VineBlock.UP, true);
                    // Move back to center
                    mutable.move(facing.getOpposite());
                    centerChunk.setBlockState(mutable, vineBlock, false);
                    // hanging vines
                    vineBlock = vineBlock.setValue(VineBlock.UP, false);
                    for (int depth = random.nextInt(4); depth < 3; depth++) {
                        mutable.move(Direction.DOWN);
                        if (!centerChunk.getBlockState(mutable).isAir()) {
                            break;
                        }
                        centerChunk.setBlockState(mutable, vineBlock, false);
                    }
                    break;
                }
            }
        }
    }
    return structureBlockInfoWorld;
}
Also used : ChunkAccess(net.minecraft.world.level.chunk.ChunkAccess) BlockState(net.minecraft.world.level.block.state.BlockState) WorldgenRandom(net.minecraft.world.level.levelgen.WorldgenRandom) Random(java.util.Random) LegacyRandomSource(net.minecraft.world.level.levelgen.LegacyRandomSource) WorldgenRandom(net.minecraft.world.level.levelgen.WorldgenRandom) BlockPos(net.minecraft.core.BlockPos) Direction(net.minecraft.core.Direction)

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