use of net.minecraftforge.fml.loading.moddiscovery.ModInfo in project Magma-1.16.x by magmafoundation.
the class ModListScreen method updateCache.
private void updateCache() {
if (selected == null) {
this.configButton.active = false;
this.modInfo.clearInfo();
return;
}
ModInfo selectedMod = selected.getInfo();
this.configButton.active = ConfigGuiHandler.getGuiFactoryFor(selectedMod).isPresent();
List<String> lines = new ArrayList<>();
VersionChecker.CheckResult vercheck = VersionChecker.getResult(selectedMod);
@SuppressWarnings("resource") Pair<ResourceLocation, Size2i> logoData = selectedMod.getLogoFile().map(logoFile -> {
TextureManager tm = this.minecraft.getTextureManager();
final ModFileResourcePack resourcePack = ResourcePackLoader.getResourcePackFor(selectedMod.getModId()).orElse(ResourcePackLoader.getResourcePackFor("forge").orElseThrow(() -> new RuntimeException("Can't find forge, WHAT!")));
try {
NativeImage logo = null;
InputStream logoResource = resourcePack.getRootResource(logoFile);
if (logoResource != null)
logo = NativeImage.read(logoResource);
if (logo != null) {
return Pair.of(tm.register("modlogo", new DynamicTexture(logo) {
@Override
public void upload() {
this.bind();
NativeImage td = this.getPixels();
// Use custom "blur" value which controls texture filtering (nearest-neighbor vs linear)
this.getPixels().upload(0, 0, 0, 0, 0, td.getWidth(), td.getHeight(), selectedMod.getLogoBlur(), false, false, false);
}
}), new Size2i(logo.getWidth(), logo.getHeight()));
}
} catch (IOException e) {
}
return Pair.<ResourceLocation, Size2i>of(null, new Size2i(0, 0));
}).orElse(Pair.of(null, new Size2i(0, 0)));
lines.add(selectedMod.getDisplayName());
lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.version", MavenVersionStringHelper.artifactVersionToString(selectedMod.getVersion())));
lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.idstate", selectedMod.getModId(), ModList.get().getModContainerById(selectedMod.getModId()).map(ModContainer::getCurrentState).map(Object::toString).orElse("NONE")));
selectedMod.getConfigElement("credits").ifPresent(credits -> lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.credits", credits)));
selectedMod.getConfigElement("authors").ifPresent(authors -> lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.authors", authors)));
selectedMod.getConfigElement("displayURL").ifPresent(displayURL -> lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.displayurl", displayURL)));
if (selectedMod.getOwningFile() == null || selectedMod.getOwningFile().getMods().size() == 1)
lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.nochildmods"));
else
lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.childmods", selectedMod.getOwningFile().getMods().stream().map(IModInfo::getDisplayName).collect(Collectors.joining(","))));
if (vercheck.status == VersionChecker.Status.OUTDATED || vercheck.status == VersionChecker.Status.BETA_OUTDATED)
lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.updateavailable", vercheck.url == null ? "" : vercheck.url));
lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.license", selectedMod.getOwningFile().getLicense()));
lines.add(null);
lines.add(selectedMod.getDescription());
if ((vercheck.status == VersionChecker.Status.OUTDATED || vercheck.status == VersionChecker.Status.BETA_OUTDATED) && vercheck.changes.size() > 0) {
lines.add(null);
lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.changelogheader"));
for (Entry<ComparableVersion, String> entry : vercheck.changes.entrySet()) {
lines.add(" " + entry.getKey() + ":");
lines.add(entry.getValue());
lines.add(null);
}
}
modInfo.setInfo(lines, logoData.getLeft(), logoData.getRight());
}
use of net.minecraftforge.fml.loading.moddiscovery.ModInfo in project Magma-1.16.x by magmafoundation.
the class ModListScreen method init.
@Override
public void init() {
for (ModInfo mod : mods) {
listWidth = Math.max(listWidth, getFontRenderer().width(mod.getDisplayName()) + 10);
listWidth = Math.max(listWidth, getFontRenderer().width(MavenVersionStringHelper.artifactVersionToString(mod.getVersion())) + 5);
}
listWidth = Math.max(Math.min(listWidth, width / 3), 100);
listWidth += listWidth % numButtons != 0 ? (numButtons - listWidth % numButtons) : 0;
int modInfoWidth = this.width - this.listWidth - (PADDING * 3);
int doneButtonWidth = Math.min(modInfoWidth, 200);
int y = this.height - 20 - PADDING;
this.addButton(new Button(((listWidth + PADDING + this.width - doneButtonWidth) / 2), y, doneButtonWidth, 20, new TranslationTextComponent("gui.done"), b -> ModListScreen.this.onClose()));
this.addButton(this.openModsFolderButton = new Button(6, y, this.listWidth, 20, new TranslationTextComponent("fml.menu.mods.openmodsfolder"), b -> Util.getPlatform().openFile(FMLPaths.MODSDIR.get().toFile())));
y -= 20 + PADDING;
this.addButton(this.configButton = new Button(6, y, this.listWidth, 20, new TranslationTextComponent("fml.menu.mods.config"), b -> ModListScreen.this.displayModConfig()));
this.configButton.active = false;
y -= 14 + PADDING + 1;
search = new TextFieldWidget(getFontRenderer(), PADDING + 1, y, listWidth - 2, 14, new TranslationTextComponent("fml.menu.mods.search"));
int fullButtonHeight = PADDING + 20 + PADDING;
this.modList = new ModListWidget(this, listWidth, fullButtonHeight, search.y - getFontRenderer().lineHeight - PADDING);
this.modList.setLeftPos(6);
this.modInfo = new InfoPanel(this.minecraft, modInfoWidth, this.height - PADDING - fullButtonHeight, PADDING);
children.add(search);
children.add(modList);
children.add(modInfo);
search.setFocus(false);
search.setCanLoseFocus(true);
final int width = listWidth / numButtons;
int x = PADDING;
addButton(SortType.NORMAL.button = new Button(x, PADDING, width - buttonMargin, 20, SortType.NORMAL.getButtonText(), b -> resortMods(SortType.NORMAL)));
x += width + buttonMargin;
addButton(SortType.A_TO_Z.button = new Button(x, PADDING, width - buttonMargin, 20, SortType.A_TO_Z.getButtonText(), b -> resortMods(SortType.A_TO_Z)));
x += width + buttonMargin;
addButton(SortType.Z_TO_A.button = new Button(x, PADDING, width - buttonMargin, 20, SortType.Z_TO_A.getButtonText(), b -> resortMods(SortType.Z_TO_A)));
resortMods(SortType.NORMAL);
updateCache();
}
use of net.minecraftforge.fml.loading.moddiscovery.ModInfo in project LoliServer by Loli-Server.
the class ModListScreen method updateCache.
private void updateCache() {
if (selected == null) {
this.configButton.active = false;
this.modInfo.clearInfo();
return;
}
ModInfo selectedMod = selected.getInfo();
this.configButton.active = ConfigGuiHandler.getGuiFactoryFor(selectedMod).isPresent();
List<String> lines = new ArrayList<>();
VersionChecker.CheckResult vercheck = VersionChecker.getResult(selectedMod);
@SuppressWarnings("resource") Pair<ResourceLocation, Size2i> logoData = selectedMod.getLogoFile().map(logoFile -> {
TextureManager tm = this.minecraft.getTextureManager();
final ModFileResourcePack resourcePack = ResourcePackLoader.getResourcePackFor(selectedMod.getModId()).orElse(ResourcePackLoader.getResourcePackFor("forge").orElseThrow(() -> new RuntimeException("Can't find forge, WHAT!")));
try {
NativeImage logo = null;
InputStream logoResource = resourcePack.getRootResource(logoFile);
if (logoResource != null)
logo = NativeImage.read(logoResource);
if (logo != null) {
return Pair.of(tm.register("modlogo", new DynamicTexture(logo) {
@Override
public void upload() {
this.bind();
NativeImage td = this.getPixels();
// Use custom "blur" value which controls texture filtering (nearest-neighbor vs linear)
this.getPixels().upload(0, 0, 0, 0, 0, td.getWidth(), td.getHeight(), selectedMod.getLogoBlur(), false, false, false);
}
}), new Size2i(logo.getWidth(), logo.getHeight()));
}
} catch (IOException e) {
}
return Pair.<ResourceLocation, Size2i>of(null, new Size2i(0, 0));
}).orElse(Pair.of(null, new Size2i(0, 0)));
lines.add(selectedMod.getDisplayName());
lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.version", MavenVersionStringHelper.artifactVersionToString(selectedMod.getVersion())));
lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.idstate", selectedMod.getModId(), ModList.get().getModContainerById(selectedMod.getModId()).map(ModContainer::getCurrentState).map(Object::toString).orElse("NONE")));
selectedMod.getConfigElement("credits").ifPresent(credits -> lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.credits", credits)));
selectedMod.getConfigElement("authors").ifPresent(authors -> lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.authors", authors)));
selectedMod.getConfigElement("displayURL").ifPresent(displayURL -> lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.displayurl", displayURL)));
if (selectedMod.getOwningFile() == null || selectedMod.getOwningFile().getMods().size() == 1)
lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.nochildmods"));
else
lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.childmods", selectedMod.getOwningFile().getMods().stream().map(IModInfo::getDisplayName).collect(Collectors.joining(","))));
if (vercheck.status == VersionChecker.Status.OUTDATED || vercheck.status == VersionChecker.Status.BETA_OUTDATED)
lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.updateavailable", vercheck.url == null ? "" : vercheck.url));
lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.license", selectedMod.getOwningFile().getLicense()));
lines.add(null);
lines.add(selectedMod.getDescription());
if ((vercheck.status == VersionChecker.Status.OUTDATED || vercheck.status == VersionChecker.Status.BETA_OUTDATED) && vercheck.changes.size() > 0) {
lines.add(null);
lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.changelogheader"));
for (Entry<ComparableVersion, String> entry : vercheck.changes.entrySet()) {
lines.add(" " + entry.getKey() + ":");
lines.add(entry.getValue());
lines.add(null);
}
}
modInfo.setInfo(lines, logoData.getLeft(), logoData.getRight());
}
use of net.minecraftforge.fml.loading.moddiscovery.ModInfo in project LoliServer by Loli-Server.
the class ModListScreen method init.
@Override
public void init() {
for (ModInfo mod : mods) {
listWidth = Math.max(listWidth, getFontRenderer().width(mod.getDisplayName()) + 10);
listWidth = Math.max(listWidth, getFontRenderer().width(MavenVersionStringHelper.artifactVersionToString(mod.getVersion())) + 5);
}
listWidth = Math.max(Math.min(listWidth, width / 3), 100);
listWidth += listWidth % numButtons != 0 ? (numButtons - listWidth % numButtons) : 0;
int modInfoWidth = this.width - this.listWidth - (PADDING * 3);
int doneButtonWidth = Math.min(modInfoWidth, 200);
int y = this.height - 20 - PADDING;
this.addButton(new Button(((listWidth + PADDING + this.width - doneButtonWidth) / 2), y, doneButtonWidth, 20, new TranslationTextComponent("gui.done"), b -> ModListScreen.this.onClose()));
this.addButton(this.openModsFolderButton = new Button(6, y, this.listWidth, 20, new TranslationTextComponent("fml.menu.mods.openmodsfolder"), b -> Util.getPlatform().openFile(FMLPaths.MODSDIR.get().toFile())));
y -= 20 + PADDING;
this.addButton(this.configButton = new Button(6, y, this.listWidth, 20, new TranslationTextComponent("fml.menu.mods.config"), b -> ModListScreen.this.displayModConfig()));
this.configButton.active = false;
y -= 14 + PADDING + 1;
search = new TextFieldWidget(getFontRenderer(), PADDING + 1, y, listWidth - 2, 14, new TranslationTextComponent("fml.menu.mods.search"));
int fullButtonHeight = PADDING + 20 + PADDING;
this.modList = new ModListWidget(this, listWidth, fullButtonHeight, search.y - getFontRenderer().lineHeight - PADDING);
this.modList.setLeftPos(6);
this.modInfo = new InfoPanel(this.minecraft, modInfoWidth, this.height - PADDING - fullButtonHeight, PADDING);
children.add(search);
children.add(modList);
children.add(modInfo);
search.setFocus(false);
search.setCanLoseFocus(true);
final int width = listWidth / numButtons;
int x = PADDING;
addButton(SortType.NORMAL.button = new Button(x, PADDING, width - buttonMargin, 20, SortType.NORMAL.getButtonText(), b -> resortMods(SortType.NORMAL)));
x += width + buttonMargin;
addButton(SortType.A_TO_Z.button = new Button(x, PADDING, width - buttonMargin, 20, SortType.A_TO_Z.getButtonText(), b -> resortMods(SortType.A_TO_Z)));
x += width + buttonMargin;
addButton(SortType.Z_TO_A.button = new Button(x, PADDING, width - buttonMargin, 20, SortType.Z_TO_A.getButtonText(), b -> resortMods(SortType.Z_TO_A)));
resortMods(SortType.NORMAL);
updateCache();
}
use of net.minecraftforge.fml.loading.moddiscovery.ModInfo in project Catalogue by MrCrayfish.
the class CatalogueModListScreen method loadAndCacheLogo.
private void loadAndCacheLogo(IModInfo info) {
if (LOGO_CACHE.containsKey(info.getModId()))
return;
// Fills an empty logo as logo may not be present
LOGO_CACHE.put(info.getModId(), Pair.of(null, new Size2i(0, 0)));
// Attempts to load the real logo
ModInfo modInfo = (ModInfo) info;
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)) {
TextureManager textureManager = this.getMinecraft().getTextureManager();
LOGO_CACHE.put(info.getModId(), Pair.of(textureManager.register("modlogo", this.createLogoTexture(logo, modInfo.getLogoBlur())), new Size2i(logo.getWidth(), logo.getHeight())));
} catch (IOException ignored) {
}
});
}
Aggregations