Search in sources :

Example 6 with ResourceDirectory

use of ivorius.reccomplex.files.loading.ResourceDirectory in project RecurrentComplex by Ivorforce.

the class PacketSaveStructureHandler method write.

public static boolean write(ICommandSender sender, GenericStructure structure, String id, ResourceDirectory saveDir, boolean deleteOther, boolean inform) {
    StructureRegistry.INSTANCE.register(id, "", structure, saveDir.isActive(), saveDir.getLevel());
    ResourceDirectory delDir = saveDir.opposite();
    boolean saveResult = RecurrentComplex.saver.trySave(saveDir.toPath(), RCFileSaver.STRUCTURE, id);
    if (!inform || RCCommands.informSaveResult(saveResult, sender, saveDir, RCFileSaver.STRUCTURE, id)) {
        if (deleteOther) {
            Pair<Set<Path>, Set<Path>> deleteResult = RecurrentComplex.saver.tryDeleteWithID(delDir.toPath(), RCFileSaver.STRUCTURE, id);
            if (inform)
                RCCommands.informDeleteResult(deleteResult, sender, RCFileSaver.STRUCTURE, id, delDir);
        }
    }
    return saveResult;
}
Also used : Set(java.util.Set) ResourceDirectory(ivorius.reccomplex.files.loading.ResourceDirectory)

Example 7 with ResourceDirectory

use of ivorius.reccomplex.files.loading.ResourceDirectory 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 8 with ResourceDirectory

use of ivorius.reccomplex.files.loading.ResourceDirectory in project RecurrentComplex by Ivorforce.

the class PacketSaveStructureHandler method processServer.

@Override
public void processServer(PacketSaveStructure message, MessageContext ctx, WorldServer server) {
    NetHandlerPlayServer netHandlerPlayServer = ctx.getServerHandler();
    EntityPlayerMP player = netHandlerPlayServer.player;
    if (RecurrentComplex.checkPerms(player))
        return;
    RCEntityInfo entityInfo = RCEntityInfo.get(player, null);
    GenericStructure genericStructureInfo = message.getStructureInfo();
    if (entityInfo != null)
        genericStructureInfo.worldDataCompound = entityInfo.getCachedExportStructureBlockDataNBT();
    SaveDirectoryData.Result saveDirectoryDataResult = message.getSaveDirectoryDataResult();
    String id = message.getStructureID();
    ResourceDirectory saveDir = saveDirectoryDataResult.directory;
    write(player, genericStructureInfo, id, saveDir, saveDirectoryDataResult.deleteOther, true);
}
Also used : ResourceDirectory(ivorius.reccomplex.files.loading.ResourceDirectory) SaveDirectoryData(ivorius.reccomplex.utils.SaveDirectoryData) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) RCEntityInfo(ivorius.reccomplex.capability.RCEntityInfo) NetHandlerPlayServer(net.minecraft.network.NetHandlerPlayServer) GenericStructure(ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure)

Example 9 with ResourceDirectory

use of ivorius.reccomplex.files.loading.ResourceDirectory in project RecurrentComplex by Ivorforce.

the class PacketSaveLootTableHandler method processServer.

