Search in sources :

Example 1 with BlockBox

use of net.minecraft.util.math.BlockBox in project lithium-fabric by CaffeineMC.

the class NearbyEntityListener method forEachChunkInRangeChange.

/**
 * Calls the callbacks for the chunk coordinates that this listener is leaving and entering
 */
default void forEachChunkInRangeChange(SectionedEntityCache<? extends EntityLike> entityCache, ChunkSectionPos prevCenterPos, ChunkSectionPos newCenterPos) {
    Range6Int chunkRange = this.getChunkRange();
    if (chunkRange == EMPTY_RANGE) {
        return;
    }
    BlockPos.Mutable pos = new BlockPos.Mutable();
    BlockBox after = newCenterPos == null ? null : new BlockBox(newCenterPos.getX() - chunkRange.negativeX(), newCenterPos.getY() - chunkRange.negativeY(), newCenterPos.getZ() - chunkRange.negativeZ(), newCenterPos.getX() + chunkRange.positiveX(), newCenterPos.getY() + chunkRange.positiveY(), newCenterPos.getZ() + chunkRange.positiveZ());
    BlockBox before = prevCenterPos == null ? null : new BlockBox(prevCenterPos.getX() - chunkRange.negativeX(), prevCenterPos.getY() - chunkRange.negativeY(), prevCenterPos.getZ() - chunkRange.negativeZ(), prevCenterPos.getX() + chunkRange.positiveX(), prevCenterPos.getY() + chunkRange.positiveY(), prevCenterPos.getZ() + chunkRange.positiveZ());
    if (before != null) {
        for (int x = before.getMinX(); x <= before.getMaxX(); x++) {
            for (int y = before.getMinY(); y <= before.getMaxY(); y++) {
                for (int z = before.getMinZ(); z <= before.getMaxZ(); z++) {
                    if (after == null || !after.contains(pos.set(x, y, z))) {
                        long sectionPos = ChunkSectionPos.asLong(x, y, z);
                        EntityTrackingSection<? extends EntityLike> trackingSection = entityCache.getTrackingSection(sectionPos);
                        ((EntityTrackerSection) trackingSection).removeListener(entityCache, this);
                        if (trackingSection.isEmpty()) {
                            entityCache.removeSection(sectionPos);
                        }
                    }
                }
            }
        }
    }
    if (after != null) {
        for (int x = after.getMinX(); x <= after.getMaxX(); x++) {
            for (int y = after.getMinY(); y <= after.getMaxY(); y++) {
                for (int z = after.getMinZ(); z <= after.getMaxZ(); z++) {
                    if (before == null || !before.contains(pos.set(x, y, z))) {
                        ((EntityTrackerSection) entityCache.getTrackingSection(ChunkSectionPos.asLong(x, y, z))).addListener(this);
                    }
                }
            }
        }
    }
}
Also used : Range6Int(me.jellysquid.mods.lithium.common.util.tuples.Range6Int) BlockBox(net.minecraft.util.math.BlockBox) EntityTrackerSection(me.jellysquid.mods.lithium.common.entity.tracker.EntityTrackerSection) BlockPos(net.minecraft.util.math.BlockPos)

Example 2 with BlockBox

use of net.minecraft.util.math.BlockBox in project SeedcrackerX by 19MisterX98.

the class ShipwreckFinder method onChestFound.

/**
 * Source: https://github.com/skyrising/casual-mod/blob/master/src/main/java/de/skyrising/casual/ShipwreckFinder.java
 */
