Search in sources :

Example 1 with LegacyRandomSource

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

the class BuriableStructure method generatePieces.

public static <CC extends RSBuriableConfig> Optional<PieceGenerator<CC>> generatePieces(PieceGeneratorSupplier.Context<CC> context) {
    BlockPos blockpos = new BlockPos(context.chunkPos().getMinBlockX(), context.chunkGenerator().getSeaLevel(), context.chunkPos().getMinBlockZ());
    CC config = context.config();
    return PieceLimitedJigsawManager.assembleJigsawStructure(context, new JigsawConfiguration(config.startPool, config.size), GeneralUtils.getCsfNameForConfig(config, context.registryAccess()), blockpos, false, false, Integer.MAX_VALUE, Integer.MIN_VALUE, (structurePiecesBuilder, pieces) -> {
        GeneralUtils.centerAllPieces(blockpos, pieces);
        Heightmap.Types heightMapToUse = config.useOceanHeightmap ? Heightmap.Types.OCEAN_FLOOR_WG : Heightmap.Types.WORLD_SURFACE_WG;
        BoundingBox box = pieces.get(0).getBoundingBox();
        int highestLandPos = context.chunkGenerator().getFirstOccupiedHeight(box.minX(), box.minZ(), heightMapToUse, context.heightAccessor());
        highestLandPos = Math.min(highestLandPos, context.chunkGenerator().getFirstOccupiedHeight(box.minX(), box.maxZ(), heightMapToUse, context.heightAccessor()));
        highestLandPos = Math.min(highestLandPos, context.chunkGenerator().getFirstOccupiedHeight(box.maxX(), box.minZ(), heightMapToUse, context.heightAccessor()));
        highestLandPos = Math.min(highestLandPos, context.chunkGenerator().getFirstOccupiedHeight(box.maxX(), box.maxZ(), heightMapToUse, context.heightAccessor()));
        if (config.useOceanHeightmap) {
            int maxHeightForSubmerging = context.chunkGenerator().getSeaLevel() - box.getYSpan();
            highestLandPos = Math.min(highestLandPos, maxHeightForSubmerging);
        }
        WorldgenRandom random = new WorldgenRandom(new LegacyRandomSource(0L));
        random.setLargeFeatureSeed(context.seed(), context.chunkPos().x, context.chunkPos().z);
        int heightDiff = highestLandPos - box.minY();
        for (StructurePiece structurePiece : pieces) {
            structurePiece.move(0, heightDiff + (config.offsetAmount), 0);
        }
    });
}
Also used : Heightmap(net.minecraft.world.level.levelgen.Heightmap) JigsawConfiguration(net.minecraft.world.level.levelgen.feature.configurations.JigsawConfiguration) LegacyRandomSource(net.minecraft.world.level.levelgen.LegacyRandomSource) BoundingBox(net.minecraft.world.level.levelgen.structure.BoundingBox) StructurePiece(net.minecraft.world.level.levelgen.structure.StructurePiece) BlockPos(net.minecraft.core.BlockPos) WorldgenRandom(net.minecraft.world.level.levelgen.WorldgenRandom)

Example 2 with LegacyRandomSource

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

the class GenericNetherJigsawStructure method generateNetherPieces.

