Search in sources :

Example 6 with ModMetadata

use of net.fabricmc.loader.api.metadata.ModMetadata in project BCLib by paulevsGitch.

the class ModUtil method accept.

private static void accept(Path file) {
    try {
        URI uri = URI.create("jar:" + file.toUri());
        FileSystem fs;
        // boolean doClose = false;
        try {
            fs = FileSystems.getFileSystem(uri);
        } catch (Exception e) {
            // doClose = true;
            fs = FileSystems.newFileSystem(file);
        }
        if (fs != null) {
            try {
                Path modMetaFile = fs.getPath("fabric.mod.json");
                if (modMetaFile != null) {
                    try (InputStream is = Files.newInputStream(modMetaFile)) {
                        // ModMetadata mc = ModMetadataParser.parseMetadata(is, uri.toString(), new LinkedList<String>());
                        ModMetadata mc = readJSON(is, uri.toString());
                        if (mc != null) {
                            mods.put(mc.getId(), new ModInfo(mc, file));
                        }
                    }
                }
            } catch (Exception e) {
                BCLib.LOGGER.error("Error for " + uri + ": " + e.toString());
            }
        // if (doClose) fs.close();
        }
    } catch (Exception e) {
        BCLib.LOGGER.error("Error for " + file.toUri() + ": " + e.toString());
        e.printStackTrace();
    }
}
Also used : Path(java.nio.file.Path) ModMetadata(net.fabricmc.loader.api.metadata.ModMetadata) InputStream(java.io.InputStream) FileSystem(java.nio.file.FileSystem) URI(java.net.URI) VersionParsingException(net.fabricmc.loader.api.VersionParsingException) IOException(java.io.IOException)

Example 7 with ModMetadata

use of net.fabricmc.loader.api.metadata.ModMetadata in project BCLib by paulevsGitch.

the class ModUtil method readJSON.

private static ModMetadata readJSON(InputStream is, String sourceFile) throws IOException {
    try (com.google.gson.stream.JsonReader reader = new JsonReader(new InputStreamReader(is, StandardCharsets.UTF_8))) {
        JsonObject data = new JsonParser().parse(reader).getAsJsonObject();
        Version ver;
        try {
            ver = new SemanticVersionImpl(data.get("version").getAsString(), false);
        } catch (VersionParsingException e) {
            BCLib.LOGGER.error("Unable to parse Version in " + sourceFile);
            return null;
        }
        if (data.get("id") == null) {
            BCLib.LOGGER.error("Unable to read ID in " + sourceFile);
            return null;
        }
        if (data.get("name") == null) {
            BCLib.LOGGER.error("Unable to read name in " + sourceFile);
            return null;
        }
        return new ModMetadata() {

            @Override
            public Version getVersion() {
                return ver;
            }

            @Override
            public String getType() {
                return "fabric";
            }

            @Override
            public String getId() {
                return data.get("id").getAsString();
            }

            @Override
            public Collection<String> getProvides() {
                return new ArrayList<>();
            }

            @Override
            public ModEnvironment getEnvironment() {
                JsonElement env = data.get("environment");
                if (env == null) {
                    BCLib.LOGGER.warning("No environment specified in " + sourceFile);
                // return ModEnvironment.UNIVERSAL;
                }
                final String environment = env == null ? "" : env.getAsString().toLowerCase(Locale.ROOT);
                if (environment.isEmpty() || environment.equals("*") || environment.equals("\"*\"") || environment.equals("common")) {
                    JsonElement entrypoints = data.get("entrypoints");
                    boolean hasClient = true;
                    // check if there is an actual client entrypoint
                    if (entrypoints != null && entrypoints.isJsonObject()) {
                        JsonElement client = entrypoints.getAsJsonObject().get("client");
                        if (client != null && client.isJsonArray()) {
                            hasClient = client.getAsJsonArray().size() > 0;
                        } else if (client == null || !client.isJsonPrimitive()) {
                            hasClient = false;
                        } else if (!client.getAsJsonPrimitive().isString()) {
                            hasClient = false;
                        }
                    }
                    // if (hasClient == false) return ModEnvironment.SERVER;
                    return ModEnvironment.UNIVERSAL;
                } else if (environment.equals("client")) {
                    return ModEnvironment.CLIENT;
                } else if (environment.equals("server")) {
                    return ModEnvironment.SERVER;
                } else {
                    BCLib.LOGGER.error("Unable to read environment in " + sourceFile);
                    return ModEnvironment.UNIVERSAL;
                }
            }

            @Override
            public Collection<ModDependency> getDepends() {
                return new ArrayList<>();
            }

            @Override
            public Collection<ModDependency> getRecommends() {
                return new ArrayList<>();
            }

            @Override
            public Collection<ModDependency> getSuggests() {
                return new ArrayList<>();
            }

            @Override
            public Collection<ModDependency> getConflicts() {
                return new ArrayList<>();
            }

            @Override
            public Collection<ModDependency> getBreaks() {
                return new ArrayList<>();
            }

            public Collection<ModDependency> getDependencies() {
                return new ArrayList<>();
            }

            @Override
            public String getName() {
                return data.get("name").getAsString();
            }

            @Override
            public String getDescription() {
                return "";
            }

            @Override
            public Collection<Person> getAuthors() {
                return new ArrayList<>();
            }

            @Override
            public Collection<Person> getContributors() {
                return new ArrayList<>();
            }

            @Override
            public ContactInformation getContact() {
                return null;
            }

            @Override
            public Collection<String> getLicense() {
                return new ArrayList<>();
            }

            @Override
            public Optional<String> getIconPath(int size) {
                return Optional.empty();
            }

            @Override
            public boolean containsCustomValue(String key) {
                return false;
            }

            @Override
            public CustomValue getCustomValue(String key) {
                return null;
            }

            @Override
            public Map<String, CustomValue> getCustomValues() {
                return new HashMap<>();
            }

            @Override
            public boolean containsCustomElement(String key) {
                return false;
            }

            public JsonElement getCustomElement(String key) {
                return null;
            }
        };
    }
}
Also used : SemanticVersionImpl(net.fabricmc.loader.util.version.SemanticVersionImpl) InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) ModDependency(net.fabricmc.loader.api.metadata.ModDependency) JsonReader(com.google.gson.stream.JsonReader) CustomValue(net.fabricmc.loader.api.metadata.CustomValue) VersionParsingException(net.fabricmc.loader.api.VersionParsingException) ModMetadata(net.fabricmc.loader.api.metadata.ModMetadata) Version(net.fabricmc.loader.api.Version) SemanticVersion(net.fabricmc.loader.api.SemanticVersion) JsonElement(com.google.gson.JsonElement) JsonReader(com.google.gson.stream.JsonReader) Person(net.fabricmc.loader.api.metadata.Person) JsonParser(com.google.gson.JsonParser)

