Search in sources :

Example 11 with BlockArea

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;
}
Also used : BlockArea(ivorius.ivtoolkit.blocks.BlockArea) BlockPos(net.minecraft.util.math.BlockPos) Nullable(javax.annotation.Nullable)

Example 12 with BlockArea

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());
    });
}
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)12 SelectionOwner (ivorius.reccomplex.capability.SelectionOwner)8 BlockPos (net.minecraft.util.math.BlockPos)8 RCParameters (ivorius.reccomplex.commands.parameters.RCParameters)7 IvWorldData (ivorius.ivtoolkit.tools.IvWorldData)5 Nullable (javax.annotation.Nullable)3 IBlockState (net.minecraft.block.state.IBlockState)3 AxisAlignedTransform2D (ivorius.ivtoolkit.math.AxisAlignedTransform2D)2 OperationGenerateStructure (ivorius.reccomplex.world.gen.feature.structure.OperationGenerateStructure)2 GenericStructure (ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure)2 Collectors (java.util.stream.Collectors)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 WorldServer (net.minecraft.world.WorldServer)2 com.google.gson (com.google.gson)1 BlockAreas (ivorius.ivtoolkit.blocks.BlockAreas)1 BlockStates (ivorius.ivtoolkit.blocks.BlockStates)1 BlockSurfacePos (ivorius.ivtoolkit.blocks.BlockSurfacePos)1 IvBlockCollection (ivorius.ivtoolkit.blocks.IvBlockCollection)1 IvShapeHelper (ivorius.ivtoolkit.math.IvShapeHelper)1 MCRegistry (ivorius.ivtoolkit.tools.MCRegistry)1