Search in sources :

Example 1 with NaP

use of ivorius.mcopts.commands.parameters.NaP 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 NaP

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

the class CommandWrite method execute.

@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
    Parameters parameters = Parameters.of(args, expect()::declare);
    String adapterID = parameters.get(0).require();
    if (!RecurrentComplex.saver.has(adapterID))
        throw RecurrentComplex.translations.commandException("commands.rcsave.noregistry");
    ResourceDirectory directory = parameters.get("directory").to(RCP::resourceDirectory).optional().orElse(ResourceDirectory.ACTIVE);
    Optional<FileSaverAdapter<?>> adapterOptional = Optional.ofNullable(RecurrentComplex.saver.get(adapterID));
    Set<String> ids = adapterOptional.map(a -> a.getRegistry().ids()).orElse(Collections.emptySet());
    ResourceExpression resourceExpression = ExpressionCache.of(new ResourceExpression(id -> adapterOptional.map(a -> a.getRegistry().has(id)).orElse(false)), parameters.get(1).rest(NaP::join).require());
    int saved = 0, failed = 0;
    for (String id : ids) {
        if (!resourceExpression.test(new RawResourceLocation(adapterOptional.map(a -> a.getRegistry().status(id).getDomain()).orElseThrow(IllegalStateException::new), id)))
            continue;
        boolean success = RecurrentComplex.saver.trySave(directory.toPath(), adapterID, id);
        if (success)
            saved++;
        else
            failed++;
    }
    commandSender.sendMessage(RecurrentComplex.translations.format("commands.rcsaveall.result", saved, RCTextStyle.path(directory), failed));
    RCCommands.tryReload(RecurrentComplex.loader, LeveledRegistry.Level.CUSTOM);
    RCCommands.tryReload(RecurrentComplex.loader, LeveledRegistry.Level.SERVER);
}
Also used : ExpressionCache(ivorius.reccomplex.utils.algebra.ExpressionCache) LeveledRegistry(ivorius.reccomplex.files.loading.LeveledRegistry) RCCommands(ivorius.reccomplex.commands.RCCommands) Set(java.util.Set) FileSaverAdapter(ivorius.reccomplex.files.saving.FileSaverAdapter) RCTextStyle(ivorius.reccomplex.commands.RCTextStyle) RCConfig(ivorius.reccomplex.RCConfig) CommandExpecting(ivorius.mcopts.commands.CommandExpecting) RawResourceLocation(ivorius.reccomplex.utils.RawResourceLocation) RCE(ivorius.reccomplex.commands.parameters.expect.RCE) ResourceExpression(ivorius.reccomplex.utils.expression.ResourceExpression) NaP(ivorius.mcopts.commands.parameters.NaP) RCP(ivorius.reccomplex.commands.parameters.RCP) CommandException(net.minecraft.command.CommandException) MinecraftServer(net.minecraft.server.MinecraftServer) Expect(ivorius.mcopts.commands.parameters.expect.Expect) ICommandSender(net.minecraft.command.ICommandSender) ResourceDirectory(ivorius.reccomplex.files.loading.ResourceDirectory) Optional(java.util.Optional) RecurrentComplex(ivorius.reccomplex.RecurrentComplex) Collections(java.util.Collections) Parameters(ivorius.mcopts.commands.parameters.Parameters) Parameters(ivorius.mcopts.commands.parameters.Parameters) RawResourceLocation(ivorius.reccomplex.utils.RawResourceLocation) ResourceDirectory(ivorius.reccomplex.files.loading.ResourceDirectory) NaP(ivorius.mcopts.commands.parameters.NaP) RCP(ivorius.reccomplex.commands.parameters.RCP) FileSaverAdapter(ivorius.reccomplex.files.saving.FileSaverAdapter) ResourceExpression(ivorius.reccomplex.utils.expression.ResourceExpression)

Example 3 with NaP

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

the class CommandFill method execute.

