use of ivorius.ivtoolkit.blocks.BlockSurfacePos 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());
});
}
use of ivorius.ivtoolkit.blocks.BlockSurfacePos in project RecurrentComplex by Ivorforce.
the class CommandNaturalFloor method placeNaturalFloor.
public static void placeNaturalFloor(MockWorld world, BlockArea area, double lowerExpansion) {
// Rounding and stuff
lowerExpansion += 0.01;
IBlockState floorBlock = RCBlocks.genericSolid.getDefaultState();
Block airBlock1 = RCBlocks.genericSpace;
BlockPos lowerPoint = area.getLowerCorner();
BlockPos higherPoint = area.getHigherCorner();
Set<BlockSurfacePos> stopped = new HashSet<>();
Set<BlockSurfacePos> stopping = new HashSet<>();
for (int y = lowerPoint.getY() + 1; y <= higherPoint.getY(); y++) {
for (BlockSurfacePos surfaceCoord : (Iterable<BlockSurfacePos>) BlockSurfaceArea.from(area).stream().filter((o) -> !stopped.contains(o))::iterator) {
IBlockState block = world.getBlockState(surfaceCoord.blockPos(y));
if ((block.getMaterial() != Material.AIR && block.getBlock() != airBlock1)) {
stopping.add(surfaceCoord);
if (block != floorBlock) {
setBlockIfAirInArea(world, surfaceCoord.blockPos(y - 1), floorBlock, area);
fillSurface(world, area, lowerExpansion, floorBlock, surfaceCoord.blockPos(y), stopping);
}
}
}
stopped.addAll(stopping);
stopping.clear();
}
}
Aggregations