Search in sources :

Example 1 with MCP

use of ivorius.mcopts.commands.parameters.MCP 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 2 with MCP

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

the class CommandSearchStructure method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    Parameters parameters = Parameters.of(args, expect()::declare);
    List<ToDoubleFunction<String>> ranks = new ArrayList<>();
    consider(ranks, parameters.get(0), Parameter::varargsList, (s, t) -> StructureSearch.searchRank(t, StructureSearch.keywords(StructureRegistry.INSTANCE.id(s), s)));
    consider(ranks, parameters.get("containing"), e -> RCP.expression(e, new BlockExpression(RecurrentComplex.specialRegistry)), StructureSearch::containedBlocks);
    consider(ranks, parameters.get("biome"), MCP::biome, StructureSearch::biome);
    consider(ranks, parameters.get("dimension"), MCP.dimension(server, sender), StructureSearch::dimension);
    consider(ranks, parameters.get("maze"), p -> p, StructureSearch::maze);
    consider(ranks, parameters.get("list"), p -> p, StructureSearch::list);
    consider(ranks, parameters.get("author"), p -> p, StructureSearch::author);
    boolean all = parameters.has("all");
    if (ranks.stream().noneMatch(Objects::nonNull))
        throw new WrongUsageException(getUsage(sender));
    postResultMessage("Results: ", sender, RCTextStyle::structure, search(all ? StructureRegistry.INSTANCE.ids() : StructureRegistry.INSTANCE.activeIDs(), name -> ranks.stream().filter(Objects::nonNull).mapToDouble(f -> f.applyAsDouble(name)).reduce(1, (a, b) -> a * b)));
}
Also used : BlockExpression(ivorius.reccomplex.utils.expression.BlockExpression) java.util(java.util) MCE(ivorius.mcopts.commands.parameters.expect.MCE) Structure(ivorius.reccomplex.world.gen.feature.structure.Structure) StructureRegistry(ivorius.reccomplex.world.gen.feature.structure.StructureRegistry) TextComponentBase(net.minecraft.util.text.TextComponentBase) RCConfig(ivorius.reccomplex.RCConfig) Function(java.util.function.Function) ServerTranslations(ivorius.mcopts.translation.ServerTranslations) ITextComponent(net.minecraft.util.text.ITextComponent) CommandException(net.minecraft.command.CommandException) MinecraftServer(net.minecraft.server.MinecraftServer) RecurrentComplex(ivorius.reccomplex.RecurrentComplex) Nonnull(javax.annotation.Nonnull) RCTextStyle(ivorius.reccomplex.commands.RCTextStyle) CommandExpecting(ivorius.mcopts.commands.CommandExpecting) Collectors(java.util.stream.Collectors) MCP(ivorius.mcopts.commands.parameters.MCP) TextComponentString(net.minecraft.util.text.TextComponentString) ToDoubleBiFunction(java.util.function.ToDoubleBiFunction) RCP(ivorius.reccomplex.commands.parameters.RCP) Expect(ivorius.mcopts.commands.parameters.expect.Expect) ICommandSender(net.minecraft.command.ICommandSender) WrongUsageException(net.minecraft.command.WrongUsageException) ToDoubleFunction(java.util.function.ToDoubleFunction) Doubles(com.google.common.primitives.Doubles) Parameter(ivorius.mcopts.commands.parameters.Parameter) Parameters(ivorius.mcopts.commands.parameters.Parameters) Parameters(ivorius.mcopts.commands.parameters.Parameters) BlockExpression(ivorius.reccomplex.utils.expression.BlockExpression) WrongUsageException(net.minecraft.command.WrongUsageException) RCTextStyle(ivorius.reccomplex.commands.RCTextStyle) Parameter(ivorius.mcopts.commands.parameters.Parameter) MCP(ivorius.mcopts.commands.parameters.MCP) ToDoubleFunction(java.util.function.ToDoubleFunction)

Aggregations

CommandExpecting (ivorius.mcopts.commands.CommandExpecting)2 MCP (ivorius.mcopts.commands.parameters.MCP)2 Parameters (ivorius.mcopts.commands.parameters.Parameters)2 Expect (ivorius.mcopts.commands.parameters.expect.Expect)2 MCE (ivorius.mcopts.commands.parameters.expect.MCE)2 RCConfig (ivorius.reccomplex.RCConfig)2 RecurrentComplex (ivorius.reccomplex.RecurrentComplex)2 RCP (ivorius.reccomplex.commands.parameters.RCP)2 Collectors (java.util.stream.Collectors)2 CommandException (net.minecraft.command.CommandException)2 ICommandSender (net.minecraft.command.ICommandSender)2 Sets (com.google.common.collect.Sets)1 Doubles (com.google.common.primitives.Doubles)1 BlockArea (ivorius.ivtoolkit.blocks.BlockArea)1 BlockStates (ivorius.ivtoolkit.blocks.BlockStates)1 IvShapeHelper (ivorius.ivtoolkit.math.IvShapeHelper)1 MockWorld (ivorius.ivtoolkit.world.MockWorld)1 NaP (ivorius.mcopts.commands.parameters.NaP)1 Parameter (ivorius.mcopts.commands.parameters.Parameter)1 ServerTranslations (ivorius.mcopts.translation.ServerTranslations)1