@Override
public void execute(MockWorld world, ICommandSender sender, String[] args) throws CommandException {
    Parameters parameters = Parameters.of(args, expect()::declare);
    Block dstBlock = parameters.get(0).to(MCP::block, sender).require();
    int[] dstMeta = parameters.get("metadata").to(RCP::metadatas).optional().orElse(new int[1]);
    List<IBlockState> dst = IntStream.of(dstMeta).mapToObj(m -> BlockStates.fromMetadata(dstBlock, m)).collect(Collectors.toList());
    RCP.Shape shape = parameters.get("shape").to(RCP::shape).optional().orElse(RCP.Shape.cube);
    PositionedBlockExpression matcher = parameters.get(1).rest(NaP::join).orElse("").to(RCP::expression, new PositionedBlockExpression(RecurrentComplex.specialRegistry)).require();
    SelectionOwner selectionOwner = RCCommands.getSelectionOwner(sender, null, true);
    RCCommands.assertSize(sender, selectionOwner);
    if (parameters.has("flood")) {
        List<EnumFacing> directions = parameters.get("flood").orElse("").to(RCP::directions).require();
        List<BlockPos> dirty = new ArrayList<>();
        Set<BlockPos> visited = Sets.newHashSet(dirty);
        runShape(shape, selectionOwner.getSelection(), dirty::add);
        while (!dirty.isEmpty()) {
            BlockPos pos = dirty.remove(dirty.size() - 1);
            for (EnumFacing facing : directions) {
                BlockPos offset = pos.offset(facing);
                if (matcher.evaluate(() -> PositionedBlockExpression.Argument.at(world, offset)) && visited.add(offset))
                    dirty.add(offset);
            }
            if (visited.size() > MAX_FLOOD)
                throw new CommandException("Area too big to flood!");
        }
        visited.forEach(p -> setFrom(world, dst, p));
    } else {
        // TODO Can't freeze because the lighting update won't get sent
        // HeightMapFreezer freezer = HeightMapFreezer.freeze(BlockAreas.toBoundingBox(selectionOwner.getSelection()), sender.getEntityWorld());
        runShape(shape, selectionOwner.getSelection(), pos -> {
            if (matcher.evaluate(() -> PositionedBlockExpression.Argument.at(world, pos))) {
                setFrom(world, dst, pos);
            // freezer.markBlock(pos, state);
            }
        });
    // freezer.melt();
    }
}
Also used : SelectionOwner(ivorius.reccomplex.capability.SelectionOwner) IntStream(java.util.stream.IntStream) MCE(ivorius.mcopts.commands.parameters.expect.MCE) RCCommands(ivorius.reccomplex.commands.RCCommands) MockWorld(ivorius.ivtoolkit.world.MockWorld) RCConfig(ivorius.reccomplex.RCConfig) ArrayList(java.util.ArrayList) BlockArea(ivorius.ivtoolkit.blocks.BlockArea) NaP(ivorius.mcopts.commands.parameters.NaP) CommandException(net.minecraft.command.CommandException) Block(net.minecraft.block.Block) RecurrentComplex(ivorius.reccomplex.RecurrentComplex) IvShapeHelper(ivorius.ivtoolkit.math.IvShapeHelper) PositionedBlockExpression(ivorius.reccomplex.utils.expression.PositionedBlockExpression) EnumFacing(net.minecraft.util.EnumFacing) Set(java.util.Set) BlockStates(ivorius.ivtoolkit.blocks.BlockStates) BlockPos(net.minecraft.util.math.BlockPos) CommandVirtual(ivorius.reccomplex.commands.CommandVirtual) CommandExpecting(ivorius.mcopts.commands.CommandExpecting) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) RCE(ivorius.reccomplex.commands.parameters.expect.RCE) MCP(ivorius.mcopts.commands.parameters.MCP) Consumer(java.util.function.Consumer) IBlockState(net.minecraft.block.state.IBlockState) RCP(ivorius.reccomplex.commands.parameters.RCP) List(java.util.List) Expect(ivorius.mcopts.commands.parameters.expect.Expect) ICommandSender(net.minecraft.command.ICommandSender) Parameters(ivorius.mcopts.commands.parameters.Parameters) Parameters(ivorius.mcopts.commands.parameters.Parameters) IBlockState(net.minecraft.block.state.IBlockState) SelectionOwner(ivorius.reccomplex.capability.SelectionOwner) EnumFacing(net.minecraft.util.EnumFacing) ArrayList(java.util.ArrayList) CommandException(net.minecraft.command.CommandException) PositionedBlockExpression(ivorius.reccomplex.utils.expression.PositionedBlockExpression) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) RCP(ivorius.reccomplex.commands.parameters.RCP)

Example 4 with NaP

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

the class CommandDelete method execute.

