Search in sources :

Example 11 with StructureManager

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

Example 12 with StructureManager

use of net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager in project The-Aether by Gilded-Games.

the class CrystalTreeFeature method place.

@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> context) {
    WorldGenLevel reader = context.level();
    BlockPos pos = context.origin();
    Random rand = context.random();
    Rotation rotation = Rotation.getRandom(rand);
    StructureManager templatemanager = reader.getLevel().getServer().getStructureManager();
    StructureTemplate tree = templatemanager.getOrCreate(TREE);
    StructureTemplate fruit = templatemanager.getOrCreate(FRUIT);
    ChunkPos chunkpos = new ChunkPos(pos);
    BoundingBox mutableboundingbox = new BoundingBox(chunkpos.getMinBlockX(), 0, chunkpos.getMinBlockZ(), chunkpos.getMaxBlockX(), 256, chunkpos.getMaxBlockZ());
    StructurePlaceSettings placementsettings = (new StructurePlaceSettings()).setRotation(rotation).setBoundingBox(mutableboundingbox).setRandom(rand).addProcessor(BlockIgnoreProcessor.STRUCTURE_AND_AIR);
    Vec3i vec3i = tree.getSize(rotation);
    int x = rand.nextInt(16 - vec3i.getX());
    int z = rand.nextInt(16 - vec3i.getZ());
    int y = Math.max(Math.min(reader.getHeight(Heightmap.Types.OCEAN_FLOOR_WG, pos.getX() + x, pos.getZ() + z) + rand.nextInt(20) + 40, 200), 100);
    BlockPos blockpos1 = tree.getZeroPositionWithTransform(pos.offset(x, y, z), Mirror.NONE, rotation);
    tree.placeInWorld(reader, blockpos1, blockpos1, placementsettings, rand, 4);
    BlockRotProcessor integrityprocessor = new BlockRotProcessor(0.2F);
    placementsettings.clearProcessors().addProcessor(integrityprocessor);
    fruit.placeInWorld(reader, blockpos1, blockpos1, placementsettings, rand, 4);
    return true;
}
Also used : Vec3i(net.minecraft.core.Vec3i) BlockRotProcessor(net.minecraft.world.level.levelgen.structure.templatesystem.BlockRotProcessor) Random(java.util.Random) BoundingBox(net.minecraft.world.level.levelgen.structure.BoundingBox) StructureManager(net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager) BlockPos(net.minecraft.core.BlockPos) StructureTemplate(net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate) ChunkPos(net.minecraft.world.level.ChunkPos) StructurePlaceSettings(net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings) Rotation(net.minecraft.world.level.block.Rotation) WorldGenLevel(net.minecraft.world.level.WorldGenLevel)

Example 13 with StructureManager

use of net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager in project The-Aether by Gilded-Games.

the class HolidayTreeFeature method place.

