Search in sources :

Example 1 with StructurePiece

use of net.minecraft.world.level.levelgen.structure.StructurePiece 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 StructurePiece

use of net.minecraft.world.level.levelgen.structure.StructurePiece 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 3 with StructurePiece

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

the class GeneralUtils method centerAllPieces.

// ////////////////////////////////////////////
public static void centerAllPieces(BlockPos targetPos, List<? extends StructurePiece> pieces) {
    if (pieces.isEmpty())
        return;
    Vec3i structureCenter = pieces.get(0).getBoundingBox().getCenter();
    int xOffset = targetPos.getX() - structureCenter.getX();
    int zOffset = targetPos.getZ() - structureCenter.getZ();
    for (StructurePiece structurePiece : pieces) {
        structurePiece.move(xOffset, 0, zOffset);
    }
}
Also used : Vec3i(net.minecraft.core.Vec3i) StructurePiece(net.minecraft.world.level.levelgen.structure.StructurePiece)

Example 4 with StructurePiece

use of net.minecraft.world.level.levelgen.structure.StructurePiece 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

StructurePiece (net.minecraft.world.level.levelgen.structure.StructurePiece)4 BlockPos (net.minecraft.core.BlockPos)3 LegacyRandomSource (net.minecraft.world.level.levelgen.LegacyRandomSource)3 WorldgenRandom (net.minecraft.world.level.levelgen.WorldgenRandom)3 JigsawConfiguration (net.minecraft.world.level.levelgen.feature.configurations.JigsawConfiguration)3 Codec (com.mojang.serialization.Codec)2 GeneralUtils (com.telepathicgrunt.repurposedstructures.utils.GeneralUtils)2 PieceLimitedJigsawManager (com.telepathicgrunt.repurposedstructures.world.structures.pieces.PieceLimitedJigsawManager)2 Comparator (java.util.Comparator)2 Optional (java.util.Optional)2 Direction (net.minecraft.core.Direction)2 Heightmap (net.minecraft.world.level.levelgen.Heightmap)2 PoolElementStructurePiece (net.minecraft.world.level.levelgen.structure.PoolElementStructurePiece)2 PieceGenerator (net.minecraft.world.level.levelgen.structure.pieces.PieceGenerator)2 PieceGeneratorSupplier (net.minecraft.world.level.levelgen.structure.pieces.PieceGeneratorSupplier)2 Vector3f (com.mojang.math.Vector3f)1 RepurposedStructures (com.telepathicgrunt.repurposedstructures.RepurposedStructures)1 RSAdvancedDistanceConfig (com.telepathicgrunt.repurposedstructures.world.structures.configs.RSAdvancedDistanceConfig)1 RSMineshaftEndConfig (com.telepathicgrunt.repurposedstructures.world.structures.configs.RSMineshaftEndConfig)1 Function (java.util.function.Function)1