@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
    Parameters parameters = Parameters.of(args, expect()::declare);
    String adapterID = parameters.get(0).require();
    if (!RecurrentComplex.saver.has(adapterID))
        throw RecurrentComplex.translations.commandException("commands.rcsave.noregistry");
    ResourceDirectory directory = parameters.get("directory").to(RCP::resourceDirectory).require();
    Optional<FileSaverAdapter<?>> adapterOptional = Optional.ofNullable(RecurrentComplex.saver.get(adapterID));
    Collection<String> ids = Lists.newArrayList(adapterOptional.map(a -> a.getRegistry().ids()).orElse(Collections.emptySet()));
    ResourceExpression resourceExpression = ExpressionCache.of(new ResourceExpression(id -> adapterOptional.map(a -> a.getRegistry().has(id)).orElse(false)), parameters.get(1).rest(NaP::join).require());
    for (String id : ids) {
        if (!resourceExpression.test(new RawResourceLocation(adapterOptional.map(a -> a.getRegistry().status(id).getDomain()).orElseThrow(IllegalStateException::new), id)))
            continue;
        RCCommands.informDeleteResult(RecurrentComplex.saver.tryDeleteWithID(directory.toPath(), adapterID, id), commandSender, adapterID, id, directory);
        // Could also predict changes and just reload those for the file but eh.
        RCCommands.tryReload(RecurrentComplex.loader, LeveledRegistry.Level.CUSTOM);
        RCCommands.tryReload(RecurrentComplex.loader, LeveledRegistry.Level.SERVER);
    }
}
Also used : ExpressionCache(ivorius.reccomplex.utils.algebra.ExpressionCache) LeveledRegistry(ivorius.reccomplex.files.loading.LeveledRegistry) RCCommands(ivorius.reccomplex.commands.RCCommands) Collection(java.util.Collection) FileSaverAdapter(ivorius.reccomplex.files.saving.FileSaverAdapter) RCConfig(ivorius.reccomplex.RCConfig) CommandExpecting(ivorius.mcopts.commands.CommandExpecting) RawResourceLocation(ivorius.reccomplex.utils.RawResourceLocation) RCE(ivorius.reccomplex.commands.parameters.expect.RCE) ResourceExpression(ivorius.reccomplex.utils.expression.ResourceExpression) NaP(ivorius.mcopts.commands.parameters.NaP) RCP(ivorius.reccomplex.commands.parameters.RCP) CommandException(net.minecraft.command.CommandException) MinecraftServer(net.minecraft.server.MinecraftServer) Lists(com.google.common.collect.Lists) Expect(ivorius.mcopts.commands.parameters.expect.Expect) ICommandSender(net.minecraft.command.ICommandSender) ResourceDirectory(ivorius.reccomplex.files.loading.ResourceDirectory) Optional(java.util.Optional) RecurrentComplex(ivorius.reccomplex.RecurrentComplex) Collections(java.util.Collections) Parameters(ivorius.mcopts.commands.parameters.Parameters) Parameters(ivorius.mcopts.commands.parameters.Parameters) ResourceDirectory(ivorius.reccomplex.files.loading.ResourceDirectory) NaP(ivorius.mcopts.commands.parameters.NaP) FileSaverAdapter(ivorius.reccomplex.files.saving.FileSaverAdapter) ResourceExpression(ivorius.reccomplex.utils.expression.ResourceExpression) RawResourceLocation(ivorius.reccomplex.utils.RawResourceLocation)

Example 5 with NaP

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

the class CommandMapStructure method execute.

