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