Search in sources :

Example 36 with RCParameters

use of ivorius.reccomplex.commands.parameters.RCParameters in project RecurrentComplex by Ivorforce.

the class CommandWriteAll method execute.

@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
    RCParameters parameters = RCParameters.of(args);
    String adapterID = parameters.get().first().require();
    if (!RecurrentComplex.saver.has(adapterID))
        throw ServerTranslations.commandException("commands.rcsaveall.noregistry");
    ResourceDirectory directory = parameters.rc("dir").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().at(1).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(ServerTranslations.format("commands.rcsaveall.result", saved, directory, failed));
    RCCommands.tryReload(RecurrentComplex.loader, LeveledRegistry.Level.CUSTOM);
    RCCommands.tryReload(RecurrentComplex.loader, LeveledRegistry.Level.SERVER);
}
Also used : RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) ExpressionCache(ivorius.reccomplex.utils.algebra.ExpressionCache) LeveledRegistry(ivorius.reccomplex.files.loading.LeveledRegistry) RCCommands(ivorius.reccomplex.commands.RCCommands) Set(java.util.Set) ServerTranslations(ivorius.reccomplex.utils.ServerTranslations) CommandBase(net.minecraft.command.CommandBase) BlockPos(net.minecraft.util.math.BlockPos) FileSaverAdapter(ivorius.reccomplex.files.saving.FileSaverAdapter) RCConfig(ivorius.reccomplex.RCConfig) RawResourceLocation(ivorius.reccomplex.utils.RawResourceLocation) RCExpect(ivorius.reccomplex.commands.parameters.RCExpect) ResourceExpression(ivorius.reccomplex.utils.expression.ResourceExpression) CommandException(net.minecraft.command.CommandException) MinecraftServer(net.minecraft.server.MinecraftServer) List(java.util.List) ICommandSender(net.minecraft.command.ICommandSender) ResourceDirectory(ivorius.reccomplex.files.loading.ResourceDirectory) Optional(java.util.Optional) RecurrentComplex(ivorius.reccomplex.RecurrentComplex) RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) Collections(java.util.Collections) Nullable(javax.annotation.Nullable) ResourceDirectory(ivorius.reccomplex.files.loading.ResourceDirectory) FileSaverAdapter(ivorius.reccomplex.files.saving.FileSaverAdapter) ResourceExpression(ivorius.reccomplex.utils.expression.ResourceExpression) RawResourceLocation(ivorius.reccomplex.utils.RawResourceLocation)

Example 37 with RCParameters

use of ivorius.reccomplex.commands.parameters.RCParameters in project RecurrentComplex by Ivorforce.

the class CommandWriteAll method getTabCompletions.

@Override
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos pos) {
    RCParameters parameters = RCParameters.of(args);
    RCExpect<?> expect = RCExpect.expectRC();
    // Can't chain because of compiler bug :|
    expect.next(RecurrentComplex.saver.keySet());
    expect.next(args1 -> parameters.get().first().tryGet().map(RecurrentComplex.saver::get).map(a -> a.getRegistry().ids()).orElse(Collections.emptySet()));
    expect.named("dir").resourceDirectory();
    return expect.get(server, sender, args, pos);
}
Also used : RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) RecurrentComplex(ivorius.reccomplex.RecurrentComplex)

Example 38 with RCParameters

use of ivorius.reccomplex.commands.parameters.RCParameters in project RecurrentComplex by Ivorforce.

the class CommandMapStructure method execute.

@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
    RCParameters parameters = RCParameters.of(args);
    String id = parameters.get().first().require();
    GenericStructure structure = parameters.rc().genericStructure().require();
    ResourceDirectory directory = parameters.rc("dir").resourceDirectory().optional().orElse(ResourceDirectory.ACTIVE);
    CommandVirtual virtual = parameters.rc().move(1).virtualCommand(server).require();
    IvWorldData worldData = structure.constructWorldData();
    MockWorld world = new MockWorld.WorldData(worldData);
    try {
        virtual.execute(world, new CommandSelecting.SelectingSender(commandSender, BlockPos.ORIGIN, worldData.blockCollection.area().getHigherCorner()), parameters.get().move(2).varargs());
    } catch (MockWorld.VirtualWorldException ex) {
        throw ServerTranslations.commandException("commands.rcmap.nonvirtual.arguments");
    }
    structure.worldDataCompound = worldData.createTagCompound();
    PacketSaveStructureHandler.write(commandSender, structure, id, directory, true, true);
}
Also used : RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) CommandVirtual(ivorius.reccomplex.commands.CommandVirtual) ResourceDirectory(ivorius.reccomplex.files.loading.ResourceDirectory) IvWorldData(ivorius.ivtoolkit.tools.IvWorldData) IvWorldData(ivorius.ivtoolkit.tools.IvWorldData) CommandSelecting(ivorius.reccomplex.commands.CommandSelecting) MockWorld(ivorius.ivtoolkit.world.MockWorld) GenericStructure(ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure)

Example 39 with RCParameters

use of ivorius.reccomplex.commands.parameters.RCParameters in project RecurrentComplex by Ivorforce.

the class CommandSightCheck method execute.

@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
    RCParameters parameters = RCParameters.of(args);
    World world = commandSender.getEntityWorld();
    BlockPos pos = parameters.mc().pos(commandSender.getPosition(), false).require();
    List<WorldStructureGenerationData.Entry> entries = WorldStructureGenerationData.get(world).entriesAt(pos).collect(Collectors.toCollection(ArrayList::new));
    if (entries.size() > 0)
        commandSender.sendMessage(ServerTranslations.format(new ArrayList<ITextComponent>().size() > 1 ? "commands.whatisthis.many" : "commands.whatisthis.one", ServerTranslations.join(entries.stream().map(RCTextStyle::sight).collect(Collectors.toList()))));
    else
        commandSender.sendMessage(ServerTranslations.format("commands.whatisthis.none"));
}
Also used : RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) ArrayList(java.util.ArrayList) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World)

Aggregations

RCParameters (ivorius.reccomplex.commands.parameters.RCParameters)39 BlockPos (net.minecraft.util.math.BlockPos)17 SelectionOwner (ivorius.reccomplex.capability.SelectionOwner)14 GenericStructure (ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure)11 RCConfig (ivorius.reccomplex.RCConfig)8 RCExpect (ivorius.reccomplex.commands.parameters.RCExpect)8 ServerTranslations (ivorius.reccomplex.utils.ServerTranslations)8 Nullable (javax.annotation.Nullable)8 CommandException (net.minecraft.command.CommandException)8 ICommandSender (net.minecraft.command.ICommandSender)8 MinecraftServer (net.minecraft.server.MinecraftServer)8 BlockArea (ivorius.ivtoolkit.blocks.BlockArea)7 RecurrentComplex (ivorius.reccomplex.RecurrentComplex)7 ResourceDirectory (ivorius.reccomplex.files.loading.ResourceDirectory)7 List (java.util.List)7 WorldServer (net.minecraft.world.WorldServer)7 AxisAlignedTransform2D (ivorius.ivtoolkit.math.AxisAlignedTransform2D)6 MockWorld (ivorius.ivtoolkit.world.MockWorld)6 CommandVirtual (ivorius.reccomplex.commands.CommandVirtual)6 RCCommands (ivorius.reccomplex.commands.RCCommands)6