Search in sources :

Example 1 with StructureManager

use of net.minecraft.structure.StructureManager in project Biome-Makeover by Lemonszz.

the class SurfaceFossilFeature method generate.

@Override
public boolean generate(StructureWorldAccess structureWorldAccess, ChunkGenerator chunkGenerator, Random random, BlockPos blockPos, DefaultFeatureConfig defaultFeatureConfig) {
    BlockRotation rot = BlockRotation.random(random);
    int fossilIndex = random.nextInt(FOSSILS.length);
    StructureManager structureManager = structureWorldAccess.toServerWorld().getServer().getStructureManager();
    Structure structure = structureManager.getStructureOrBlank(FOSSILS[fossilIndex]);
    ChunkPos chunkPos = new ChunkPos(blockPos);
    BlockBox blockBox = new BlockBox(chunkPos.getStartX(), 0, chunkPos.getStartZ(), chunkPos.getEndX(), 256, chunkPos.getEndZ());
    StructurePlacementData placeData = (new StructurePlacementData()).setRotation(rot).setBoundingBox(blockBox).setRandom(random).addProcessor(BlockIgnoreStructureProcessor.IGNORE_STRUCTURE_BLOCKS);
    BlockPos size = structure.getRotatedSize(rot);
    int x = random.nextInt(16 - size.getX());
    int z = random.nextInt(16 - size.getZ());
    int y = 256;
    for (int xx = 0; xx < size.getX(); xx++) {
        for (int zz = 0; zz < size.getZ(); ++zz) {
            y = Math.min(y, structureWorldAccess.getTopY(Heightmap.Type.OCEAN_FLOOR_WG, blockPos.getX() + xx + x, blockPos.getZ() + zz + z));
        }
    }
    if (fossilIndex < 4)
        y -= RandomUtil.randomRange(1, Math.max(2, size.getY() - 2));
    BlockPos generatePos = structure.offsetByTransformedSize(blockPos.add(x, y, z), BlockMirror.NONE, rot);
    BlockRotStructureProcessor process = new BlockRotStructureProcessor(1F);
    placeData.clearProcessors().addProcessor(process);
    structure.place(structureWorldAccess, generatePos, generatePos, placeData, random, 4);
    return true;
}
Also used : StructurePlacementData(net.minecraft.structure.StructurePlacementData) BlockBox(net.minecraft.util.math.BlockBox) BlockRotStructureProcessor(net.minecraft.structure.processor.BlockRotStructureProcessor) StructureManager(net.minecraft.structure.StructureManager) ChunkPos(net.minecraft.util.math.ChunkPos) BlockPos(net.minecraft.util.math.BlockPos) BlockRotation(net.minecraft.util.BlockRotation) Structure(net.minecraft.structure.Structure)

Aggregations

Structure (net.minecraft.structure.Structure)1 StructureManager (net.minecraft.structure.StructureManager)1 StructurePlacementData (net.minecraft.structure.StructurePlacementData)1 BlockRotStructureProcessor (net.minecraft.structure.processor.BlockRotStructureProcessor)1 BlockRotation (net.minecraft.util.BlockRotation)1 BlockBox (net.minecraft.util.math.BlockBox)1 BlockPos (net.minecraft.util.math.BlockPos)1 ChunkPos (net.minecraft.util.math.ChunkPos)1