use of net.minecraftforge.fml.ModContainer in project MinecraftForge by MinecraftForge.
the class ModListScreen method updateCache.
private void updateCache() {
if (selected == null) {
this.configButton.active = false;
this.modInfo.clearInfo();
return;
}
IModInfo 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 PathResourcePack resourcePack = ResourcePackLoader.getPackFor(selectedMod.getModId()).orElse(ResourcePackLoader.getPackFor("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.getConfig().getConfigElement("credits").ifPresent(credits -> lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.credits", credits)));
selectedMod.getConfig().getConfigElement("authors").ifPresent(authors -> lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.authors", authors)));
selectedMod.getConfig().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());
}
Aggregations