Search in sources :

Example 1 with PieceGenerator

use of net.minecraft.world.level.levelgen.structure.pieces.PieceGenerator 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 2 with PieceGenerator

use of net.minecraft.world.level.levelgen.structure.pieces.PieceGenerator in project Beyond-Earth by MrScautHD.

the class AlienVillage method createPiecesGenerator.

public static Optional<PieceGenerator<JigsawConfiguration>> createPiecesGenerator(PieceGeneratorSupplier.Context<JigsawConfiguration> context) {
    if (!AlienVillage.isFeatureChunk(context)) {
        return Optional.empty();
    }
    BlockPos blockpos = context.chunkPos().getMiddleBlockPosition(0);
    int topLandY = context.chunkGenerator().getFirstFreeHeight(blockpos.getX(), blockpos.getZ(), Heightmap.Types.WORLD_SURFACE_WG, context.heightAccessor());
    blockpos = blockpos.above(topLandY - 20);
    Optional<PieceGenerator<JigsawConfiguration>> structurePiecesGenerator = JigsawPlacement.addPieces(context, PoolElementStructurePiece::new, blockpos, false, false);
    return structurePiecesGenerator;
}
Also used : PoolElementStructurePiece(net.minecraft.world.level.levelgen.structure.PoolElementStructurePiece) BlockPos(net.minecraft.core.BlockPos) PieceGenerator(net.minecraft.world.level.levelgen.structure.pieces.PieceGenerator)

Example 3 with PieceGenerator

use of net.minecraft.world.level.levelgen.structure.pieces.PieceGenerator in project Beyond-Earth by MrScautHD.

the class PygroTower method createPiecesGenerator.

public static Optional<PieceGenerator<JigsawConfiguration>> createPiecesGenerator(PieceGeneratorSupplier.Context<JigsawConfiguration> context) {
    if (!PygroTower.isFeatureChunk(context)) {
        return Optional.empty();
    }
    BlockPos blockpos = context.chunkPos().getMiddleBlockPosition(0);
    int topLandY = context.chunkGenerator().getFirstFreeHeight(blockpos.getX(), blockpos.getZ(), Heightmap.Types.WORLD_SURFACE_WG, context.heightAccessor());
    blockpos = blockpos.above(topLandY);
    Optional<PieceGenerator<JigsawConfiguration>> structurePiecesGenerator = JigsawPlacement.addPieces(context, PoolElementStructurePiece::new, blockpos, false, false);
    return structurePiecesGenerator;
}
Also used : PoolElementStructurePiece(net.minecraft.world.level.levelgen.structure.PoolElementStructurePiece) BlockPos(net.minecraft.core.BlockPos) PieceGenerator(net.minecraft.world.level.levelgen.structure.pieces.PieceGenerator)

Example 4 with PieceGenerator

use of net.minecraft.world.level.levelgen.structure.pieces.PieceGenerator in project Beyond-Earth by MrScautHD.

the class VenusBullet method createPiecesGenerator.

public static Optional<PieceGenerator<JigsawConfiguration>> createPiecesGenerator(PieceGeneratorSupplier.Context<JigsawConfiguration> context) {
    if (!VenusBullet.isFeatureChunk(context)) {
        return Optional.empty();
    }
    BlockPos blockpos = context.chunkPos().getMiddleBlockPosition(0);
    int topLandY = context.chunkGenerator().getFirstFreeHeight(blockpos.getX(), blockpos.getZ(), Heightmap.Types.WORLD_SURFACE_WG, context.heightAccessor());
    blockpos = blockpos.above(topLandY);
    Optional<PieceGenerator<JigsawConfiguration>> structurePiecesGenerator = JigsawPlacement.addPieces(context, PoolElementStructurePiece::new, blockpos, false, false);
    return structurePiecesGenerator;
}
Also used : PoolElementStructurePiece(net.minecraft.world.level.levelgen.structure.PoolElementStructurePiece) BlockPos(net.minecraft.core.BlockPos) PieceGenerator(net.minecraft.world.level.levelgen.structure.pieces.PieceGenerator)

Example 5 with PieceGenerator

use of net.minecraft.world.level.levelgen.structure.pieces.PieceGenerator in project Brass_Amber_BattleTowers by BrassAmber-Mods.

the class LandBattleTower method createPiecesGenerator.

