use of net.minecraft.util.BlockRotation in project Biome-Makeover by Lemonszz.
the class SunkenRuinFeature method createSmaller.
private static void createSmaller(StructureManager manager, Random random, BlockRotation rotation, BlockPos pos, List<StructurePiece> pieces) {
int x = pos.getX();
int z = pos.getZ();
BlockPos blockPos = Structure.transformAround(new BlockPos(15, 0, 15), BlockMirror.NONE, rotation, BlockPos.ORIGIN).add(x, 0, z);
BlockBox blockBox = BlockBox.create(x, 0, z, blockPos.getX(), 0, blockPos.getZ());
BlockPos blockPos2 = new BlockPos(Math.min(x, blockPos.getX()), 0, Math.min(z, blockPos.getZ()));
List<BlockPos> possiblePositions = getRoomPositions(random, blockPos2.getX(), blockPos2.getZ());
int attempts = MathHelper.nextInt(random, 4, 8);
for (int l = 0; l < attempts; ++l) {
if (!possiblePositions.isEmpty()) {
int index = random.nextInt(possiblePositions.size());
BlockPos checkPos = possiblePositions.remove(index);
int checkX = checkPos.getX();
int checkZ = checkPos.getZ();
BlockRotation blockRotation = BlockRotation.random(random);
BlockPos blockPos4 = Structure.transformAround(new BlockPos(5, 0, 6), BlockMirror.NONE, blockRotation, BlockPos.ORIGIN).add(checkX, 0, checkZ);
BlockBox blockBox2 = BlockBox.create(checkX, 0, checkZ, blockPos4.getX(), 0, blockPos4.getZ());
if (!blockBox2.intersects(blockBox)) {
addPieces(manager, checkPos, blockRotation, pieces, random, false);
}
}
}
}
use of net.minecraft.util.BlockRotation 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;
}
use of net.minecraft.util.BlockRotation in project Liminal-Library by LudoCrypt.
the class NbtPlacerUtil method rotate.
public NbtPlacerUtil rotate(BlockRotation rotation) {
NbtList paletteList = storedNbt.getList("palette", 10);
HashMap<Integer, BlockState> palette = new HashMap<Integer, BlockState>(paletteList.size());
List<NbtCompound> paletteCompoundList = paletteList.stream().filter(nbtElement -> nbtElement instanceof NbtCompound).map(element -> (NbtCompound) element).toList();
for (int i = 0; i < paletteCompoundList.size(); i++) {
palette.put(i, NbtHelper.toBlockState(paletteCompoundList.get(i)).rotate(rotation));
}
NbtList sizeList = storedNbt.getList("size", 3);
BlockPos sizeVectorRotated = new BlockPos(sizeList.getInt(0), sizeList.getInt(1), sizeList.getInt(2)).rotate(rotation);
BlockPos sizeVector = new BlockPos(Math.abs(sizeVectorRotated.getX()), Math.abs(sizeVectorRotated.getY()), Math.abs(sizeVectorRotated.getZ()));
NbtList positionsList = storedNbt.getList("blocks", 10);
HashMap<BlockPos, Pair<BlockState, NbtCompound>> positions = new HashMap<BlockPos, Pair<BlockState, NbtCompound>>(positionsList.size());
List<Pair<BlockPos, Pair<BlockState, NbtCompound>>> positionsPairList = positionsList.stream().filter(nbtElement -> nbtElement instanceof NbtCompound).map(element -> (NbtCompound) element).map((nbtCompound) -> Pair.of(new BlockPos(nbtCompound.getList("pos", 3).getInt(0), nbtCompound.getList("pos", 3).getInt(1), nbtCompound.getList("pos", 3).getInt(2)).rotate(rotation), Pair.of(palette.get(nbtCompound.getInt("state")), nbtCompound.getCompound("nbt")))).sorted(Comparator.comparing((pair) -> pair.getFirst().getX())).sorted(Comparator.comparing((pair) -> pair.getFirst().getY())).sorted(Comparator.comparing((pair) -> pair.getFirst().getZ())).toList();
positionsPairList.forEach((pair) -> positions.put(pair.getFirst().subtract(positionsPairList.get(0).getFirst()), pair.getSecond()));
return new NbtPlacerUtil(storedNbt, positions, storedNbt.getList("entities", 10), positionsPairList.get(0).getFirst(), sizeVector);
}
Aggregations