public static <CC extends RSGenericNetherConfig> Optional<PieceGenerator<CC>> generateNetherPieces(PieceGeneratorSupplier.Context<CC> context) {
    CC config = context.config();
    BlockPos blockpos = new BlockPos(context.chunkPos().getMinBlockX(), config.setFixedYSpawn, context.chunkPos().getMinBlockZ());
    return PieceLimitedJigsawManager.assembleJigsawStructure(context, new JigsawConfiguration(config.startPool, config.size), GeneralUtils.getCsfNameForConfig(config, context.registryAccess()), blockpos, !config.doNotUseHeightmap, !config.doNotUseHeightmap, Integer.MAX_VALUE, Integer.MIN_VALUE, config.poolsThatIgnoreBoundaries, (structurePiecesBuilder, pieces) -> {
        GeneralUtils.centerAllPieces(blockpos, pieces);
        WorldgenRandom random = new WorldgenRandom(new LegacyRandomSource(0L));
        random.setLargeFeatureSeed(context.seed(), context.chunkPos().x, context.chunkPos().z);
        BlockPos placementPos;
        if (config.highestLandSearch) {
            placementPos = GeneralUtils.getHighestLand(context.chunkGenerator(), structurePiecesBuilder.getBoundingBox(), context.heightAccessor(), !config.cannotSpawnInLiquid);
        } else {
            placementPos = GeneralUtils.getLowestLand(context.chunkGenerator(), structurePiecesBuilder.getBoundingBox(), context.heightAccessor(), !config.cannotSpawnInLiquid);
        }
        if (placementPos.getY() >= GeneralUtils.getMaxTerrainLimit(context.chunkGenerator()) || placementPos.getY() <= context.chunkGenerator().getSeaLevel() + 1) {
            int yDiff = (context.chunkGenerator().getSeaLevel() + config.ledgeSpotOffset) - pieces.get(0).getBoundingBox().minY();
            pieces.forEach(piece -> piece.move(0, yDiff, 0));
        } else {
            int yDiff = (placementPos.getY() + config.ledgeSpotOffset) - pieces.get(0).getBoundingBox().minY();
            pieces.forEach(piece -> piece.move(0, yDiff, 0));
        }
        pieces.forEach(piece -> piece.move(0, config.centerYOffset, 0));
    });
}
Also used : JigsawConfiguration(net.minecraft.world.level.levelgen.feature.configurations.JigsawConfiguration) LegacyRandomSource(net.minecraft.world.level.levelgen.LegacyRandomSource) BlockPos(net.minecraft.core.BlockPos) WorldgenRandom(net.minecraft.world.level.levelgen.WorldgenRandom)

Example 3 with LegacyRandomSource

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

the class MineshaftEndStructure method generateMineshaftEndPieces.

