Search in sources :

Example 1 with JigsawConfiguration

use of net.minecraft.world.level.levelgen.feature.configurations.JigsawConfiguration 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 JigsawConfiguration

use of net.minecraft.world.level.levelgen.feature.configurations.JigsawConfiguration in project RepurposedStructures by TelepathicGrunt.

the class CityNetherStructure method generateCityNetherPieces.

public static <CC extends RSGenericNetherConfig> Optional<PieceGenerator<CC>> generateCityNetherPieces(PieceGeneratorSupplier.Context<CC> context) {
    CC config = context.config();
    BlockPos blockpos = new BlockPos(context.chunkPos().getMinBlockX(), context.chunkGenerator().getSeaLevel(), context.chunkPos().getMinBlockZ());
    return PieceLimitedJigsawManager.assembleJigsawStructure(context, new JigsawConfiguration(config.startPool, config.size), GeneralUtils.getCsfNameForConfig(config, context.registryAccess()), blockpos, false, false, Integer.MAX_VALUE, Integer.MIN_VALUE, config.poolsThatIgnoreBoundaries, (structurePiecesBuilder, pieces) -> pieces.get(0).move(0, config.centerYOffset, 0));
}
Also used : JigsawConfiguration(net.minecraft.world.level.levelgen.feature.configurations.JigsawConfiguration) BlockPos(net.minecraft.core.BlockPos)

Example 3 with JigsawConfiguration

use of net.minecraft.world.level.levelgen.feature.configurations.JigsawConfiguration in project RepurposedStructures by TelepathicGrunt.

the class GenericJigsawStructure method generateGenericPieces.

public static <CC extends RSGenericConfig> Optional<PieceGenerator<CC>> generateGenericPieces(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);
        pieces.get(0).move(0, config.centerYOffset, 0);
    });
}
Also used : JigsawConfiguration(net.minecraft.world.level.levelgen.feature.configurations.JigsawConfiguration) BlockPos(net.minecraft.core.BlockPos)

Example 4 with JigsawConfiguration

use of net.minecraft.world.level.levelgen.feature.configurations.JigsawConfiguration 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 5 with JigsawConfiguration

use of net.minecraft.world.level.levelgen.feature.configurations.JigsawConfiguration in project RepurposedStructures by TelepathicGrunt.

the class LandBasedEndStructure method generateLandPieces.

public static <CC extends RSGenericConfig> Optional<PieceGenerator<CC>> generateLandPieces(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);
        BoundingBox box = pieces.get(0).getBoundingBox();
        BlockPos centerPos = new BlockPos(box.getCenter());
        int radius = (int) Math.sqrt((box.getLength().getX() * box.getLength().getX()) + (box.getLength().getZ() * box.getLength().getZ())) / 2;
        List<Integer> landHeights = new ArrayList<>();
        for (int xOffset = -radius; xOffset <= radius; xOffset += (radius / 2)) {
            for (int zOffset = -radius; zOffset <= radius; zOffset += (radius / 2)) {
                int landHeight = context.chunkGenerator().getFirstOccupiedHeight(centerPos.getX() + xOffset, centerPos.getZ() + zOffset, Heightmap.Types.WORLD_SURFACE_WG, context.heightAccessor());
                landHeights.add(landHeight);
            }
        }
        // Offset structure to average land around it
        int avgHeight = (int) Math.max(landHeights.stream().mapToInt(Integer::intValue).average().orElse(0), 50);
        int parentHeight = pieces.get(0).getBoundingBox().minY();
        int offsetAmount = (avgHeight - parentHeight) + config.centerYOffset;
        pieces.forEach(child -> child.move(0, offsetAmount, 0));
    });
}
Also used : JigsawConfiguration(net.minecraft.world.level.levelgen.feature.configurations.JigsawConfiguration) BoundingBox(net.minecraft.world.level.levelgen.structure.BoundingBox) ArrayList(java.util.ArrayList) BlockPos(net.minecraft.core.BlockPos)

Aggregations

JigsawConfiguration (net.minecraft.world.level.levelgen.feature.configurations.JigsawConfiguration)19 BlockPos (net.minecraft.core.BlockPos)17 PoolElementStructurePiece (net.minecraft.world.level.levelgen.structure.PoolElementStructurePiece)11 PieceGeneratorSupplier (net.minecraft.world.level.levelgen.structure.pieces.PieceGeneratorSupplier)7 ResourceLocation (net.minecraft.resources.ResourceLocation)6 LegacyRandomSource (net.minecraft.world.level.levelgen.LegacyRandomSource)6 WorldgenRandom (net.minecraft.world.level.levelgen.WorldgenRandom)6 PieceGenerator (net.minecraft.world.level.levelgen.structure.pieces.PieceGenerator)5 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 Direction (net.minecraft.core.Direction)3 LevelHeightAccessor (net.minecraft.world.level.LevelHeightAccessor)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 RepurposedStructures (com.telepathicgrunt.repurposedstructures.RepurposedStructures)2 Function (java.util.function.Function)2