@Override
public void processServer(PacketSaveLootTable message, MessageContext ctx, WorldServer server) {
    NetHandlerPlayServer playServer = ctx.getServerHandler();
    EntityPlayerMP player = playServer.player;
    if (RecurrentComplex.checkPerms(player))
        return;
    SaveDirectoryData.Result saveDirectoryDataResult = message.getSaveDirectoryDataResult();
    String id = message.getKey();
    ResourceDirectory saveDir = saveDirectoryDataResult.directory;
    ResourceDirectory delDir = saveDir.opposite();
    GenericItemCollectionRegistry.INSTANCE.register(id, "", message.getComponent(), saveDir.isActive(), saveDir.getLevel());
    if (RCCommands.informSaveResult((message.getComponent() != null && id != null) && RecurrentComplex.saver.trySave(saveDir.toPath(), RCFileSaver.INVENTORY_GENERATION_COMPONENT, id), player, saveDir, RCFileSaver.INVENTORY_GENERATION_COMPONENT, id)) {
        if (saveDirectoryDataResult.deleteOther)
            RCCommands.informDeleteResult(RecurrentComplex.saver.tryDeleteWithID(delDir.toPath(), RCFileSaver.INVENTORY_GENERATION_COMPONENT, id), player, RCFileSaver.INVENTORY_GENERATION_COMPONENT, id, delDir);
        ItemStack heldItem = playServer.player.getHeldItem(EnumHand.MAIN_HAND);
        if (heldItem != null && heldItem.getItem() instanceof ItemLootTableComponentTag)
            ItemLootTableComponentTag.setComponentKey(heldItem, id);
        player.openContainer.detectAndSendChanges();
    }
}
Also used : ResourceDirectory(ivorius.reccomplex.files.loading.ResourceDirectory) SaveDirectoryData(ivorius.reccomplex.utils.SaveDirectoryData) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ItemLootTableComponentTag(ivorius.reccomplex.item.ItemLootTableComponentTag) ItemStack(net.minecraft.item.ItemStack) NetHandlerPlayServer(net.minecraft.network.NetHandlerPlayServer)

Example 10 with ResourceDirectory

use of ivorius.reccomplex.files.loading.ResourceDirectory in project RecurrentComplex by Ivorforce.

the class CommandConvertSchematic method execute.

@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
    Parameters parameters = Parameters.of(args, expect()::declare);
    EntityPlayerMP player = getCommandSenderAsPlayer(commandSender);
    if (args.length < 1)
        throw RecurrentComplex.translations.wrongUsageException("commands.rcconvertschematic.usage");
    ResourceDirectory directory = parameters.get("directory").to(RCP::resourceDirectory).optional().orElse(null);
    String schematicName = parameters.get(0).require();
    String structureID = parameters.get("id").optional().orElse(schematicName);
    SchematicFile schematicFile = CommandImportSchematic.parseSchematic(schematicName);
    GenericStructure from = parameters.get("from").to(RCP::structureFromBlueprint, commandSender).require();
    from.worldDataCompound = CommandExportSchematic.toWorldData(schematicFile).createTagCompound();
    PacketEditStructureHandler.openEditStructure(player, from, player.getPosition(), structureID, directory);
}
Also used : SchematicFile(ivorius.reccomplex.world.gen.feature.structure.schematics.SchematicFile) Parameters(ivorius.mcopts.commands.parameters.Parameters) ResourceDirectory(ivorius.reccomplex.files.loading.ResourceDirectory) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) RCP(ivorius.reccomplex.commands.parameters.RCP) GenericStructure(ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure)

Aggregations

ResourceDirectory (ivorius.reccomplex.files.loading.ResourceDirectory)13 RCP (ivorius.reccomplex.commands.parameters.RCP)7 GenericStructure (ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure)6 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)6 Parameters (ivorius.mcopts.commands.parameters.Parameters)5 RCConfig (ivorius.reccomplex.RCConfig)5 RawResourceLocation (ivorius.reccomplex.utils.RawResourceLocation)5 ResourceExpression (ivorius.reccomplex.utils.expression.ResourceExpression)5 CommandException (net.minecraft.command.CommandException)5 ICommandSender (net.minecraft.command.ICommandSender)5 MinecraftServer (net.minecraft.server.MinecraftServer)5 CommandExpecting (ivorius.mcopts.commands.CommandExpecting)4 Expect (ivorius.mcopts.commands.parameters.expect.Expect)4 RecurrentComplex (ivorius.reccomplex.RecurrentComplex)4 RCCommands (ivorius.reccomplex.commands.RCCommands)4 RCE (ivorius.reccomplex.commands.parameters.expect.RCE)4 LeveledRegistry (ivorius.reccomplex.files.loading.LeveledRegistry)4 NaP (ivorius.mcopts.commands.parameters.NaP)3 FileSaverAdapter (ivorius.reccomplex.files.saving.FileSaverAdapter)3 SaveDirectoryData (ivorius.reccomplex.utils.SaveDirectoryData)3