Search in sources :

Example 1 with BlockGenericSpace

use of ivorius.reccomplex.block.BlockGenericSpace 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());
    });
}
Also used : BlockArea(ivorius.ivtoolkit.blocks.BlockArea) Vec3i(net.minecraft.util.math.Vec3i) IBlockState(net.minecraft.block.state.IBlockState) BlockGenericSpace(ivorius.reccomplex.block.BlockGenericSpace) BlockSurfacePos(ivorius.ivtoolkit.blocks.BlockSurfacePos) BlockPos(net.minecraft.util.math.BlockPos) HashSet(java.util.HashSet)

Aggregations

BlockArea (ivorius.ivtoolkit.blocks.BlockArea)1 BlockSurfacePos (ivorius.ivtoolkit.blocks.BlockSurfacePos)1 BlockGenericSpace (ivorius.reccomplex.block.BlockGenericSpace)1 HashSet (java.util.HashSet)1 IBlockState (net.minecraft.block.state.IBlockState)1 BlockPos (net.minecraft.util.math.BlockPos)1 Vec3i (net.minecraft.util.math.Vec3i)1