public static <CC extends RSMineshaftEndConfig> Optional<PieceGenerator<CC>> generateMineshaftEndPieces(PieceGeneratorSupplier.Context<CC> context) {
    CC config = context.config();
    BlockPos.MutableBlockPos blockpos = new BlockPos.MutableBlockPos(context.chunkPos().getMinBlockX(), 0, context.chunkPos().getMinBlockZ());
    BlockPos.MutableBlockPos islandTopBottomThickness = new BlockPos.MutableBlockPos(Integer.MAX_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE);
    analyzeLand(context.chunkGenerator(), blockpos.getX(), blockpos.getZ(), islandTopBottomThickness, context.heightAccessor());
    int minThickness = config.minIslandThickness;
    int maxY = 53;
    int minY = 15;
    if (minThickness == 0) {
        blockpos.move(Direction.UP, 35);
    } else {
        WorldgenRandom random = new WorldgenRandom(new LegacyRandomSource(0L));
        random.setLargeFeatureSeed(context.seed(), context.chunkPos().x, context.chunkPos().z);
        int structureStartHeight = random.nextInt(Math.max(islandTopBottomThickness.getZ() - minThickness + 1, 1)) + islandTopBottomThickness.getY() + (minThickness / 2);
        blockpos.move(Direction.UP, structureStartHeight);
        maxY = islandTopBottomThickness.getX() - 5;
        minY = islandTopBottomThickness.getY();
        if (maxY - minY <= 5) {
            minY = maxY - 5;
        }
    }
    int finalMaxY = maxY;
    return PieceLimitedJigsawManager.assembleJigsawStructure(context, new JigsawConfiguration(config.startPool, config.size), GeneralUtils.getCsfNameForConfig(config, context.registryAccess()), blockpos, false, false, maxY, minY, config.poolsThatIgnoreBoundaries, (structurePiecesBuilder, pieces) -> {
        Optional<PoolElementStructurePiece> highestPiece = pieces.stream().max(Comparator.comparingInt(p -> p.getBoundingBox().maxY()));
        int topY = highestPiece.map(poolElementStructurePiece -> poolElementStructurePiece.getBoundingBox().maxY()).orElseGet(blockpos::getY);
        if (topY > finalMaxY) {
            int newOffset = finalMaxY - topY;
            for (StructurePiece piece : pieces) {
                piece.move(0, newOffset, 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) RSMineshaftEndConfig(com.telepathicgrunt.repurposedstructures.world.structures.configs.RSMineshaftEndConfig) NoiseColumn(net.minecraft.world.level.NoiseColumn) BlockState(net.minecraft.world.level.block.state.BlockState) WorldgenRandom(net.minecraft.world.level.levelgen.WorldgenRandom) LegacyRandomSource(net.minecraft.world.level.levelgen.LegacyRandomSource) Vector3f(com.mojang.math.Vector3f) 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) BlockPos(net.minecraft.core.BlockPos) PoolElementStructurePiece(net.minecraft.world.level.levelgen.structure.PoolElementStructurePiece) Heightmap(net.minecraft.world.level.levelgen.Heightmap) 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)

Example 4 with LegacyRandomSource

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

the class WallVinePostProcessor 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);
        if (random.nextFloat() < probability && centerState.isAir()) {
            BlockPos.MutableBlockPos mutable = new BlockPos.MutableBlockPos();
            for (Direction facing : Direction.Plane.HORIZONTAL) {
                mutable.set(structureBlockInfoWorld.pos).move(facing);
                BlockState worldState = worldView.getChunk(mutable).getBlockState(mutable);
                // Vines only get placed facing the side of 1 full block.
                if (!worldState.is(Blocks.SPAWNER) && Block.isFaceFull(worldState.getCollisionShape(worldView, pos), facing.getOpposite())) {
                    BlockState vineBlock = Blocks.VINE.defaultBlockState().setValue(VineBlock.getPropertyForFace(facing), true);
                    centerChunk.setBlockState(structureBlockInfoWorld.pos, 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)

Example 5 with LegacyRandomSource

use of net.minecraft.world.level.levelgen.LegacyRandomSource in project Brass_Amber_BattleTowers by BrassAmber-Mods.

the class BTLandJigsawPlacement method addPieces.

public static Optional<PieceGenerator<BTJigsawConfiguration>> addPieces(PieceGeneratorSupplier.Context<BTJigsawConfiguration> context, BTLandJigsawPlacement.PieceFactory pieceFactory, BlockPos placementPos, boolean boundaryAdjust, boolean useHeightMap, boolean water) {
    WorldgenRandom worldgenrandom = new WorldgenRandom(new LegacyRandomSource(0L));
    worldgenrandom.setLargeFeatureSeed(context.seed(), context.chunkPos().x, context.chunkPos().z);
    RegistryAccess registryaccess = context.registryAccess();
    BTJigsawConfiguration jigsawconfiguration = context.config();
    ChunkGenerator chunkgenerator = context.chunkGenerator();
    StructureManager structuremanager = context.structureManager();
    LevelHeightAccessor levelheightaccessor = context.heightAccessor();
    Predicate<Biome> predicate = context.validBiome();
    StructureFeature.bootstrap();
    Registry<StructureTemplatePool> registry = registryaccess.registryOrThrow(Registry.TEMPLATE_POOL_REGISTRY);
    Rotation rotation = Rotation.getRandom(worldgenrandom);
    watered = water;
    StructureTemplatePool structuretemplatepool = jigsawconfiguration.startPool().get();
    StructurePoolElement structurepoolelement = structuretemplatepool.getRandomTemplate(worldgenrandom);
    if (structurepoolelement == EmptyPoolElement.INSTANCE) {
        return Optional.empty();
    } else {
        PoolElementStructurePiece poolelementstructurepiece = pieceFactory.create(structuremanager, structurepoolelement, placementPos, structurepoolelement.getGroundLevelDelta(), rotation, structurepoolelement.getBoundingBox(structuremanager, placementPos, rotation));
        BoundingBox boundingbox = poolelementstructurepiece.getBoundingBox();
        int bbX = (boundingbox.maxX() + boundingbox.minX()) / 2;
        int bbZ = (boundingbox.maxZ() + boundingbox.minZ()) / 2;
        int ppY;
        if (useHeightMap) {
            ppY = placementPos.getY() + chunkgenerator.getFirstFreeHeight(bbX, bbZ, Heightmap.Types.WORLD_SURFACE_WG, levelheightaccessor);
        } else {
            ppY = placementPos.getY();
        }
        if (watered) {
            poolelementstructurepiece.move(0, -5, 0);
        }
        if (!predicate.test(chunkgenerator.getNoiseBiome(QuartPos.fromBlock(bbX), QuartPos.fromBlock(ppY), QuartPos.fromBlock(bbZ)))) {
            return Optional.empty();
        } else {
            int pieceYlevel = boundingbox.minY() + poolelementstructurepiece.getGroundLevelDelta();
            poolelementstructurepiece.move(0, ppY - pieceYlevel, 0);
            return Optional.of((piecesBuilder, pieceGenContext) -> {
                List<PoolElementStructurePiece> list = Lists.newArrayList();
                list.add(poolelementstructurepiece);
                if (jigsawconfiguration.maxDepth() > 0) {
                    int sizeLimit = 120;
                    AABB aabb = new AABB(bbX - sizeLimit, ppY - sizeLimit, bbZ - sizeLimit, bbX + sizeLimit + 1, ppY + sizeLimit + 1, bbZ + sizeLimit + 1);
                    BTLandJigsawPlacement.Placer BTLandJigsawPlacement$placer = new BTLandJigsawPlacement.Placer(registry, jigsawconfiguration.maxDepth(), pieceFactory, chunkgenerator, structuremanager, list, worldgenrandom);
                    BTLandJigsawPlacement$placer.placing.addLast(new BTLandJigsawPlacement.PieceState(poolelementstructurepiece, new MutableObject<>(Shapes.join(Shapes.create(aabb), Shapes.create(AABB.of(boundingbox)), BooleanOp.ONLY_FIRST)), 0));
                    while (!BTLandJigsawPlacement$placer.placing.isEmpty()) {
                        BTLandJigsawPlacement.PieceState BTLandJigsawPlacement$piecestate = BTLandJigsawPlacement$placer.placing.removeFirst();
                        BTLandJigsawPlacement$placer.tryPlacingChildren(BTLandJigsawPlacement$piecestate.piece, BTLandJigsawPlacement$piecestate.free, BTLandJigsawPlacement$piecestate.depth, boundaryAdjust, levelheightaccessor);
                    }
                    list.forEach(piecesBuilder::addPiece);
                }
            });
        }
    }
}
Also used : PoolElementStructurePiece(net.minecraft.world.level.levelgen.structure.PoolElementStructurePiece) StructureManager(net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager) Rotation(net.minecraft.world.level.block.Rotation) LevelHeightAccessor(net.minecraft.world.level.LevelHeightAccessor) Biome(net.minecraft.world.level.biome.Biome) LegacyRandomSource(net.minecraft.world.level.levelgen.LegacyRandomSource) BoundingBox(net.minecraft.world.level.levelgen.structure.BoundingBox) WorldgenRandom(net.minecraft.world.level.levelgen.WorldgenRandom) ChunkGenerator(net.minecraft.world.level.chunk.ChunkGenerator) AABB(net.minecraft.world.phys.AABB) MutableObject(org.apache.commons.lang3.mutable.MutableObject)

Aggregations

LegacyRandomSource (net.minecraft.world.level.levelgen.LegacyRandomSource)17 WorldgenRandom (net.minecraft.world.level.levelgen.WorldgenRandom)17 BlockPos (net.minecraft.core.BlockPos)10 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 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 Biome (net.minecraft.world.level.biome.Biome)3 BlockState (net.minecraft.world.level.block.state.BlockState)3 ChunkGenerator (net.minecraft.world.level.chunk.ChunkGenerator)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 PieceGeneratorSupplier (net.minecraft.world.level.levelgen.structure.pieces.PieceGeneratorSupplier)3