public static boolean isModLoaded( final String modid ) { try { // if this fails for some reason, try the other method. return Loader.isModLoaded( modid ); } catch( final Throwable ignored ) { } for( final ModContainer f : Loader.instance().getActiveModList() ) { if( f.getModId().equals( modid ) ) { return true; } } return false; }
final List<ModContainer> mods = loader.getActiveModList();
@Nullable static String getModNameByModId(String modId) { ModContainer container = Loader.instance().getActiveModList().stream() .filter(m -> m.getModId().toLowerCase().equals(modId)) .findFirst() .orElse(null); return container == null ? null : container.getName(); }
private String getStatsString() { try { String b = "?" + "current=" + URLEncoder.encode(currentVersion.trim(), "UTF-8") + '&' + "mc=" + URLEncoder.encode(Loader.MC_VERSION, "UTF-8") + '&' + "count=" + URLEncoder.encode("" + Loader.instance().getActiveModList().size(), "UTF-8") + '&' + "side=" + (FMLCommonHandler.instance().getEffectiveSide().isClient() ? "client" : "server"); return b; } catch (UnsupportedEncodingException e) { return ""; } }
public void init() { List<ModContainer> mods = Loader.instance().getActiveModList(); Map<Pair<ModContainer, ResourceLocation>, String> foundBooks = new HashMap<>();
public List<Result<T>> discoverFiles(String dataRoot, String basePath) { List<ModContainer> activeModList = Loader.instance().getActiveModList(); ProgressManager.ProgressBar bar = ProgressManager.push("Discovering files", activeModList.size()); List<Result<T>> discoveries = new ArrayList<>(); for (ModContainer mod : activeModList) { bar.step(mod.getName()); String base = dataRoot + "/" + mod.getModId() + "/" + basePath; CraftingHelper.findFiles(mod, base, root -> true, (root, path) -> { Path relativePath = root.relativize(path); if (!"json".equals(FilenameUtils.getExtension(path.toString())) || relativePath.getNameCount() > 1) { return true; } String name = FilenameUtils.removeExtension(relativePath.toString()).replaceAll("\\\\", "/"); ResourceLocation key = new ResourceLocation(mod.getModId(), name); try (BufferedReader reader = Files.newBufferedReader(path)) { JsonObject rootObject = new JsonParser().parse(reader).getAsJsonObject(); discoveries.add(new Result<>(key, this.parser.apply(rootObject))); } catch (JsonParseException e) { Terrarium.LOGGER.error("Couldn't parse JSON for {}", key, e); } catch (IOException e) { Terrarium.LOGGER.error("Couldn't read JSON {} from {}", key, path, e); } return true; }, false, false); } ProgressManager.pop(bar); return discoveries; }
/** * Get's the owning mod instance. If none is set, Bookshelf will attempt to auto-get it * using Forge's loader. * * @return The owning mod's instance. */ public Object getModInstance () { if (this.modInstance == null) { Constants.LOG.error("Registry helper for " + this.modid + " requires a mod instance be set. Attempting to get instance with mod ID. Please ask the mod author to set this themselves."); for (final ModContainer container : Loader.instance().getActiveModList()) { if (this.modid.equalsIgnoreCase(container.getModId())) { this.modInstance = container.getMod(); break; } } } return this.modInstance; }
public static void loadRecipes() { ModContainer awModContainer = Loader.instance().activeModContainer(); //noinspection ConstantConditions loadRecipes(awModContainer, new File(AWCoreStatics.configPathForFiles + "research_recipes"), ""); Loader.instance().getActiveModList().forEach(m -> AWCraftingManager.loadRecipes(m, m.getSource(), "assets/" + m.getModId() + "/research_recipes")); Loader.instance().setActiveModContainer(awModContainer); }
List<ResourceLocation> foundEntries = new ArrayList<>(); List<ResourceLocation> foundTemplates = new ArrayList<>(); List<ModContainer> mods = Loader.instance().getActiveModList();
public static void preInit() { MinecraftForge.EVENT_BUS.register(ChangeListener.class); List<ModContainer> mods = Loader.instance().getActiveModList(); for(ModContainer container : mods) setFlag("mod:" + container.getModId(), true); setFlag("debug", Patchouli.debug); updateFlags(); }