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;
}
Aggregations