Example 8 with ModMetadata

use of net.fabricmc.loader.api.metadata.ModMetadata in project fabric-loader by FabricMC.

the class ModDiscoverer method createJavaMod.

private ModCandidate createJavaMod() {
    ModMetadata metadata = new BuiltinModMetadata.Builder("java", System.getProperty("java.specification.version").replaceFirst("^1\\.", "")).setName(System.getProperty("java.vm.name")).build();
    BuiltinMod builtinMod = new BuiltinMod(Collections.singletonList(Paths.get(System.getProperty("java.home"))), metadata);
    return ModCandidate.createBuiltin(builtinMod, versionOverrides, depOverrides);
}
Also used : BuiltinMod(net.fabricmc.loader.impl.game.GameProvider.BuiltinMod) ModMetadata(net.fabricmc.loader.api.metadata.ModMetadata) LoaderModMetadata(net.fabricmc.loader.impl.metadata.LoaderModMetadata) BuiltinModMetadata(net.fabricmc.loader.impl.metadata.BuiltinModMetadata)

Example 9 with ModMetadata

use of net.fabricmc.loader.api.metadata.ModMetadata in project meteor-client by MeteorDevelopment.

the class AddonManager method init.

@Init(stage = InitStage.Pre)
public static void init() {
    // Meteor pseudo addon
    {
        METEOR = new MeteorAddon() {

            @Override
            public void onInitialize() {
            }
        };
        ModMetadata metadata = FabricLoader.getInstance().getModContainer("meteor-client").get().getMetadata();
        METEOR.name = metadata.getName();
        METEOR.authors = new String[metadata.getAuthors().size()];
        if (metadata.containsCustomValue("meteor-client:color"))
            METEOR.color.parse(metadata.getCustomValue("meteor-client:color").getAsString());
        int i = 0;
        for (Person author : metadata.getAuthors()) {
            METEOR.authors[i++] = author.getName();
        }
    }
    // Addons
    for (EntrypointContainer<MeteorAddon> entrypoint : FabricLoader.getInstance().getEntrypointContainers("meteor", MeteorAddon.class)) {
        ModMetadata metadata = entrypoint.getProvider().getMetadata();
        MeteorAddon addon = entrypoint.getEntrypoint();
        addon.name = metadata.getName();
        addon.authors = new String[metadata.getAuthors().size()];
        if (metadata.containsCustomValue("meteor-client:color"))
            addon.color.parse(metadata.getCustomValue("meteor-client:color").getAsString());
        int i = 0;
        for (Person author : metadata.getAuthors()) {
            addon.authors[i++] = author.getName();
        }
        ADDONS.add(addon);
    }
}
Also used : ModMetadata(net.fabricmc.loader.api.metadata.ModMetadata) Person(net.fabricmc.loader.api.metadata.Person) Init(meteordevelopment.meteorclient.utils.Init)

