use of ivorius.ivtoolkit.blocks.BlockArea in project RecurrentComplex by Ivorforce.
the class SelectionOwner method getSelection.
@Nullable
default default BlockArea getSelection() {
BlockPos l = getSelectedPoint1();
BlockPos r = getSelectedPoint2();
return l != null && r != null ? new BlockArea(l, r) : null;
}
use of ivorius.ivtoolkit.blocks.BlockArea in project RecurrentComplex by Ivorforce.
the class CommandNaturalSpace method placeNaturalAir.
public static void placeNaturalAir(MockWorld world, BlockArea area, int floorDistance, int maxClosedSides) {
BlockGenericSpace spaceBlock = RCBlocks.genericSpace;
BlockPos lowerPoint = area.getLowerCorner();
BlockPos higherPoint = area.getHigherCorner();
Set<BlockPos> set = new HashSet<>();
for (BlockSurfacePos surfaceCoord : BlockSurfaceArea.from(area)) {
int safePoint = lowerPoint.getY();
for (int y = higherPoint.getY(); y >= lowerPoint.getY(); y--) {
IBlockState blockState = world.getBlockState(surfaceCoord.blockPos(y));
if ((blockState.getMaterial() != Material.AIR && blockState.getBlock() != spaceBlock) || sidesClosed(world, surfaceCoord.blockPos(y), area) >= maxClosedSides) {
boolean isFloor = blockState == RCBlocks.genericSolid.getDefaultState();
safePoint = y + (isFloor ? 1 : floorDistance);
break;
}
}
for (int y = safePoint; y <= higherPoint.getY(); y++) set.add(surfaceCoord.blockPos(y));
if (safePoint > lowerPoint.getY()) {
for (int y = lowerPoint.getY(); y <= higherPoint.getY(); y++) {
IBlockState blockState = world.getBlockState(surfaceCoord.blockPos(y));
if ((blockState.getMaterial() != Material.AIR && blockState.getBlock() != spaceBlock) || sidesClosed(world, surfaceCoord.blockPos(y), area) >= maxClosedSides) {
safePoint = y - 1;
break;
}
}
}
for (int y = lowerPoint.getY(); y <= safePoint; y++) set.add(surfaceCoord.blockPos(y));
}
set.forEach(pos -> {
BlockPos down = pos.down();
BlockPos down2 = pos.down(2);
world.setBlockState(pos, pos.getY() > lowerPoint.getY() && !set.contains(down) && world.getBlockState(down).getBlock().isReplaceable(world, down) && world.getBlockState(down2).getBlock().isReplaceable(world, down2) && new BlockArea(pos.subtract(new Vec3i(2, 0, 2)), pos.add(new Vec3i(2, 0, 2))).stream().allMatch(set::contains) ? spaceBlock.getDefaultState().withProperty(BlockGenericSpace.TYPE, 1) : spaceBlock.getDefaultState());
});
}
Aggregations