Search in sources :

Example 1 with BTJigsawConfiguration

use of com.BrassAmber.ba_bt.worldGen.BTJigsawConfiguration 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)

Example 2 with BTJigsawConfiguration

use of com.BrassAmber.ba_bt.worldGen.BTJigsawConfiguration in project Brass_Amber_BattleTowers by BrassAmber-Mods.

the class OvergrownLandTower 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 (!OvergrownLandTower.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(BrassAmberBattleTowers.locate("land_tower/start_pool_overgrown")), // As long as it is more than the total number of possible connections the tower will spawn correctly.
    8);
    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.
    watered);
    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("Overgrown 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) 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

BTJigsawConfiguration (com.BrassAmber.ba_bt.worldGen.BTJigsawConfiguration)2 BlockPos (net.minecraft.core.BlockPos)2 PieceGenerator (net.minecraft.world.level.levelgen.structure.pieces.PieceGenerator)2 PieceGeneratorSupplier (net.minecraft.world.level.levelgen.structure.pieces.PieceGeneratorSupplier)2 NotNull (org.jetbrains.annotations.NotNull)2 ResourceLocation (net.minecraft.resources.ResourceLocation)1