Search in sources :

Example 1 with Parameters

use of ivorius.mcopts.commands.parameters.Parameters in project RecurrentComplex by Ivorforce.

the class CommandSelectMove method execute.

@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
    Parameters parameters = Parameters.of(args, expect()::declare);
    SelectionOwner selectionOwner = RCCommands.getSelectionOwner(commandSender, null, true);
    RCCommands.assertSize(commandSender, selectionOwner);
    BlockPos move = parameters.get(RCP.pos("x", "y", "z", BlockPos.ORIGIN, false)).require();
    AxisAlignedTransform2D transform = parameters.get(IvP.transform("rotation", "mirror")).optional().orElse(AxisAlignedTransform2D.ORIGINAL);
    boolean noselect = parameters.has("noselect");
    boolean duplicate = parameters.has("duplicate");
    int times = parameters.get("times").to(NaP::asInt).optional().orElse(1);
    BlockArea area = selectionOwner.getSelection();
    IvWorldData worldData = IvWorldData.capture(commandSender.getEntityWorld(), area, true);
    NBTTagCompound worldDataCompound = worldData.createTagCompound();
    GenericStructure structure = GenericStructure.createDefaultStructure();
    structure.worldDataCompound = worldDataCompound;
    BlockPos pos = selectionOwner.getSelection().getLowerCorner();
    for (int i = 0; i < times; i++) {
        pos = pos.add(move);
        if (duplicate)
            OperationRegistry.queueOperation(new OperationGenerateStructure(structure, null, transform, pos, true).prepare((WorldServer) commandSender.getEntityWorld()), commandSender);
        else
            OperationRegistry.queueOperation(new OperationMulti(new OperationClearArea(area), new OperationGenerateStructure(structure, null, transform, pos, true).prepare((WorldServer) commandSender.getEntityWorld())), commandSender);
    }
    if (!noselect) {
        StructureGenerator<GenericStructure.InstanceData> generator = new StructureGenerator<>(structure).transform(transform).lowerCoord(pos);
        // noinspection OptionalGetWithoutIsPresent
        StructureBoundingBox boundingBox = generator.boundingBox().get();
        selectionOwner.setSelection(RCBlockAreas.from(boundingBox));
    }
}
Also used : OperationGenerateStructure(ivorius.reccomplex.operation.OperationGenerateStructure) Parameters(ivorius.mcopts.commands.parameters.Parameters) SelectionOwner(ivorius.reccomplex.capability.SelectionOwner) StructureBoundingBox(net.minecraft.world.gen.structure.StructureBoundingBox) AxisAlignedTransform2D(ivorius.ivtoolkit.math.AxisAlignedTransform2D) IvWorldData(ivorius.ivtoolkit.tools.IvWorldData) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) WorldServer(net.minecraft.world.WorldServer) OperationClearArea(ivorius.reccomplex.operation.OperationClearArea) BlockArea(ivorius.ivtoolkit.blocks.BlockArea) OperationMulti(ivorius.reccomplex.operation.OperationMulti) StructureGenerator(ivorius.reccomplex.world.gen.feature.StructureGenerator) BlockPos(net.minecraft.util.math.BlockPos) NaP(ivorius.mcopts.commands.parameters.NaP) GenericStructure(ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure)

Example 2 with Parameters

use of ivorius.mcopts.commands.parameters.Parameters in project RecurrentComplex by Ivorforce.

the class CommandSetProperty method execute.

@Override
public void execute(MockWorld world, ICommandSender sender, String[] args) throws CommandException {
    Parameters parameters = Parameters.of(args, expect()::declare);
    PositionedBlockExpression matcher = parameters.get("exp").orElse("").to(RCP::expression, new PositionedBlockExpression(RecurrentComplex.specialRegistry)).require();
    String propertyName = parameters.get(0).require();
    String propertyValue = parameters.get(1).require();
    RCP.Shape shape = parameters.get("shape").to(RCP::shape).optional().orElse(RCP.Shape.cube);
    Consumer<BlockPos> consumer = (BlockPos pos) -> {
        PositionedBlockExpression.Argument at = PositionedBlockExpression.Argument.at(world, pos);
        if (matcher.test(at))
            TransformerProperty.withProperty(at.state, propertyName, propertyValue).ifPresent(state -> world.setBlockState(pos, state, 3));
    };
    SelectionOwner selectionOwner = RCCommands.getSelectionOwner(sender, null, true);
    RCCommands.assertSize(sender, selectionOwner);
    CommandFill.runShape(shape, selectionOwner.getSelection(), consumer);
}
Also used : Parameters(ivorius.mcopts.commands.parameters.Parameters) PositionedBlockExpression(ivorius.reccomplex.utils.expression.PositionedBlockExpression) SelectionOwner(ivorius.reccomplex.capability.SelectionOwner) BlockPos(net.minecraft.util.math.BlockPos) RCP(ivorius.reccomplex.commands.parameters.RCP)

Example 3 with Parameters

use of ivorius.mcopts.commands.parameters.Parameters in project RecurrentComplex by Ivorforce.

