Search in sources :

Example 1 with PositionedBlockExpression

use of ivorius.reccomplex.utils.expression.PositionedBlockExpression in project RecurrentComplex by Ivorforce.

the class CommandSelectReplace 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("metadata").metadatas().optional().orElse(new int[1]);
    List<IBlockState> dst = IntStream.of(dstMeta).mapToObj(m -> BlockStates.fromMetadata(dstBlock, m)).collect(Collectors.toList());
    PositionedBlockExpression matcher = parameters.rc().move(1).expression(new PositionedBlockExpression(RecurrentComplex.specialRegistry)).require();
    SelectionOwner selectionOwner = RCCommands.getSelectionOwner(commandSender, null, true);
    RCCommands.assertSize(commandSender, selectionOwner);
    for (BlockPos coord : selectionOwner.getSelection()) {
        if (matcher.evaluate(() -> PositionedBlockExpression.Argument.at(world, coord))) {
            IBlockState state = dst.get(world.rand().nextInt(dst.size()));
            world.setBlockState(coord, state, 3);
        }
    }
}
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) 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) RecurrentComplex(ivorius.reccomplex.RecurrentComplex) RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) PositionedBlockExpression(ivorius.reccomplex.utils.expression.PositionedBlockExpression) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) IBlockState(net.minecraft.block.state.IBlockState) PositionedBlockExpression(ivorius.reccomplex.utils.expression.PositionedBlockExpression) SelectionOwner(ivorius.reccomplex.capability.SelectionOwner) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos)

Example 2 with PositionedBlockExpression

use of ivorius.reccomplex.utils.expression.PositionedBlockExpression in project RecurrentComplex by Ivorforce.

the class CommandSetProperty method execute.

@Override
public void execute(MockWorld world, ICommandSender commandSender, String[] args) throws CommandException {
    RCParameters parameters = RCParameters.of(args);
    PositionedBlockExpression matcher = new PositionedBlockExpression(RecurrentComplex.specialRegistry);
    IvOptional.ifAbsent(parameters.rc("exp").expression(matcher).optional(), () -> matcher.setExpression(""));
    String propertyName = parameters.get().first().require();
    String propertyValue = parameters.get().at(1).require();
    SelectionOwner selectionOwner = RCCommands.getSelectionOwner(commandSender, null, true);
    RCCommands.assertSize(commandSender, selectionOwner);
    for (BlockPos pos : BlockAreas.mutablePositions(selectionOwner.getSelection())) {
        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));
    }
}
Also used : RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) SelectionOwner(ivorius.reccomplex.capability.SelectionOwner) TransformerProperty(ivorius.reccomplex.world.gen.feature.structure.generic.transformers.TransformerProperty) RCCommands(ivorius.reccomplex.commands.RCCommands) BlockAreas(ivorius.ivtoolkit.blocks.BlockAreas) 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) IvOptional(ivorius.reccomplex.utils.optional.IvOptional) CommandException(net.minecraft.command.CommandException) MinecraftServer(net.minecraft.server.MinecraftServer) List(java.util.List) ICommandSender(net.minecraft.command.ICommandSender) RecurrentComplex(ivorius.reccomplex.RecurrentComplex) RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) PositionedBlockExpression(ivorius.reccomplex.utils.expression.PositionedBlockExpression) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) PositionedBlockExpression(ivorius.reccomplex.utils.expression.PositionedBlockExpression) SelectionOwner(ivorius.reccomplex.capability.SelectionOwner) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

MockWorld (ivorius.ivtoolkit.world.MockWorld)2 RCConfig (ivorius.reccomplex.RCConfig)2 RecurrentComplex (ivorius.reccomplex.RecurrentComplex)2 SelectionOwner (ivorius.reccomplex.capability.SelectionOwner)2 CommandVirtual (ivorius.reccomplex.commands.CommandVirtual)2 RCCommands (ivorius.reccomplex.commands.RCCommands)2 RCExpect (ivorius.reccomplex.commands.parameters.RCExpect)2 RCParameters (ivorius.reccomplex.commands.parameters.RCParameters)2 ServerTranslations (ivorius.reccomplex.utils.ServerTranslations)2 PositionedBlockExpression (ivorius.reccomplex.utils.expression.PositionedBlockExpression)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Nonnull (javax.annotation.Nonnull)2 Nullable (javax.annotation.Nullable)2 CommandException (net.minecraft.command.CommandException)2 ICommandSender (net.minecraft.command.ICommandSender)2 MinecraftServer (net.minecraft.server.MinecraftServer)2 BlockPos (net.minecraft.util.math.BlockPos)2 BlockAreas (ivorius.ivtoolkit.blocks.BlockAreas)1 BlockStates (ivorius.ivtoolkit.blocks.BlockStates)1