Search in sources :

Example 1 with BlockArea

use of ivorius.ivtoolkit.blocks.BlockArea in project RecurrentComplex by Ivorforce.

the class CommandSelectCopy method execute.

@Override
public void execute(MockWorld world, ICommandSender commandSender, String[] args) throws CommandException {
    RCEntityInfo RCEntityInfo = RCCommands.getStructureEntityInfo(commandSender, null);
    SelectionOwner selectionOwner = RCCommands.getSelectionOwner(commandSender, null, true);
    RCCommands.assertSize(commandSender, selectionOwner);
    BlockArea area = selectionOwner.getSelection();
    IvWorldData worldData = IvWorldData.capture(world, area, true);
    RCEntityInfo.setWorldDataClipboard(worldData.createTagCompound());
    commandSender.sendMessage(ServerTranslations.format("commands.selectCopy.success", RCTextStyle.area(area)));
}
Also used : BlockArea(ivorius.ivtoolkit.blocks.BlockArea) SelectionOwner(ivorius.reccomplex.capability.SelectionOwner) IvWorldData(ivorius.ivtoolkit.tools.IvWorldData) RCEntityInfo(ivorius.reccomplex.capability.RCEntityInfo)

Example 2 with BlockArea

use of ivorius.ivtoolkit.blocks.BlockArea in project RecurrentComplex by Ivorforce.

the class CommandNaturalAll method execute.

@Override
public void execute(MockWorld world, ICommandSender commandSender, String[] args) throws CommandException {
    RCParameters parameters = RCParameters.of(args);
    SelectionOwner selectionOwner = RCCommands.getSelectionOwner(commandSender, null, true);
    RCCommands.assertSize(commandSender, selectionOwner);
    BlockArea area = selectionOwner.getSelection();
    double expandFloor = parameters.get("floor-expansion").doubleAt(0).optional().orElse(1.);
    int floorDistance = parameters.get("space-distance-to-floor").intAt(0).optional().orElse(0) + 1;
    int maxClosedSides = parameters.get("space-max-closed-sides").intAt(1).optional().orElse(3);
    CommandNaturalFloor.placeNaturalFloor(world, area, expandFloor);
    CommandNaturalSpace.placeNaturalAir(world, area, 3, 3);
}
Also used : RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) BlockArea(ivorius.ivtoolkit.blocks.BlockArea) SelectionOwner(ivorius.reccomplex.capability.SelectionOwner)

Example 3 with BlockArea

use of ivorius.ivtoolkit.blocks.BlockArea in project RecurrentComplex by Ivorforce.

the class TransformerNaturalAir method transform.

