Search in sources :

Example 1 with Structure

use of net.minecraft.structure.Structure 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)

Example 2 with Structure

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

the class SimpleStructurePieceMixin method generate.

@Inject(method = "generate", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/structure/Structure;getInfosForBlock(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/structure/StructurePlacementData;Lnet/minecraft/block/Block;)Ljava/util/List;"))
public void generate(StructureWorldAccess world, StructureAccessor structureAccessor, ChunkGenerator chunkGenerator, Random random, BlockBox box, ChunkPos chunkPos, BlockPos blockPos, CallbackInfoReturnable<Boolean> cbi) {
    if (this instanceof DirectionalDataHandler) {
        List<Structure.StructureBlockInfo> list = this.structure.getInfosForBlock(this.pos, this.placementData, BMBlocks.DIRECTIONAL_DATA);
        for (Structure.StructureBlockInfo info : list) {
            if (info.tag != null) {
                String meta = info.tag.getString("metadata");
                Direction dir = info.state.get(FacingBlock.FACING);
                world.setBlockState(info.pos, Blocks.AIR.getDefaultState(), 3);
                ((DirectionalDataHandler) this).handleDirectionalMetadata(meta, dir, info.pos, world, random, box);
            }
        }
    }
}
Also used : DirectionalDataHandler(party.lemons.biomemakeover.util.DirectionalDataHandler) Structure(net.minecraft.structure.Structure) Direction(net.minecraft.util.math.Direction) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

Structure (net.minecraft.structure.Structure)2 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 Direction (net.minecraft.util.math.Direction)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1 DirectionalDataHandler (party.lemons.biomemakeover.util.DirectionalDataHandler)1