Search in sources :

Example 1 with BlockRotation

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);
            }
        }
    }
}
Also used : BlockBox(net.minecraft.util.math.BlockBox) BlockPos(net.minecraft.util.math.BlockPos) BlockRotation(net.minecraft.util.BlockRotation)

Example 2 with BlockRotation

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;
}
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 3 with BlockRotation

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);
}
Also used : EntityType(net.minecraft.entity.EntityType) NbtIo(net.minecraft.nbt.NbtIo) NbtList(net.minecraft.nbt.NbtList) ChunkRegion(net.minecraft.world.ChunkRegion) HashMap(java.util.HashMap) Resource(net.minecraft.resource.Resource) Direction(net.minecraft.util.math.Direction) NbtDouble(net.minecraft.nbt.NbtDouble) Vec3d(net.minecraft.util.math.Vec3d) BlockState(net.minecraft.block.BlockState) Entity(net.minecraft.entity.Entity) TriConsumer(org.apache.logging.log4j.util.TriConsumer) BlockRotation(net.minecraft.util.BlockRotation) NbtFloat(net.minecraft.nbt.NbtFloat) IOException(java.io.IOException) BlockPos(net.minecraft.util.math.BlockPos) NbtHelper(net.minecraft.nbt.NbtHelper) ResourceManager(net.minecraft.resource.ResourceManager) Pair(com.mojang.datafixers.util.Pair) Blocks(net.minecraft.block.Blocks) NbtInt(net.minecraft.nbt.NbtInt) NbtCompound(net.minecraft.nbt.NbtCompound) List(java.util.List) MathHelper(net.minecraft.util.math.MathHelper) Optional(java.util.Optional) Identifier(net.minecraft.util.Identifier) Comparator(java.util.Comparator) NbtCompound(net.minecraft.nbt.NbtCompound) HashMap(java.util.HashMap) BlockState(net.minecraft.block.BlockState) NbtList(net.minecraft.nbt.NbtList) BlockPos(net.minecraft.util.math.BlockPos) Pair(com.mojang.datafixers.util.Pair)

Aggregations

BlockRotation (net.minecraft.util.BlockRotation)3 BlockPos (net.minecraft.util.math.BlockPos)3 BlockBox (net.minecraft.util.math.BlockBox)2 Pair (com.mojang.datafixers.util.Pair)1 IOException (java.io.IOException)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Optional (java.util.Optional)1 BlockState (net.minecraft.block.BlockState)1 Blocks (net.minecraft.block.Blocks)1 Entity (net.minecraft.entity.Entity)1 EntityType (net.minecraft.entity.EntityType)1 NbtCompound (net.minecraft.nbt.NbtCompound)1 NbtDouble (net.minecraft.nbt.NbtDouble)1 NbtFloat (net.minecraft.nbt.NbtFloat)1 NbtHelper (net.minecraft.nbt.NbtHelper)1 NbtInt (net.minecraft.nbt.NbtInt)1 NbtIo (net.minecraft.nbt.NbtIo)1 NbtList (net.minecraft.nbt.NbtList)1