Search in sources :

Example 1 with BoundingBox

use of net.minecraft.world.level.levelgen.structure.BoundingBox in project Tropicraft by Tropicraft.

the class HomeTreeBranchPiece method placeBlockLine.

private void placeBlockLine(final WorldGenLevel world, BlockPos from, BlockPos to, BlockState state, BoundingBox chunkBounds) {
    BoundingBox lineBounds = BoundingBox.fromCorners(from, to);
    if (!chunkBounds.intersects(lineBounds)) {
        return;
    }
    BlockPos delta = to.subtract(from);
    Direction.Axis primaryAxis = getLongestAxis(delta);
    int maxLength = Math.abs(getCoordinateAlong(delta, primaryAxis));
    if (maxLength == 0) {
        return;
    }
    double stepX = (double) getCoordinateAlong(delta, Direction.Axis.X) / maxLength;
    double stepY = (double) getCoordinateAlong(delta, Direction.Axis.Y) / maxLength;
    double stepZ = (double) getCoordinateAlong(delta, Direction.Axis.Z) / maxLength;
    for (int length = 0; length <= maxLength; length++) {
        BlockPos pos = new BlockPos(from.getX() + length * stepX + 0.5, from.getY() + length * stepY + 0.5, from.getZ() + length * stepZ + 0.5);
        if (chunkBounds.isInside(pos)) {
            world.setBlock(pos, state, Block.UPDATE_ALL);
        }
    }
}
Also used : BoundingBox(net.minecraft.world.level.levelgen.structure.BoundingBox) BlockPos(net.minecraft.core.BlockPos) Direction(net.minecraft.core.Direction)

Example 2 with BoundingBox

use of net.minecraft.world.level.levelgen.structure.BoundingBox in project Tropicraft by Tropicraft.

the class HomeTreeBranchPiece method genLeafCircle.

public void genLeafCircle(final WorldGenLevel world, final int x, final int y, final int z, int outerRadius, int innerRadius, BlockState state, BoundingBox chunkBounds) {
    int outerRadiusSquared = outerRadius * outerRadius;
    int innerRadiusSquared = innerRadius * innerRadius;
    BlockPos origin = new BlockPos(x, y, z);
    BoundingBox outerBounds = BoundingBox.fromCorners(origin.offset(-outerRadius, 0, -outerRadius), origin.offset(outerRadius, 0, outerRadius));
    BoundingBox bounds = intersection(chunkBounds, outerBounds);
    if (bounds == null) {
        // this leaf circle does not intersect with our given chunk bounds
        return;
    }
    for (BlockPos pos : BlockPos.betweenClosed(bounds.minX(), bounds.minY(), bounds.minZ(), bounds.maxX(), bounds.maxY(), bounds.maxZ())) {
        double distanceSquared = pos.distSqr(origin);
        if (distanceSquared <= outerRadiusSquared && distanceSquared >= innerRadiusSquared) {
            if (world.isEmptyBlock(pos) || world.getBlockState(pos).getBlock() == state.getBlock()) {
                world.setBlock(pos, state, Block.UPDATE_ALL);
            }
        }
    }
}
Also used : BoundingBox(net.minecraft.world.level.levelgen.structure.BoundingBox) BlockPos(net.minecraft.core.BlockPos)

Aggregations

BlockPos (net.minecraft.core.BlockPos)2 BoundingBox (net.minecraft.world.level.levelgen.structure.BoundingBox)2 Direction (net.minecraft.core.Direction)1