@Override
public void transform(InstanceData instanceData, Phase phase, StructureSpawnContext context, IvWorldData worldData, RunTransformer transformer) {
    super.transform(instanceData, phase, context, worldData, transformer);
    if (phase == Phase.AFTER) {
        WorldServer world = context.environment.world;
        IvBlockCollection blockCollection = worldData.blockCollection;
        int[] areaSize = new int[] { blockCollection.width, blockCollection.height, blockCollection.length };
        BlockPos lowerCoord = StructureBoundingBoxes.min(context.boundingBox);
        // Remove dying foliage
        HashSet<BlockPos> check = instanceData.cloud.keySet().stream().flatMap(pos -> new BlockArea(pos.subtract(new Vec3i(2, 2, 2)), pos.add(new Vec3i(2, 2, 2))).stream()).filter(pos -> !instanceData.cloud.containsKey(pos)).map(pos -> context.transform.apply(pos, areaSize).add(lowerCoord)).collect(Collectors.toCollection(HashSet::new));
        Set<BlockPos> remove = new HashSet<>();
        HashSet<BlockPos> start = new HashSet<>();
        // Do each one separately, since each block needs to be connected to floor separately
        check.forEach(checking -> {
            start.add(checking);
            if (visitRecursively(start, (changed, pos) -> {
                IBlockState state = world.getBlockState(pos);
                boolean isFoliage = RCBlockLogic.isFoliage(state, world, pos);
                if (!RCBlockLogic.canStay(state, world, pos))
                    context.setBlock(pos, Blocks.AIR.getDefaultState(), 2);
                else if (!isFoliage && !state.getBlock().isReplaceable(world, pos))
                    return false;
                else if (isFoliage && remove.size() < MAX_TREE_SIZE && remove.add(pos))
                    neighbors(pos).forEach(changed::add);
                return true;
            })) {
                remove.forEach(pos -> context.setBlock(pos, Blocks.AIR.getDefaultState(), 2));
            }
            start.clear();
            remove.clear();
        });
    }
}
Also used : IvBlockCollection(ivorius.ivtoolkit.blocks.IvBlockCollection) BlockExpression(ivorius.reccomplex.utils.expression.BlockExpression) Blocks(net.minecraft.init.Blocks) StructureSpawnContext(ivorius.reccomplex.world.gen.feature.structure.context.StructureSpawnContext) BlockAreas(ivorius.ivtoolkit.blocks.BlockAreas) TableDataSource(ivorius.reccomplex.gui.table.datasource.TableDataSource) TableDataSourceBTNaturalAir(ivorius.reccomplex.gui.editstructure.transformers.TableDataSourceBTNaturalAir) Environment(ivorius.reccomplex.world.gen.feature.structure.Environment) StructureBoundingBoxes(ivorius.ivtoolkit.world.chunk.gen.StructureBoundingBoxes) HashSet(java.util.HashSet) BlockArea(ivorius.ivtoolkit.blocks.BlockArea) Vec3i(net.minecraft.util.math.Vec3i) RecurrentComplex(ivorius.reccomplex.RecurrentComplex) PositionedBlockExpression(ivorius.reccomplex.utils.expression.PositionedBlockExpression) WorldServer(net.minecraft.world.WorldServer) JsonUtils(ivorius.reccomplex.json.JsonUtils) Nullable(javax.annotation.Nullable) IvWorldData(ivorius.ivtoolkit.tools.IvWorldData) ExpressionCache(ivorius.reccomplex.utils.algebra.ExpressionCache) StructureLoadContext(ivorius.reccomplex.world.gen.feature.structure.context.StructureLoadContext) StructurePrepareContext(ivorius.reccomplex.world.gen.feature.structure.context.StructurePrepareContext) NBTBase(net.minecraft.nbt.NBTBase) Set(java.util.Set) BlockPos(net.minecraft.util.math.BlockPos) RCBlocks(ivorius.reccomplex.block.RCBlocks) Collectors(java.util.stream.Collectors) MCRegistry(ivorius.ivtoolkit.tools.MCRegistry) TableNavigator(ivorius.reccomplex.gui.table.TableNavigator) IBlockState(net.minecraft.block.state.IBlockState) Stream(java.util.stream.Stream) RCBlockLogic(ivorius.reccomplex.utils.RCBlockLogic) Type(java.lang.reflect.Type) TableDelegate(ivorius.reccomplex.gui.table.TableDelegate) com.google.gson(com.google.gson) BlockArea(ivorius.ivtoolkit.blocks.BlockArea) Vec3i(net.minecraft.util.math.Vec3i) IBlockState(net.minecraft.block.state.IBlockState) WorldServer(net.minecraft.world.WorldServer) BlockPos(net.minecraft.util.math.BlockPos) IvBlockCollection(ivorius.ivtoolkit.blocks.IvBlockCollection) HashSet(java.util.HashSet)

Example 4 with BlockArea

use of ivorius.ivtoolkit.blocks.BlockArea in project RecurrentComplex by Ivorforce.

the class CommandSelectDuplicate method execute.

@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
    RCParameters parameters = RCParameters.of(args, "mirror");
    SelectionOwner selectionOwner = RCCommands.getSelectionOwner(commandSender, null, true);
    BlockArea area = selectionOwner.getSelection();
    BlockPos pos = parameters.pos("x", "y", "z", commandSender.getPosition(), false).require();
    AxisAlignedTransform2D transform = parameters.transform("rotation", "mirror").optional().orElse(AxisAlignedTransform2D.ORIGINAL);
    IvWorldData worldData = IvWorldData.capture(commandSender.getEntityWorld(), area, true);
    NBTTagCompound worldDataCompound = worldData.createTagCompound();
    GenericStructure structureInfo = GenericStructure.createDefaultStructure();
    structureInfo.worldDataCompound = worldDataCompound;
    OperationRegistry.queueOperation(new OperationGenerateStructure(structureInfo, null, transform, pos, true).prepare((WorldServer) commandSender.getEntityWorld()), commandSender);
}
Also used : RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) BlockArea(ivorius.ivtoolkit.blocks.BlockArea) OperationGenerateStructure(ivorius.reccomplex.world.gen.feature.structure.OperationGenerateStructure) SelectionOwner(ivorius.reccomplex.capability.SelectionOwner) AxisAlignedTransform2D(ivorius.ivtoolkit.math.AxisAlignedTransform2D) IvWorldData(ivorius.ivtoolkit.tools.IvWorldData) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) BlockPos(net.minecraft.util.math.BlockPos) WorldServer(net.minecraft.world.WorldServer) GenericStructure(ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure)