@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> context) {
    BlockPos pos = context.origin();
    Random rand = context.random();
    WorldGenLevel reader = context.level();
    Calendar calendar = Calendar.getInstance();
    if ((AetherConfig.COMMON.generate_holiday_tree_seasonally.get() && (calendar.get(Calendar.MONTH) == Calendar.DECEMBER || calendar.get(Calendar.MONTH) == Calendar.JANUARY)) || AetherConfig.COMMON.generate_holiday_tree_always.get()) {
        Rotation rotation = Rotation.getRandom(rand);
        StructureManager templatemanager = reader.getLevel().getServer().getStructureManager();
        StructureTemplate tree = templatemanager.getOrCreate(TREE);
        StructureTemplate decor = templatemanager.getOrCreate(DECORATION);
        ChunkPos chunkpos = new ChunkPos(pos);
        BoundingBox mutableboundingbox = new BoundingBox(chunkpos.getMinBlockX(), 0, chunkpos.getMinBlockZ(), chunkpos.getMaxBlockX(), 256, chunkpos.getMaxBlockZ());
        StructurePlaceSettings placementsettings = (new StructurePlaceSettings()).setRotation(rotation).setBoundingBox(mutableboundingbox).setRandom(rand).addProcessor(BlockIgnoreProcessor.STRUCTURE_AND_AIR);
        Vec3i size = tree.getSize(rotation);
        int rx = Math.floorDiv(size.getX(), 2);
        int rz = Math.floorDiv(size.getZ(), 2);
        int x = rand.nextInt(16 - size.getX());
        int z = rand.nextInt(16 - size.getZ());
        int y = reader.getHeight(Heightmap.Types.OCEAN_FLOOR_WG, pos.getX() + x + rx, pos.getZ() + z + rz);
        if (y <= 48)
            return true;
        pos = pos.offset(x, y, z);
        for (int i = -rx * 2; i < rx * 2 + 1; i++) {
            for (int j = -rz * 2; j < rz * 2 + 1; j++) {
                if (i * i + j * j <= 3.5 * rx * rx) {
                    y = reader.getHeight(Heightmap.Types.OCEAN_FLOOR_WG, pos.getX() + rx + i, pos.getZ() + rz + j);
                    if (y <= 48)
                        continue;
                    BlockPos pos1 = new BlockPos(pos.getX() + rx + i, y, pos.getZ() + rz + j);
                    if (rand.nextInt(6) == 0) {
                        this.setBlock(reader, pos1, AetherBlocks.PRESENT.get().defaultBlockState());
                    } else {
                        this.setBlock(reader, pos1, Blocks.SNOW.defaultBlockState());
                    }
                }
            }
        }
        BlockPos blockpos1 = tree.getZeroPositionWithTransform(pos, Mirror.NONE, rotation);
        tree.placeInWorld(reader, blockpos1, blockpos1, placementsettings, rand, 4);
        BlockRotProcessor integrityprocessor = new BlockRotProcessor(0.2F);
        placementsettings.clearProcessors().addProcessor(integrityprocessor);
        decor.placeInWorld(reader, blockpos1, blockpos1, placementsettings, rand, 4);
    }
    return true;
}
Also used : Vec3i(net.minecraft.core.Vec3i) BlockRotProcessor(net.minecraft.world.level.levelgen.structure.templatesystem.BlockRotProcessor) Calendar(java.util.Calendar) StructureManager(net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager) Rotation(net.minecraft.world.level.block.Rotation) Random(java.util.Random) BoundingBox(net.minecraft.world.level.levelgen.structure.BoundingBox) BlockPos(net.minecraft.core.BlockPos) StructureTemplate(net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate) ChunkPos(net.minecraft.world.level.ChunkPos) StructurePlaceSettings(net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings) WorldGenLevel(net.minecraft.world.level.WorldGenLevel)

Example 14 with StructureManager

use of net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager in project TerraFirmaCraft by TerraFirmaCraft.

the class StackedTreeFeature method place.

@Override
public boolean place(FeaturePlaceContext<StackedTreeConfig> context) {
    final WorldGenLevel worldIn = context.level();
    final BlockPos pos = context.origin();
    final Random random = context.random();
    final StackedTreeConfig config = context.config();
    final ChunkPos chunkPos = new ChunkPos(pos);
    final BlockPos.MutableBlockPos mutablePos = new BlockPos.MutableBlockPos().set(pos);
    final StructureManager manager = TreeHelpers.getStructureManager(worldIn);
    final StructurePlaceSettings settings = TreeHelpers.getPlacementSettings(worldIn, chunkPos, random);
    if (!isValidLocation(worldIn, mutablePos) || !isAreaClear(worldIn, mutablePos, config.radius(), 2)) {
        return false;
    }
    // Trunk first
    int trunkHeight = TreeHelpers.placeTrunk(worldIn, mutablePos, random, settings, config.trunk());
    mutablePos.move(0, trunkHeight, 0);
    for (StackedTreeConfig.Layer layer : config.layers()) {
        // Place each layer
        int layerCount = layer.getCount(random);
        for (int i = 0; i < layerCount; i++) {
            final ResourceLocation structureId = layer.templates().get(random.nextInt(layer.templates().size()));
            final StructureTemplate structure = manager.getOrCreate(structureId);
            TreeHelpers.placeTemplate(structure, settings, worldIn, mutablePos.subtract(TreeHelpers.transformCenter(structure.getSize(), settings)));
            mutablePos.move(0, structure.getSize().getY(), 0);
        }
    }
    return true;
}
Also used : Random(java.util.Random) ResourceLocation(net.minecraft.resources.ResourceLocation) StructureManager(net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager) BlockPos(net.minecraft.core.BlockPos) ChunkPos(net.minecraft.world.level.ChunkPos) StructurePlaceSettings(net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings) StructureTemplate(net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate) WorldGenLevel(net.minecraft.world.level.WorldGenLevel)