Example 10 with ModMetadata

use of net.fabricmc.loader.api.metadata.ModMetadata in project frame-fabric by moddingplayground.

the class DataMain method main.

public static void main(String[] strings) throws IOException {
    OptionParser opts = new OptionParser();
    OptionSpec<Void> help = opts.accepts("help", "Show the help menu").forHelp();
    OptionSpec<Void> server = opts.accepts("server", "Include server generators");
    OptionSpec<Void> client = opts.accepts("client", "Include client generators");
    OptionSpec<Void> dev = opts.accepts("dev", "Include development tools");
    OptionSpec<Void> reports = opts.accepts("reports", "Include data reports");
    OptionSpec<Void> validate = opts.accepts("validate", "Validate inputs");
    OptionSpec<Void> all = opts.accepts("all", "Include all generators");
    OptionSpec<String> output = opts.accepts("output", "Output folder").withRequiredArg().defaultsTo("generated");
    OptionSpec<String> extra = opts.accepts("extra", "Additional output folder to copy assets to").withRequiredArg();
    OptionSpec<String> input = opts.accepts("input", "Input folder").withRequiredArg();
    OptionSet optionSet = opts.parse(strings);
    if (!optionSet.has(help) && optionSet.hasOptions()) {
        Path path = Paths.get(output.value(optionSet));
        boolean genAll = optionSet.has(all);
        boolean genClient = genAll || optionSet.has(client);
        boolean genServer = genAll || optionSet.has(server);
        boolean genDev = genAll || optionSet.has(dev);
        boolean genReports = genAll || optionSet.has(reports);
        boolean genValidate = genAll || optionSet.has(validate);
        FabricLoader loader = FabricLoader.getInstance();
        List<EntrypointContainer<ToymakerEntrypoint>> initializers = loader.getEntrypointContainers("toymaker", ToymakerEntrypoint.class);
        if (initializers.isEmpty()) {
            LOGGER.error("No data generators were initialized!");
        } else {
            for (EntrypointContainer<ToymakerEntrypoint> initializer : initializers) {
                ModMetadata meta = initializer.getProvider().getMetadata();
                if (TARGET_MOD_ID != null && !meta.getId().equals(TARGET_MOD_ID))
                    continue;
                LOGGER.info("Initializing data generator for " + meta.getId());
                initializer.getEntrypoint().onInitializeToymaker();
            }
        }
        DataGenerator gen = create(path, optionSet.valuesOf(input).stream().map(Paths::get).collect(Collectors.toList()), genClient, genServer, genDev, genReports, genValidate);
        DataGenAccess access = (DataGenAccess) gen;
        access.run(config -> optionSet.valuesOf(extra).stream().map(Paths::get).forEach(config::addCopyPath));
    } else {
        opts.printHelpOn(System.out);
    }
}
Also used : Path(java.nio.file.Path) FabricLoader(net.fabricmc.loader.api.FabricLoader) OptionParser(joptsimple.OptionParser) EntrypointContainer(net.fabricmc.loader.api.entrypoint.EntrypointContainer) ModMetadata(net.fabricmc.loader.api.metadata.ModMetadata) DataGenerator(net.minecraft.data.DataGenerator) Paths(java.nio.file.Paths) OptionSet(joptsimple.OptionSet) ToymakerEntrypoint(net.moddingplayground.frame.api.toymaker.v0.ToymakerEntrypoint)

Aggregations

ModMetadata (net.fabricmc.loader.api.metadata.ModMetadata)14 FabricLoader (net.fabricmc.loader.api.FabricLoader)3 ModContainer (net.fabricmc.loader.api.ModContainer)3 VersionParsingException (net.fabricmc.loader.api.VersionParsingException)3 File (java.io.File)2 Path (java.nio.file.Path)2 EntrypointContainer (net.fabricmc.loader.api.entrypoint.EntrypointContainer)2 Person (net.fabricmc.loader.api.metadata.Person)2 Iterables (com.google.common.collect.Iterables)1 LinkedHashMultimap (com.google.common.collect.LinkedHashMultimap)1 Multimap (com.google.common.collect.Multimap)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 JsonReader (com.google.gson.stream.JsonReader)1 CommandDispatcher (com.mojang.brigadier.CommandDispatcher)1 LiteralArgumentBuilder (com.mojang.brigadier.builder.LiteralArgumentBuilder)1 CommandContext (com.mojang.brigadier.context.CommandContext)1 ModMenuApi (com.terraformersmc.modmenu.api.ModMenuApi)1 ModConfigFile (com.tom.cpl.config.ModConfigFile)1