Search in sources :

Example 1 with RawResourceLocation

use of ivorius.reccomplex.utils.RawResourceLocation in project RecurrentComplex by Ivorforce.

the class CommandMapAllStructure method execute.

@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
    RCParameters parameters = RCParameters.of(args);
    ResourceExpression expression = new ResourceExpression(StructureRegistry.INSTANCE::has);
    IvOptional.ifAbsent(parameters.rc("exp").expression(expression).optional(), () -> expression.setExpression(""));
    ResourceDirectory directory = parameters.rc("dir").resourceDirectory().optional().orElse(ResourceDirectory.ACTIVE);
    CommandVirtual virtual = parameters.rc().virtualCommand(server).require();
    int saved = 0, failed = 0, skipped = 0;
    for (String id : StructureRegistry.INSTANCE.ids()) {
        if (!expression.test(new RawResourceLocation(StructureRegistry.INSTANCE.status(id).getDomain(), id)))
            continue;
        Structure<?> info = StructureRegistry.INSTANCE.get(id);
        if (!(info instanceof GenericStructure)) {
            skipped++;
            continue;
        }
        GenericStructure structure = (GenericStructure) info;
        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(1).varargs());
        } catch (MockWorld.VirtualWorldException ex) {
            throw ServerTranslations.commandException("commands.rcmap.nonvirtual.arguments");
        }
        structure.worldDataCompound = worldData.createTagCompound();
        if (PacketSaveStructureHandler.write(commandSender, structure, id, directory, true, false))
            saved++;
        else
            failed++;
    }
    commandSender.sendMessage(ServerTranslations.format("commands.rcmapall.result", saved, RCTextStyle.path(directory), failed, skipped));
    RCCommands.tryReload(RecurrentComplex.loader, LeveledRegistry.Level.CUSTOM);
    RCCommands.tryReload(RecurrentComplex.loader, LeveledRegistry.Level.SERVER);
}
Also used : IvWorldData(ivorius.ivtoolkit.tools.IvWorldData) IvWorldData(ivorius.ivtoolkit.tools.IvWorldData) CommandSelecting(ivorius.reccomplex.commands.CommandSelecting) RawResourceLocation(ivorius.reccomplex.utils.RawResourceLocation) RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) CommandVirtual(ivorius.reccomplex.commands.CommandVirtual) ResourceDirectory(ivorius.reccomplex.files.loading.ResourceDirectory) MockWorld(ivorius.ivtoolkit.world.MockWorld) GenericStructure(ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure) ResourceExpression(ivorius.reccomplex.utils.expression.ResourceExpression)

Example 2 with RawResourceLocation

use of ivorius.reccomplex.utils.RawResourceLocation 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)

Aggregations

RCParameters (ivorius.reccomplex.commands.parameters.RCParameters)2 ResourceDirectory (ivorius.reccomplex.files.loading.ResourceDirectory)2 RawResourceLocation (ivorius.reccomplex.utils.RawResourceLocation)2 ResourceExpression (ivorius.reccomplex.utils.expression.ResourceExpression)2 IvWorldData (ivorius.ivtoolkit.tools.IvWorldData)1 MockWorld (ivorius.ivtoolkit.world.MockWorld)1 RCConfig (ivorius.reccomplex.RCConfig)1 RecurrentComplex (ivorius.reccomplex.RecurrentComplex)1 CommandSelecting (ivorius.reccomplex.commands.CommandSelecting)1 CommandVirtual (ivorius.reccomplex.commands.CommandVirtual)1 RCCommands (ivorius.reccomplex.commands.RCCommands)1 RCExpect (ivorius.reccomplex.commands.parameters.RCExpect)1 LeveledRegistry (ivorius.reccomplex.files.loading.LeveledRegistry)1 FileSaverAdapter (ivorius.reccomplex.files.saving.FileSaverAdapter)1 ServerTranslations (ivorius.reccomplex.utils.ServerTranslations)1 ExpressionCache (ivorius.reccomplex.utils.algebra.ExpressionCache)1 GenericStructure (ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure)1 Collections (java.util.Collections)1 List (java.util.List)1 Optional (java.util.Optional)1