the class CommandPaste method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    Parameters parameters = Parameters.of(args, expect()::declare);
    EntityPlayerMP entityPlayerMP = getCommandSenderAsPlayer(sender);
    RCEntityInfo entityInfo = RCCommands.getStructureEntityInfo(entityPlayerMP, null);
    NBTTagCompound worldData = entityInfo.getWorldDataClipboard();
    if (worldData == null)
        throw RecurrentComplex.translations.commandException("commands.strucPaste.noClipboard");
    WorldServer world = (WorldServer) sender.getEntityWorld();
    BlockPos pos = parameters.get(MCP.pos("x", "y", "z", sender.getPosition(), false)).require();
    AxisAlignedTransform2D transform = parameters.get(IvP.transform("rotation", "mirror")).optional().orElse(AxisAlignedTransform2D.ORIGINAL);
    String seed = parameters.get("seed").optional().orElse(null);
    boolean generate = parameters.has("generate");
    GenericStructure structure = GenericStructure.createDefaultStructure();
    structure.worldDataCompound = worldData;
    // TODO Generate with generation info?
    OperationRegistry.queueOperation(new OperationGenerateStructure(structure, null, transform, pos, !generate).withSeed(seed).prepare(world), sender);
    if (parameters.has("select")) {
        StructureGenerator<?> generator = new StructureGenerator<>(structure).transform(transform).lowerCoord(pos);
        // Can never not place so don't handle
        // noinspection OptionalGetWithoutIsPresent
        RCCommands.select(sender, RCBlockAreas.from(generator.boundingBox().get()));
    }
}
Also used : OperationGenerateStructure(ivorius.reccomplex.operation.OperationGenerateStructure) Parameters(ivorius.mcopts.commands.parameters.Parameters) AxisAlignedTransform2D(ivorius.ivtoolkit.math.AxisAlignedTransform2D) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) WorldServer(net.minecraft.world.WorldServer) RCEntityInfo(ivorius.reccomplex.capability.RCEntityInfo) StructureGenerator(ivorius.reccomplex.world.gen.feature.StructureGenerator) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) BlockPos(net.minecraft.util.math.BlockPos) GenericStructure(ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure)

Example 4 with Parameters

use of ivorius.mcopts.commands.parameters.Parameters in project RecurrentComplex by Ivorforce.

the class CommandImportSchematic method execute.

@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
    Function<Parameters, Parameters> c = expect()::declare;
    Parameters parameters = Parameters.of(args, c);
    if (args.length < 1)
        throw RecurrentComplex.translations.wrongUsageException("commands.rcimportschematic.usage");
    SchematicFile schematicFile = parseSchematic(parameters.get(0).require());
    BlockPos pos = parameters.get(MCP.pos("x", "y", "z", commandSender.getPosition(), false)).require();
    AxisAlignedTransform2D transform = parameters.get(IvP.transform("rotation", "mirror")).optional().orElse(AxisAlignedTransform2D.ORIGINAL);
    OperationRegistry.queueOperation(new OperationGenerateSchematic(schematicFile, transform, pos), commandSender);
}
Also used : SchematicFile(ivorius.reccomplex.world.gen.feature.structure.schematics.SchematicFile) Parameters(ivorius.mcopts.commands.parameters.Parameters) AxisAlignedTransform2D(ivorius.ivtoolkit.math.AxisAlignedTransform2D) OperationGenerateSchematic(ivorius.reccomplex.operation.OperationGenerateSchematic) BlockPos(net.minecraft.util.math.BlockPos)

Example 5 with Parameters

use of ivorius.mcopts.commands.parameters.Parameters in project RecurrentComplex by Ivorforce.

the class CommandExportStructure method execute.

@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
    Parameters parameters = Parameters.of(args, expect()::declare);
    EntityPlayerMP player = getCommandSenderAsPlayer(commandSender);
    ResourceDirectory directory = parameters.get("directory").to(RCP::resourceDirectory).optional().orElse(null);
    String structureID = parameters.get("id").optional().orElse(parameters.get(0).optional().orElse(null));
    GenericStructure from = parameters.get(0).to(RCP::structureFromBlueprint, commandSender).require();
    SelectionOwner selectionOwner = RCCommands.getSelectionOwner(commandSender, null, true);
    RCCommands.assertSize(commandSender, selectionOwner);
    from.worldDataCompound = IvWorldData.capture(commandSender.getEntityWorld(), selectionOwner.getSelection(), true).createTagCompound();
    PacketEditStructureHandler.openEditStructure(player, from, selectionOwner.getSelection().getLowerCorner(), structureID, directory);
}
Also used : Parameters(ivorius.mcopts.commands.parameters.Parameters) SelectionOwner(ivorius.reccomplex.capability.SelectionOwner) ResourceDirectory(ivorius.reccomplex.files.loading.ResourceDirectory) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) RCP(ivorius.reccomplex.commands.parameters.RCP) GenericStructure(ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure)

Aggregations

Parameters (ivorius.mcopts.commands.parameters.Parameters)18 RCP (ivorius.reccomplex.commands.parameters.RCP)9 BlockPos (net.minecraft.util.math.BlockPos)8 CommandExpecting (ivorius.mcopts.commands.CommandExpecting)7 Expect (ivorius.mcopts.commands.parameters.expect.Expect)7 RCConfig (ivorius.reccomplex.RCConfig)7 RecurrentComplex (ivorius.reccomplex.RecurrentComplex)7 GenericStructure (ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure)7 NaP (ivorius.mcopts.commands.parameters.NaP)6 ResourceDirectory (ivorius.reccomplex.files.loading.ResourceDirectory)6 CommandException (net.minecraft.command.CommandException)6 ICommandSender (net.minecraft.command.ICommandSender)6 MinecraftServer (net.minecraft.server.MinecraftServer)6 RCE (ivorius.reccomplex.commands.parameters.expect.RCE)5 Structure (ivorius.reccomplex.world.gen.feature.structure.Structure)5 MCE (ivorius.mcopts.commands.parameters.expect.MCE)4 RCCommands (ivorius.reccomplex.commands.RCCommands)4 WorldServer (net.minecraft.world.WorldServer)4 AxisAlignedTransform2D (ivorius.ivtoolkit.math.AxisAlignedTransform2D)3 SelectionOwner (ivorius.reccomplex.capability.SelectionOwner)3