Example 5 with BlockArea

use of ivorius.ivtoolkit.blocks.BlockArea in project RecurrentComplex by Ivorforce.

the class CommandSelectFill method execute.

@Override
public void execute(MockWorld world, ICommandSender commandSender, String[] args) throws CommandException {
    RCParameters parameters = RCParameters.of(args);
    Block dstBlock = parameters.mc().block(commandSender).require();
    int[] dstMeta = parameters.rc().move(1).metadatas().optional().orElse(new int[1]);
    List<IBlockState> dst = IntStream.of(dstMeta).mapToObj(m -> BlockStates.fromMetadata(dstBlock, m)).collect(Collectors.toList());
    SelectionOwner selectionOwner = RCCommands.getSelectionOwner(commandSender, null, true);
    RCCommands.assertSize(commandSender, selectionOwner);
    String shape = parameters.get("shape").first().optional().orElse("cube");
    BlockArea area = selectionOwner.getSelection();
    BlockPos p1 = area.getPoint1();
    BlockPos p2 = area.getPoint2();
    switch(shape) {
        case "cube":
            for (BlockPos pos : area) {
                IBlockState state = dst.get(world.rand().nextInt(dst.size()));
                world.setBlockState(pos, state, 2);
            }
            break;
        case "sphere":
            {
                double[] spheroidOrigin = new double[] { (p1.getX() + p2.getX()) * 0.5, (p1.getY() + p2.getY()) * 0.5, (p1.getZ() + p2.getZ()) * 0.5 };
                int[] areaSize = area.areaSize();
                double[] spheroidSize = new double[] { areaSize[0] * 0.5, areaSize[1] * 0.5, areaSize[2] * 0.5 };
                for (BlockPos coord : area) {
                    double[] coordPoint = new double[] { coord.getX(), coord.getY(), coord.getZ() };
                    if (IvShapeHelper.isPointInSpheroid(coordPoint, spheroidOrigin, spheroidSize)) {
                        IBlockState state = dst.get(world.rand().nextInt(dst.size()));
                        world.setBlockState(coord, state, 2);
                    }
                }
                break;
            }
        default:
            throw new WrongUsageException(getUsage(commandSender));
    }
}
Also used : RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) SelectionOwner(ivorius.reccomplex.capability.SelectionOwner) IntStream(java.util.stream.IntStream) RCCommands(ivorius.reccomplex.commands.RCCommands) BlockStates(ivorius.ivtoolkit.blocks.BlockStates) ServerTranslations(ivorius.reccomplex.utils.ServerTranslations) BlockPos(net.minecraft.util.math.BlockPos) MockWorld(ivorius.ivtoolkit.world.MockWorld) CommandVirtual(ivorius.reccomplex.commands.CommandVirtual) RCConfig(ivorius.reccomplex.RCConfig) Collectors(java.util.stream.Collectors) RCExpect(ivorius.reccomplex.commands.parameters.RCExpect) BlockArea(ivorius.ivtoolkit.blocks.BlockArea) IBlockState(net.minecraft.block.state.IBlockState) CommandException(net.minecraft.command.CommandException) MinecraftServer(net.minecraft.server.MinecraftServer) List(java.util.List) Block(net.minecraft.block.Block) ICommandSender(net.minecraft.command.ICommandSender) WrongUsageException(net.minecraft.command.WrongUsageException) IvShapeHelper(ivorius.ivtoolkit.math.IvShapeHelper) RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) Nullable(javax.annotation.Nullable) BlockArea(ivorius.ivtoolkit.blocks.BlockArea) WrongUsageException(net.minecraft.command.WrongUsageException) IBlockState(net.minecraft.block.state.IBlockState) SelectionOwner(ivorius.reccomplex.capability.SelectionOwner) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos)

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