private boolean onChestFound(BlockPos pos) {
    BlockPos.Mutable mutablePos = new BlockPos.Mutable(pos.getX(), pos.getY(), pos.getZ());
    Direction chestFacing = world.getBlockState(pos).get(ChestBlock.FACING);
    int[] stairs = new int[4];
    int totalStairs = 0;
    int[] trapdoors = new int[4];
    int totalTrapdoors = 0;
    for (int y = -1; y <= 2; y++) {
        for (int x = -1; x <= 1; x++) {
            for (int z = -1; z <= 1; z++) {
                if (x == 0 && y == 0 && z == 0)
                    continue;
                mutablePos.set(pos.getX() + x, pos.getY() + y, pos.getZ() + z);
                BlockState neighborState = world.getBlockState(mutablePos);
                Block neighborBlock = neighborState.getBlock();
                if (neighborBlock == Blocks.VOID_AIR)
                    return false;
                if (neighborBlock instanceof StairsBlock) {
                    stairs[y + 1]++;
                    totalStairs++;
                } else if (neighborBlock instanceof TrapdoorBlock) {
                    trapdoors[y + 1]++;
                    totalTrapdoors++;
                }
            }
        }
    }
    int chestX = 4;
    int chestY = 2;
    int chestZ = 0;
    int length = 16;
    int height = 9;
    Direction direction = chestFacing;
    if (trapdoors[3] > 4) {
        // with_mast[_degraded]
        chestZ = 9;
        height = 21;
        length = 28;
    } else if (totalTrapdoors == 0 && stairs[3] == 3) {
        // upsidedown_backhalf[_degraded]
        if (stairs[0] == 0) {
            chestX = 2;
            chestZ = 12;
            direction = chestFacing.getOpposite();
        } else {
            // upsidedown front
            chestX = 3;
            chestY = 5;
            chestZ = 17;
            length = 22;
            direction = chestFacing.rotateYClockwise();
        }
    } else if (totalTrapdoors == 0) {
        // rightsideup that have backhalf
        if (stairs[0] == 4) {
            if (totalStairs > 4) {
                chestX = 6;
                chestY = 4;
                chestZ = 12;
                direction = chestFacing.getOpposite();
            } else {
                // sideways backhalf
                chestX = 6;
                chestY = 3;
                chestZ = 8;
                length = 17;
                direction = chestFacing.getOpposite();
            }
        } else if (stairs[0] == 3 && totalStairs > 5) {
            chestX = 5;
            chestZ = 6;
            direction = chestFacing.rotateYCounterclockwise();
        } else if (totalStairs == 3 && stairs[0] == 1 && stairs[2] == 1 && stairs[3] == 1) {
            // upsidedown full
            chestX = 3;
            chestY = 5;
            chestZ = 17;
            length = 28;
            direction = chestFacing.rotateYClockwise();
        }
        mutablePos.set(pos);
        mutablePos.move(0, -chestY, 0);
        mutablePos.move(direction.rotateYClockwise(), chestX - 4);
        mutablePos.move(direction, -chestZ - 1);
        if (this.world.getBlockState(mutablePos).getMaterial() == Material.WOOD) {
            if (length == 17) {
                // sideways
                chestZ += 11;
                length += 11;
            } else {
                chestZ += 12;
                length += 12;
            }
            mutablePos.move(0, 10, 0);
            if (this.world.getBlockState(mutablePos).isIn(BlockTags.LOGS)) {
                height = 21;
            }
        }
    } else if (totalTrapdoors == 2 && trapdoors[3] == 2 && stairs[3] == 3) {
        // rightsideup_fronthalf[_degraded]
        chestZ = 8;
        length = 24;
    } else if (totalTrapdoors == 2 && totalStairs == 4 && stairs[0] == 2) {
        // sideways-fronthalf
        chestX = 5;
        chestY = 3;
        chestZ = 8;
        length = 24;
    }
    if (chestZ != 0) {
        mutablePos.set(pos);
        mutablePos.move(direction, 15 - chestZ);
        mutablePos.move(direction.rotateYClockwise(), chestX - 4);
        BlockPos.Mutable pos2 = new BlockPos.Mutable(mutablePos.getX(), mutablePos.getY(), mutablePos.getZ());
        pos2.move(0, -chestY, 0);
        pos2.move(direction, -15);
        pos2.move(direction.rotateYClockwise(), 4);
        BlockPos.Mutable pos3 = new BlockPos.Mutable(pos2.getX(), pos2.getY(), pos2.getZ());
        pos3.move(direction, length - 1);
        pos3.move(direction.rotateYClockwise(), -8);
        pos3.move(0, height - 1, 0);
        BlockBox box = new BlockBox(Math.min(pos2.getX(), pos3.getX()), pos2.getY(), Math.min(pos2.getZ(), pos3.getZ()), Math.max(pos2.getX(), pos3.getX()) + 1, pos3.getY() + 1, Math.max(pos2.getZ(), pos3.getZ()) + 1);
        mutablePos.move(-4, -chestY, -15);
        if ((mutablePos.getX() & 0xf) == 0 && (mutablePos.getZ() & 0xf) == 0) {
            RegionStructure.Data<?> data = Features.SHIPWRECK.at(new ChunkPos(mutablePos).x, new ChunkPos(mutablePos).z);
            if (SeedCracker.get().getDataStorage().addBaseData(data, DataAddedEvent.POKE_LIFTING)) {
                this.renderers.add(new Cuboid(box, new Color(0, 255, 255)));
                this.renderers.add(new Cube(new ChunkPos(mutablePos).getStartPos().offset(Direction.UP, mutablePos.getY()), new Color(0, 255, 255)));
                return true;
            }
        }
    }
    return false;
}
Also used : BlockBox(net.minecraft.util.math.BlockBox) Color(kaptainwutax.seedcrackerX.render.Color) Cuboid(kaptainwutax.seedcrackerX.render.Cuboid) Direction(net.minecraft.util.math.Direction) Cube(kaptainwutax.seedcrackerX.render.Cube) BlockPos(net.minecraft.util.math.BlockPos) ChunkPos(net.minecraft.util.math.ChunkPos) RegionStructure(com.seedfinding.mcfeature.structure.RegionStructure)

