use of net.minecraftforge.fml.loading.moddiscovery.ModInfo in project Catalogue by MrCrayfish.
the class CatalogueModListScreen method loadAndCacheIcon.
private void loadAndCacheIcon(IModInfo info) {
if (ICON_CACHE.containsKey(info.getModId()))
return;
// Fills an empty icon as icon may not be present
ICON_CACHE.put(info.getModId(), Pair.of(null, new Size2i(0, 0)));
// Attempts to load the real icon
ModInfo modInfo = (ModInfo) info;
if (modInfo.getModProperties().containsKey("catalogueImageIcon")) {
String s = (String) modInfo.getModProperties().get("catalogueImageIcon");
if (s.isEmpty())
return;
if (s.contains("/") || s.contains("\\")) {
Catalogue.LOGGER.warn("Skipped loading Catalogue icon file from {}. The file name '{}' contained illegal characters '/' or '\\'", info.getDisplayName(), s);
return;
}
PathResourcePack resourcePack = ResourcePackLoader.getPackFor(info.getModId()).orElse(ResourcePackLoader.getPackFor("forge").orElseThrow(() -> new RuntimeException("Can't find forge, WHAT!")));
try (InputStream is = resourcePack.getRootResource(s);
NativeImage icon = NativeImage.read(is)) {
TextureManager textureManager = this.getMinecraft().getTextureManager();
ICON_CACHE.put(info.getModId(), Pair.of(textureManager.register("catalogueicon", this.createLogoTexture(icon, false)), new Size2i(icon.getWidth(), icon.getHeight())));
return;
} catch (IOException ignored) {
}
}
// Attempts to use the logo file if it's a square
modInfo.getLogoFile().ifPresent(s -> {
if (s.isEmpty())
return;
if (s.contains("/") || s.contains("\\")) {
Catalogue.LOGGER.warn("Skipped loading logo file from {}. The file name '{}' contained illegal characters '/' or '\\'", info.getDisplayName(), s);
return;
}
PathResourcePack resourcePack = ResourcePackLoader.getPackFor(info.getModId()).orElse(ResourcePackLoader.getPackFor("forge").orElseThrow(() -> new RuntimeException("Can't find forge, WHAT!")));
try (InputStream is = resourcePack.getRootResource(s);
NativeImage logo = NativeImage.read(is)) {
if (logo.getWidth() == logo.getHeight()) {
TextureManager textureManager = this.getMinecraft().getTextureManager();
String modId = info.getModId();
/* The first selected mod will have it's logo cached before the icon, so we
* can just use the logo instead of loading the image again. */
if (LOGO_CACHE.containsKey(modId)) {
if (LOGO_CACHE.get(modId).getLeft() != null) {
ICON_CACHE.put(modId, LOGO_CACHE.get(modId));
return;
}
}
/* Since the icon will be same as the logo, we can cache into both icon and logo cache */
DynamicTexture texture = this.createLogoTexture(logo, modInfo.getLogoBlur());
Size2i size = new Size2i(logo.getWidth(), logo.getHeight());
ResourceLocation textureId = textureManager.register("catalogueicon", texture);
ICON_CACHE.put(modId, Pair.of(textureId, size));
LOGO_CACHE.put(modId, Pair.of(textureId, size));
}
} catch (IOException ignored) {
}
});
}
use of net.minecraftforge.fml.loading.moddiscovery.ModInfo in project Magma-1.16.x by magmafoundation.
the class ModSorter method addDependency.
@SuppressWarnings("UnstableApiUsage")
private void addDependency(MutableGraph<ModFileInfo> topoGraph, IModInfo.ModVersion dep) {
final ModFileInfo self = (ModFileInfo) dep.getOwner().getOwningFile();
final ModInfo targetModInfo = modIdNameLookup.get(dep.getModId());
// soft dep that doesn't exist. Just return. No edge required.
if (targetModInfo == null)
return;
final ModFileInfo target = targetModInfo.getOwningFile();
if (self == target)
// in case a jar has two mods that have dependencies between
return;
switch(dep.getOrdering()) {
case BEFORE:
topoGraph.putEdge(self, target);
break;
case AFTER:
topoGraph.putEdge(target, self);
break;
case NONE:
break;
}
}
use of net.minecraftforge.fml.loading.moddiscovery.ModInfo in project roadrunner by MaxNeedsSnacks.
the class RoadRunnerRuleConfig method applyModOverrides.
/*
* Modified by RoadRunner for Forge mods
*
* Since Forge doesn't have any good ways to add overrides to the metadata files,
* we'll just be using a properties file that goes into a mod's resources folder.
*
*/
private void applyModOverrides() {
for (ModInfo mod : LoadingModList.get().getMods()) {
String modid = mod.getModId();
Path path = mod.getOwningFile().getFile().findResource("roadrunner.overrides.properties");
if (Files.exists(path)) {
Properties props = new Properties();
try (InputStream stream = Files.newInputStream(path)) {
props.load(stream);
} catch (IOException e) {
LOGGER.warn("Could not load overrides file for mod '{}', ignoring", modid);
continue;
}
for (Map.Entry<Object, Object> entry : props.entrySet()) {
applyModOverride(modid, entry.getKey().toString(), entry.getValue().toString());
}
}
}
}
use of net.minecraftforge.fml.loading.moddiscovery.ModInfo in project simple-voice-chat by henkelmax.
the class DebugReport method appendMods.
private void appendMods() {
addLine("Loaded mods");
addLine("");
for (ModInfo mod : ModList.get().getMods()) {
addLine("Mod ID: " + mod.getModId());
addLine("Name: " + mod.getDisplayName());
addLine("Version: " + mod.getVersion().getQualifier());
addLine("Dependencies: " + mod.getDependencies().stream().map(IModInfo.ModVersion::getModId).collect(Collectors.joining(", ")));
addLine("");
}
}
use of net.minecraftforge.fml.loading.moddiscovery.ModInfo in project Catalogue by MrCrayfish.
the class CatalogueModListScreen method drawModInfo.
/**
* Draws everything considered right of the screen; logo, mod title, description and more.
*
* @param poseStack the current matrix stack
* @param mouseX the current mouse x position
* @param mouseY the current mouse y position
* @param partialTicks the partial ticks
*/
private void drawModInfo(PoseStack poseStack, int mouseX, int mouseY, float partialTicks) {
this.vLine(poseStack, this.modList.getRight() + 11, -1, this.height, 0xFF707070);
fill(poseStack, this.modList.getRight() + 12, 0, this.width, this.height, 0x66000000);
this.descriptionList.render(poseStack, mouseX, mouseY, partialTicks);
int contentLeft = this.modList.getRight() + 12 + 10;
int contentWidth = this.width - contentLeft - 10;
if (this.selectedModInfo != null) {
// Draw mod logo
this.drawLogo(poseStack, contentWidth, contentLeft, 10, this.width - (this.modList.getRight() + 12 + 10) - 10, 50);
// Draw mod name
poseStack.pushPose();
poseStack.translate(contentLeft, 70, 0);
poseStack.scale(2.0F, 2.0F, 2.0F);
drawString(poseStack, this.font, this.selectedModInfo.getDisplayName(), 0, 0, 0xFFFFFF);
poseStack.popPose();
// Draw version
Component modId = new TextComponent("Mod ID: " + this.selectedModInfo.getModId()).withStyle(ChatFormatting.DARK_GRAY);
int modIdWidth = this.font.width(modId);
drawString(poseStack, this.font, modId, contentLeft + contentWidth - modIdWidth, 92, 0xFFFFFF);
// Set tooltip for secure mod features forge has. REMOVED DUE TO FORGE ALSO REMOVING
/*if(ScreenUtil.isMouseWithin(contentLeft + contentWidth - modIdWidth, 92, modIdWidth, this.font.lineHeight, mouseX, mouseY))
{
if(FMLEnvironment.secureJarsEnabled)
{
this.setActiveTooltip(ForgeI18n.parseMessage("fml.menu.mods.info.signature", ((ModInfo) this.selectedModInfo).getOwningFile().getCodeSigningFingerprint().orElse(ForgeI18n.parseMessage("fml.menu.mods.info.signature.unsigned"))));
this.setActiveTooltip(ForgeI18n.parseMessage("fml.menu.mods.info.trust", ((ModInfo) this.selectedModInfo).getOwningFile().getTrustData().orElse(ForgeI18n.parseMessage("fml.menu.mods.info.trust.noauthority"))));
}
else
{
this.setActiveTooltip(ForgeI18n.parseMessage("fml.menu.mods.info.securejardisabled"));
}
}*/
// Draw version
this.drawStringWithLabel(poseStack, "fml.menu.mods.info.version", this.selectedModInfo.getVersion().toString(), contentLeft, 92, contentWidth, mouseX, mouseY, ChatFormatting.GRAY, ChatFormatting.WHITE);
// Draws an icon if there is an update for the mod
VersionChecker.CheckResult result = VersionChecker.getResult(this.selectedModInfo);
if (result.status().shouldDraw() && result.url() != null) {
String version = ForgeI18n.parseMessage("fml.menu.mods.info.version", this.selectedModInfo.getVersion().toString());
int versionWidth = this.font.width(version);
RenderSystem.setShader(GameRenderer::getPositionColorTexShader);
RenderSystem.setShaderTexture(0, VERSION_CHECK_ICONS);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
int vOffset = result.status().isAnimated() && (System.currentTimeMillis() / 800 & 1) == 1 ? 8 : 0;
Screen.blit(poseStack, contentLeft + versionWidth + 5, 92, result.status().getSheetOffset() * 8, vOffset, 8, 8, 64, 16);
if (ScreenUtil.isMouseWithin(contentLeft + versionWidth + 5, 92, 8, 8, mouseX, mouseY)) {
this.setActiveTooltip(ForgeI18n.parseMessage("fml.menu.mods.info.updateavailable", result.url()));
}
}
int labelOffset = this.height - 20;
// Draw license
String license = this.selectedModInfo.getOwningFile().getLicense();
this.drawStringWithLabel(poseStack, "fml.menu.mods.info.license", license, contentLeft, labelOffset, contentWidth, mouseX, mouseY, ChatFormatting.GRAY, ChatFormatting.WHITE);
labelOffset -= 15;
// Draw credits
Optional<Object> credits = ((ModInfo) this.selectedModInfo).getConfigElement("credits");
if (credits.isPresent()) {
this.drawStringWithLabel(poseStack, "fml.menu.mods.info.credits", credits.get().toString(), contentLeft, labelOffset, contentWidth, mouseX, mouseY, ChatFormatting.GRAY, ChatFormatting.WHITE);
labelOffset -= 15;
}
// Draw authors
Optional<Object> authors = ((ModInfo) this.selectedModInfo).getConfigElement("authors");
if (authors.isPresent()) {
this.drawStringWithLabel(poseStack, "fml.menu.mods.info.authors", authors.get().toString(), contentLeft, labelOffset, contentWidth, mouseX, mouseY, ChatFormatting.GRAY, ChatFormatting.WHITE);
}
} else {
Component message = new TranslatableComponent("catalogue.gui.no_selection").withStyle(ChatFormatting.GRAY);
drawCenteredString(poseStack, this.font, message, contentLeft + contentWidth / 2, this.height / 2 - 5, 0xFFFFFF);
}
}
Aggregations