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);
}
}
}
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));
}
}
Aggregations