Example 3 with BlockBox

use of net.minecraft.util.math.BlockBox 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 4 with BlockBox

use of net.minecraft.util.math.BlockBox 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 5 with BlockBox

use of net.minecraft.util.math.BlockBox in project Biome-Makeover by Lemonszz.

the class WillowFoliagePlacer method generate.

protected void generate(ModifiableTestableWorld world, Random random, TreeFeatureConfig config, int trunkHeight, FoliagePlacer.TreeNode treeNode, int foliageHeight, int radius, Set<BlockPos> leaves, int offset, BlockBox box) {
    for (int placeOffset = offset; placeOffset >= offset - foliageHeight; --placeOffset) {
        int baseHeight;
        if (treeNode.getFoliageRadius() > 0)
            baseHeight = Math.max(radius + treeNode.getFoliageRadius() - 1 - placeOffset / 2, 0);
        else
            baseHeight = Math.max(radius + treeNode.getFoliageRadius() - placeOffset / 2, 0);
        this.generateSquare(world, random, config, treeNode.getCenter(), baseHeight, leaves, placeOffset, treeNode.isGiantTrunk(), box);
    }
    BlockBox leafBox = BlockBox.empty();
    for (BlockPos leafPos : leaves) {
        leafBox.encompass(new BlockBox(leafPos, leafPos));
    }
    for (int i = 0; i < 4 + random.nextInt(8); i++) {
        BlockPos.Mutable downPos = new BlockPos.Mutable(RandomUtil.randomRange(box.minX, box.maxX), leafBox.minY - 1, RandomUtil.randomRange(box.minZ, box.maxZ));
        if (TreeFeature.canReplace(world, downPos) && world.testBlockState(downPos.up(), (state) -> state.isIn(BlockTags.LEAVES))) {
            world.setBlockState(downPos, config.leavesProvider.getBlockState(random, downPos), 19);
            box.encompass(new BlockBox(downPos, downPos));
            leaves.add(downPos.toImmutable());
        }
    }
    if (// TODO: this should be a tree decorator
    doWillows)
        for (int i = 0; i < 10; i++) {
            BlockPos.Mutable pos = new BlockPos.Mutable(RandomUtil.randomRange(box.minX, box.maxX), leafBox.minY, RandomUtil.randomRange(box.minZ, box.maxZ));
            for (int j = 0; j < 3; j++) {
                if ((world.testBlockState(pos, (s) -> s.isAir()) || world.testBlockState(pos, (s) -> s == Blocks.WATER.getDefaultState())) && world.testBlockState(pos.up(), (s) -> s.isIn(BlockTags.LEAVES) || (s.isOf(BMBlocks.WILLOWING_BRANCHES) && s.get(WillowingBranchesBlock.STAGE) < 2))) {
                    boolean water = world.testBlockState(pos, (s) -> s == Blocks.WATER.getDefaultState());
                    if (water || world.testBlockState(pos, (s) -> s.isAir())) {
                        world.setBlockState(pos, BMBlocks.WILLOWING_BRANCHES.getDefaultState().with(WillowingBranchesBlock.STAGE, j).with(Properties.WATERLOGGED, water), 19);
                        pos.move(Direction.DOWN);
                    } else
                        break;
                } else {
                    break;
                }
            }
        }
}
Also used : FoliagePlacer(net.minecraft.world.gen.foliage.FoliagePlacer) ModifiableTestableWorld(net.minecraft.world.ModifiableTestableWorld) Set(java.util.Set) BlockPos(net.minecraft.util.math.BlockPos) Random(java.util.Random) FoliagePlacerType(net.minecraft.world.gen.foliage.FoliagePlacerType) Blocks(net.minecraft.block.Blocks) Direction(net.minecraft.util.math.Direction) Properties(net.minecraft.state.property.Properties) Products(com.mojang.datafixers.Products) Codec(com.mojang.serialization.Codec) BlockBox(net.minecraft.util.math.BlockBox) TreeFeatureConfig(net.minecraft.world.gen.feature.TreeFeatureConfig) BMBlocks(party.lemons.biomemakeover.init.BMBlocks) RandomUtil(party.lemons.biomemakeover.util.RandomUtil) TreeFeature(net.minecraft.world.gen.feature.TreeFeature) BMWorldGen(party.lemons.biomemakeover.init.BMWorldGen) RecordCodecBuilder(com.mojang.serialization.codecs.RecordCodecBuilder) BlockTags(net.minecraft.tag.BlockTags) WillowingBranchesBlock(party.lemons.biomemakeover.block.WillowingBranchesBlock) UniformIntDistribution(net.minecraft.world.gen.UniformIntDistribution) BlockBox(net.minecraft.util.math.BlockBox) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