@NotNull
public static Optional<PieceGenerator<BTJigsawConfiguration>> createPiecesGenerator(PieceGeneratorSupplier.Context<BTJigsawConfiguration> context) {
    // Returning an empty optional tells the game to skip this spot as it will not generate the structure. -- TelepathicGrunt
    if (!LandBattleTower.isFeatureChunk(context)) {
        return Optional.empty();
    }
    /*
         * We pass this into addPieces to tell it where to generate the structure.
         * If addPieces's last parameter is true, blockpos's Y value is ignored and the
         * structure will spawn at terrain height instead. Set that parameter to false to
         * force the structure to spawn at blockpos's Y value instead. You got options here!
         * -- TelepathicGrunt
         */
    BTJigsawConfiguration config = new BTJigsawConfiguration(() -> context.registryAccess().ownedRegistryOrThrow(Registry.TEMPLATE_POOL_REGISTRY).get(new ResourceLocation(BrassAmberBattleTowers.MOD_ID, "land_tower/start_pool")), // As long as it is more than the total number of possible connections the tower will spawn correctly.
    12);
    PieceGeneratorSupplier.Context<BTJigsawConfiguration> baseTower = new PieceGeneratorSupplier.Context<>(context.chunkGenerator(), context.biomeSource(), context.seed(), context.chunkPos(), config, context.heightAccessor(), context.validBiome(), context.structureManager(), context.registryAccess());
    // Get chunk center coordinates
    BlockPos centerPos = context.chunkPos().getMiddleBlockPosition(0);
    Optional<PieceGenerator<BTJigsawConfiguration>> piecesGenerator;
    // All a structure has to do is call this method to turn it into a jigsaw based structure!
    piecesGenerator = BTLandJigsawPlacement.addPieces(// Used for JigsawPlacement to get all the proper behaviors done.
    baseTower, // Needed in order to create a list of jigsaw pieces when making the structure's layout.
    PoolElementStructurePiece::new, // Position of the structure. Y value is ignored if last parameter is set to true. --TelepathicGrunt
    centerPos, // Special boundary adjustments for villages. It's... hard to explain. Keep this false and make your pieces not be partially intersecting. --TelepathicGrunt
    false, // Place at heightmap (top land). Set this to false for structure to be place at the passed in blockpos's Y value instead.
    true, // null here == random rotation.
    false);
    if (piecesGenerator.isPresent()) {
        // I use to debug and quickly find out if the structure is spawning or not and where it is.
        // This is returning the coordinates of the center starting piece.
        BrassAmberBattleTowers.LOGGER.info("Land Tower at " + centerPos);
    }
    // Return the pieces generator that is now set up so that the game runs it when it needs to create the layout of structure pieces.
    return piecesGenerator;
}
Also used : PieceGeneratorSupplier(net.minecraft.world.level.levelgen.structure.pieces.PieceGeneratorSupplier) ResourceLocation(net.minecraft.resources.ResourceLocation) BlockPos(net.minecraft.core.BlockPos) BTJigsawConfiguration(com.BrassAmber.ba_bt.worldGen.BTJigsawConfiguration) PieceGenerator(net.minecraft.world.level.levelgen.structure.pieces.PieceGenerator) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

BlockPos (net.minecraft.core.BlockPos)13 PieceGenerator (net.minecraft.world.level.levelgen.structure.pieces.PieceGenerator)13 PoolElementStructurePiece (net.minecraft.world.level.levelgen.structure.PoolElementStructurePiece)11 PieceGeneratorSupplier (net.minecraft.world.level.levelgen.structure.pieces.PieceGeneratorSupplier)7 JigsawConfiguration (net.minecraft.world.level.levelgen.feature.configurations.JigsawConfiguration)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 LegacyRandomSource (net.minecraft.world.level.levelgen.LegacyRandomSource)3 WorldgenRandom (net.minecraft.world.level.levelgen.WorldgenRandom)3 BTJigsawConfiguration (com.BrassAmber.ba_bt.worldGen.BTJigsawConfiguration)2 RepurposedStructures (com.telepathicgrunt.repurposedstructures.RepurposedStructures)2 Function (java.util.function.Function)2 Predicate (java.util.function.Predicate)2 Heightmap (net.minecraft.world.level.levelgen.Heightmap)2