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