BlockBox (net.minecraft.util.math.BlockBox)7 BlockPos (net.minecraft.util.math.BlockPos)7 Color (kaptainwutax.seedcrackerX.render.Color)2 Cube (kaptainwutax.seedcrackerX.render.Cube)2 Cuboid (kaptainwutax.seedcrackerX.render.Cuboid)2 BlockRotation (net.minecraft.util.BlockRotation)2 ChunkPos (net.minecraft.util.math.ChunkPos)2 Direction (net.minecraft.util.math.Direction)2 Products (com.mojang.datafixers.Products)1 Codec (com.mojang.serialization.Codec)1 RecordCodecBuilder (com.mojang.serialization.codecs.RecordCodecBuilder)1 RegionStructure (com.seedfinding.mcfeature.structure.RegionStructure)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 Set (java.util.Set)1 FullFungusData (kaptainwutax.seedcrackerX.cracker.decorator.FullFungusData)1 WarpedFungus (kaptainwutax.seedcrackerX.cracker.decorator.WarpedFungus)1 EntityTrackerSection (me.jellysquid.mods.lithium.common.entity.tracker.EntityTrackerSection)1 Range6Int (me.jellysquid.mods.lithium.common.util.tuples.Range6Int)1 Block (net.minecraft.block.Block)1