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