Search in sources :

Example 6 with BlockSurfacePos

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());
    });
}
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)

Example 7 with BlockSurfacePos

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

Aggregations

BlockSurfacePos (ivorius.ivtoolkit.blocks.BlockSurfacePos)7 BlockPos (net.minecraft.util.math.BlockPos)3 RCParameters (ivorius.reccomplex.commands.parameters.RCParameters)2 HashSet (java.util.HashSet)2 IBlockState (net.minecraft.block.state.IBlockState)2 WorldServer (net.minecraft.world.WorldServer)2 BlockArea (ivorius.ivtoolkit.blocks.BlockArea)1 AxisAlignedTransform2D (ivorius.ivtoolkit.math.AxisAlignedTransform2D)1 BlockGenericSpace (ivorius.reccomplex.block.BlockGenericSpace)1 SelectionOwner (ivorius.reccomplex.capability.SelectionOwner)1 OperationGenerateStructure (ivorius.reccomplex.world.gen.feature.structure.OperationGenerateStructure)1 Placer (ivorius.reccomplex.world.gen.feature.structure.Placer)1 GenericStructure (ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure)1 GenerationType (ivorius.reccomplex.world.gen.feature.structure.generic.generation.GenerationType)1 StaticGeneration (ivorius.reccomplex.world.gen.feature.structure.generic.generation.StaticGeneration)1 ParametersAreNonnullByDefault (javax.annotation.ParametersAreNonnullByDefault)1 Block (net.minecraft.block.Block)1 Vec3i (net.minecraft.util.math.Vec3i)1 StructureBoundingBox (net.minecraft.world.gen.structure.StructureBoundingBox)1