@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
    Parameters parameters = Parameters.of(args, expect()::declare);
    ResourceExpression expression = parameters.get(0).to(RCP::expression, new ResourceExpression(StructureRegistry.INSTANCE::has)).require();
    CommandVirtual virtual = parameters.get(1).to(RCP::virtualCommand, server).require();
    String[] virtualArgs = parameters.get(2).to(NaP::varargs).require();
    ResourceDirectory directory = parameters.has("nosave") ? null : parameters.get("directory").to(RCP::resourceDirectory).optional().orElse(ResourceDirectory.ACTIVE);
    List<String> relevant = StructureRegistry.INSTANCE.ids().stream().filter(id -> expression.test(new RawResourceLocation(StructureRegistry.INSTANCE.status(id).getDomain(), id))).collect(Collectors.toList());
    boolean inform = relevant.size() == 1;
    int saved = 0, failed = 0, skipped = 0;
    for (String id : relevant) {
        switch(map(id, directory, commandSender, virtual, virtualArgs, inform)) {
            case SKIPPED:
                skipped++;
                break;
            case SUCCESS:
                saved++;
                break;
            default:
                failed++;
                break;
        }
    }
    if (!inform)
        commandSender.sendMessage(RecurrentComplex.translations.format("commands.rcmapall.result", saved, RCTextStyle.path(directory), failed, skipped));
    RCCommands.tryReload(RecurrentComplex.loader, LeveledRegistry.Level.CUSTOM);
    RCCommands.tryReload(RecurrentComplex.loader, LeveledRegistry.Level.SERVER);
}
Also used : GenericStructure(ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure) MCE(ivorius.mcopts.commands.parameters.expect.MCE) DelegatingSender(ivorius.mcopts.commands.DelegatingSender) LeveledRegistry(ivorius.reccomplex.files.loading.LeveledRegistry) RCCommands(ivorius.reccomplex.commands.RCCommands) Structure(ivorius.reccomplex.world.gen.feature.structure.Structure) StructureRegistry(ivorius.reccomplex.world.gen.feature.structure.StructureRegistry) MockWorld(ivorius.ivtoolkit.world.MockWorld) RCConfig(ivorius.reccomplex.RCConfig) ResourceExpression(ivorius.reccomplex.utils.expression.ResourceExpression) NaP(ivorius.mcopts.commands.parameters.NaP) CommandException(net.minecraft.command.CommandException) MinecraftServer(net.minecraft.server.MinecraftServer) ResourceDirectory(ivorius.reccomplex.files.loading.ResourceDirectory) RecurrentComplex(ivorius.reccomplex.RecurrentComplex) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) IvWorldData(ivorius.ivtoolkit.tools.IvWorldData) PacketSaveStructureHandler(ivorius.reccomplex.network.PacketSaveStructureHandler) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) CommandVirtual(ivorius.reccomplex.commands.CommandVirtual) RCTextStyle(ivorius.reccomplex.commands.RCTextStyle) CommandExpecting(ivorius.mcopts.commands.CommandExpecting) RawResourceLocation(ivorius.reccomplex.utils.RawResourceLocation) Collectors(java.util.stream.Collectors) Capability(net.minecraftforge.common.capabilities.Capability) RCE(ivorius.reccomplex.commands.parameters.expect.RCE) RCP(ivorius.reccomplex.commands.parameters.RCP) List(java.util.List) Expect(ivorius.mcopts.commands.parameters.expect.Expect) ICommandSender(net.minecraft.command.ICommandSender) Parameter(ivorius.mcopts.commands.parameters.Parameter) Parameters(ivorius.mcopts.commands.parameters.Parameters) CapabilitySelection(ivorius.reccomplex.capability.CapabilitySelection) CommandVirtual(ivorius.reccomplex.commands.CommandVirtual) Parameters(ivorius.mcopts.commands.parameters.Parameters) ResourceDirectory(ivorius.reccomplex.files.loading.ResourceDirectory) ResourceExpression(ivorius.reccomplex.utils.expression.ResourceExpression) RawResourceLocation(ivorius.reccomplex.utils.RawResourceLocation)

Aggregations

NaP (ivorius.mcopts.commands.parameters.NaP)6 Parameters (ivorius.mcopts.commands.parameters.Parameters)6 CommandExpecting (ivorius.mcopts.commands.CommandExpecting)4 Expect (ivorius.mcopts.commands.parameters.expect.Expect)4 RCConfig (ivorius.reccomplex.RCConfig)4 RecurrentComplex (ivorius.reccomplex.RecurrentComplex)4 RCCommands (ivorius.reccomplex.commands.RCCommands)4 RCP (ivorius.reccomplex.commands.parameters.RCP)4 RCE (ivorius.reccomplex.commands.parameters.expect.RCE)4 CommandException (net.minecraft.command.CommandException)4 ICommandSender (net.minecraft.command.ICommandSender)4 LeveledRegistry (ivorius.reccomplex.files.loading.LeveledRegistry)3 ResourceDirectory (ivorius.reccomplex.files.loading.ResourceDirectory)3 RawResourceLocation (ivorius.reccomplex.utils.RawResourceLocation)3 ResourceExpression (ivorius.reccomplex.utils.expression.ResourceExpression)3 MinecraftServer (net.minecraft.server.MinecraftServer)3 BlockPos (net.minecraft.util.math.BlockPos)3 BlockArea (ivorius.ivtoolkit.blocks.BlockArea)2 IvWorldData (ivorius.ivtoolkit.tools.IvWorldData)2 MockWorld (ivorius.ivtoolkit.world.MockWorld)2