Example 15 with StructureManager

use of net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager in project SolarCraftRepository by FINDERFEED.

the class RadiantLandFloatingIslands method place.

@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> ctx) {
    WorldGenLevel world = ctx.level();
    if (AVAILABLE_TO_SPAWN == null) {
        initList(world);
    }
    BlockPos pos = ctx.origin();
    Random random = ctx.random();
    Rotation rot = Rotation.getRandom(random);
    StructureManager manager = world.getLevel().getStructureManager();
    StructureTemplate templ = manager.getOrCreate(List.of(ISLAND1, ISLAND2, ISLAND3, ISLAND4).get(random.nextInt(4)));
    StructurePlaceSettings set = new StructurePlaceSettings().addProcessor(BlockIgnoreProcessor.AIR).setRandom(random).setRotation(rot).setBoundingBox(BoundingBox.infinite());
    BlockPos blockpos1 = templ.getZeroPositionWithTransform(pos.offset(0, 1, 0), Mirror.NONE, rot);
    templ.placeInWorld(world, blockpos1, blockpos1, set, random, 4);
    templ.filterBlocks(blockpos1, set, Blocks.SEA_LANTERN).forEach((info) -> {
        setBlock(world, info.pos, AVAILABLE_TO_SPAWN.get(world.getRandom().nextInt(AVAILABLE_TO_SPAWN.size())).defaultBlockState());
    });
    return true;
}
Also used : Random(java.util.Random) StructureManager(net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager) BlockPos(net.minecraft.core.BlockPos) StructureTemplate(net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate) StructurePlaceSettings(net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings) Rotation(net.minecraft.world.level.block.Rotation) WorldGenLevel(net.minecraft.world.level.WorldGenLevel)

Aggregations

StructureManager (net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager)18 BlockPos (net.minecraft.core.BlockPos)17 StructureTemplate (net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate)17 StructurePlaceSettings (net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings)14 WorldGenLevel (net.minecraft.world.level.WorldGenLevel)13 Random (java.util.Random)11 Rotation (net.minecraft.world.level.block.Rotation)10 ResourceLocation (net.minecraft.resources.ResourceLocation)8 ChunkPos (net.minecraft.world.level.ChunkPos)5 BlockState (net.minecraft.world.level.block.state.BlockState)4 BoundingBox (net.minecraft.world.level.levelgen.structure.BoundingBox)3 BlockRotProcessor (net.minecraft.world.level.levelgen.structure.templatesystem.BlockRotProcessor)3 Vec3i (net.minecraft.core.Vec3i)2 TemplateAccessor (com.telepathicgrunt.repurposedstructures.mixin.structures.TemplateAccessor)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 LevelHeightAccessor (net.minecraft.world.level.LevelHeightAccessor)1 Biome (net.minecraft.world.level.biome.Biome)1 ChunkAccess (net.minecraft.world.level.chunk.ChunkAccess)1 ChunkGenerator (net.minecraft.world.level.chunk.ChunkGenerator)1