[Feature] Updater Icons from Entrypoints
This commit is contained in:
parent
bcd64b87b7
commit
dca9817c17
9 changed files with 86 additions and 11 deletions
|
@ -1,11 +1,16 @@
|
||||||
package org.betterx.bclib.client.gui.screens;
|
package org.betterx.bclib.client.gui.screens;
|
||||||
|
|
||||||
|
import org.betterx.bclib.BCLib;
|
||||||
import org.betterx.bclib.config.Configs;
|
import org.betterx.bclib.config.Configs;
|
||||||
|
import org.betterx.bclib.entrypoints.EntrypointUtil;
|
||||||
|
import org.betterx.bclib.networking.VersionCheckEntryPoint;
|
||||||
import org.betterx.bclib.networking.VersionChecker;
|
import org.betterx.bclib.networking.VersionChecker;
|
||||||
import org.betterx.ui.ColorUtil;
|
import org.betterx.ui.ColorUtil;
|
||||||
import org.betterx.ui.layout.components.HorizontalStack;
|
import org.betterx.ui.layout.components.HorizontalStack;
|
||||||
import org.betterx.ui.layout.components.LayoutComponent;
|
import org.betterx.ui.layout.components.LayoutComponent;
|
||||||
import org.betterx.ui.layout.components.VerticalStack;
|
import org.betterx.ui.layout.components.VerticalStack;
|
||||||
|
import org.betterx.ui.layout.values.Size;
|
||||||
|
import org.betterx.ui.layout.values.Value;
|
||||||
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
import net.minecraft.client.gui.GuiComponent;
|
import net.minecraft.client.gui.GuiComponent;
|
||||||
|
@ -13,6 +18,7 @@ import net.minecraft.client.gui.screens.Screen;
|
||||||
import net.minecraft.network.chat.CommonComponents;
|
import net.minecraft.network.chat.CommonComponents;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.network.chat.Style;
|
import net.minecraft.network.chat.Style;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
|
||||||
import net.fabricmc.api.EnvType;
|
import net.fabricmc.api.EnvType;
|
||||||
import net.fabricmc.api.Environment;
|
import net.fabricmc.api.Environment;
|
||||||
|
@ -27,6 +33,18 @@ public class UpdatesScreen extends BCLibLayoutScreen {
|
||||||
super(parent, Component.translatable("bclib.updates.title"), 10, 10, 10);
|
super(parent, Component.translatable("bclib.updates.title"), 10, 10, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ResourceLocation getUpdaterIcon(String modID) {
|
||||||
|
if (modID.equals(BCLib.MOD_ID)) {
|
||||||
|
return BCLibLayoutScreen.BCLIB_LOGO_LOCATION;
|
||||||
|
}
|
||||||
|
return EntrypointUtil.getCommon(VersionCheckEntryPoint.class)
|
||||||
|
.stream()
|
||||||
|
.map(vc -> vc.updaterIcon(modID))
|
||||||
|
.filter(r -> r != null)
|
||||||
|
.findAny()
|
||||||
|
.orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected LayoutComponent<?, ?> initContent() {
|
protected LayoutComponent<?, ?> initContent() {
|
||||||
VerticalStack rows = new VerticalStack(relative(1), fit()).centerHorizontal();
|
VerticalStack rows = new VerticalStack(relative(1), fit()).centerHorizontal();
|
||||||
|
@ -37,8 +55,14 @@ public class UpdatesScreen extends BCLibLayoutScreen {
|
||||||
|
|
||||||
VersionChecker.forEachUpdate((mod, cur, updated) -> {
|
VersionChecker.forEachUpdate((mod, cur, updated) -> {
|
||||||
ModContainer nfo = FabricLoader.getInstance().getModContainer(mod).orElse(null);
|
ModContainer nfo = FabricLoader.getInstance().getModContainer(mod).orElse(null);
|
||||||
|
ResourceLocation icon = getUpdaterIcon(mod);
|
||||||
HorizontalStack row = rows.addRow(relative(0.8), fit()).centerHorizontal();
|
HorizontalStack row = rows.addRow(fixed(320), fit()).centerHorizontal();
|
||||||
|
if (icon != null) {
|
||||||
|
row.addImage(Value.fit(), Value.fit(), icon, Size.of(32));
|
||||||
|
row.addSpacer(4);
|
||||||
|
} else {
|
||||||
|
row.addSpacer(36);
|
||||||
|
}
|
||||||
if (nfo != null) {
|
if (nfo != null) {
|
||||||
row.addText(fit(), fit(), Component.literal(nfo.getMetadata().getName()))
|
row.addText(fit(), fit(), Component.literal(nfo.getMetadata().getName()))
|
||||||
.setColor(ColorUtil.WHITE);
|
.setColor(ColorUtil.WHITE);
|
||||||
|
@ -54,7 +78,7 @@ public class UpdatesScreen extends BCLibLayoutScreen {
|
||||||
row.addButton(fit(), fit(), Component.translatable("bclib.updates.curseforge_link"))
|
row.addButton(fit(), fit(), Component.translatable("bclib.updates.curseforge_link"))
|
||||||
.onPress((bt) -> {
|
.onPress((bt) -> {
|
||||||
this.openLink(nfo.getMetadata().getContact().get("homepage").get());
|
this.openLink(nfo.getMetadata().getContact().get("homepage").get());
|
||||||
});
|
}).centerVertical();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,7 @@ public class WelcomeScreen extends BCLibLayoutScreen {
|
||||||
Checkbox check = innerContent.addCheckbox(
|
Checkbox check = innerContent.addCheckbox(
|
||||||
fit(),
|
fit(),
|
||||||
fit(),
|
fit(),
|
||||||
translatable("title.config.bclib.client.ui.check"),
|
translatable("title.config.bclib.client.version.check"),
|
||||||
Configs.CLIENT_CONFIG.checkVersions()
|
Configs.CLIENT_CONFIG.checkVersions()
|
||||||
)
|
)
|
||||||
.onChange((cb, state) -> {
|
.onChange((cb, state) -> {
|
||||||
|
@ -80,7 +80,7 @@ public class WelcomeScreen extends BCLibLayoutScreen {
|
||||||
});
|
});
|
||||||
innerContent.addSpacer(2);
|
innerContent.addSpacer(2);
|
||||||
HorizontalStack dscBox = innerContent.indent(24);
|
HorizontalStack dscBox = innerContent.indent(24);
|
||||||
dscBox.addMultilineText(fill(), fit(), translatable("description.config.bclib.client.ui.check"))
|
dscBox.addMultilineText(fill(), fit(), translatable("description.config.bclib.client.version.check"))
|
||||||
.setColor(ColorUtil.GRAY);
|
.setColor(ColorUtil.GRAY);
|
||||||
dscBox.addSpacer(8);
|
dscBox.addSpacer(8);
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
package org.betterx.bclib.entrypoints;
|
||||||
|
|
||||||
|
public interface BCLibEntryPoint {
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
package org.betterx.bclib.entrypoints;
|
||||||
|
|
||||||
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
|
|
||||||
|
@ApiStatus.Internal
|
||||||
|
public class EntrypointUtil {
|
||||||
|
private static <T extends BCLibEntryPoint> List<T> getEntryPoints(boolean client, Class<T> select) {
|
||||||
|
return FabricLoader.getInstance()
|
||||||
|
.getEntrypoints(
|
||||||
|
client ? "bclib_client" : "bclib",
|
||||||
|
BCLibEntryPoint.class
|
||||||
|
)
|
||||||
|
.stream()
|
||||||
|
.filter(o -> select.isAssignableFrom(o.getClass()))
|
||||||
|
.map(e -> (T) e)
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiStatus.Internal
|
||||||
|
public static <T extends BCLibEntryPoint> List<T> getCommon(Class<T> select) {
|
||||||
|
return getEntryPoints(false, select);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiStatus.Internal
|
||||||
|
public static <T extends BCLibEntryPoint> List<T> getClient(Class<T> select) {
|
||||||
|
return getEntryPoints(true, select);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
package org.betterx.bclib.networking;
|
||||||
|
|
||||||
|
import org.betterx.bclib.entrypoints.BCLibEntryPoint;
|
||||||
|
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
|
||||||
|
public interface VersionCheckEntryPoint extends BCLibEntryPoint {
|
||||||
|
ResourceLocation updaterIcon(String modID);
|
||||||
|
}
|
|
@ -4,6 +4,8 @@ import org.betterx.bclib.BCLib;
|
||||||
import org.betterx.bclib.config.Configs;
|
import org.betterx.bclib.config.Configs;
|
||||||
import org.betterx.worlds.together.util.ModUtil;
|
import org.betterx.worlds.together.util.ModUtil;
|
||||||
|
|
||||||
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -123,6 +125,10 @@ public class VersionChecker implements Runnable {
|
||||||
BCLib.LOGGER.info("Received Version Info for minecraft=" + json.mc + ", loader=" + json.loader);
|
BCLib.LOGGER.info("Received Version Info for minecraft=" + json.mc + ", loader=" + json.loader);
|
||||||
if (json.mods != null) {
|
if (json.mods != null) {
|
||||||
for (ModVersion mod : json.mods) {
|
for (ModVersion mod : json.mods) {
|
||||||
|
if (!KNOWN_MODS.contains(mod.n)) {
|
||||||
|
if (FabricLoader.getInstance().getModContainer(mod.n).isPresent())
|
||||||
|
registerMod(mod.n);
|
||||||
|
}
|
||||||
if (mod.n != null && mod.v != null && KNOWN_MODS.contains(mod.n)) {
|
if (mod.n != null && mod.v != null && KNOWN_MODS.contains(mod.n)) {
|
||||||
boolean isNew = ModUtil.isLargerVersion(mod.v, ModUtil.getModVersion(mod.n));
|
boolean isNew = ModUtil.isLargerVersion(mod.v, ModUtil.getModVersion(mod.n));
|
||||||
BCLib.LOGGER.info(" - " + mod.n + ":" + mod.v + (isNew ? " (update available)" : ""));
|
BCLib.LOGGER.info(" - " + mod.n + ":" + mod.v + (isNew ? " (update available)" : ""));
|
||||||
|
|
|
@ -19,10 +19,12 @@ public class EntrypointUtil {
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiStatus.Internal
|
||||||
public static <T extends WorldsTogetherEntrypoint> List<T> getCommon(Class<T> select) {
|
public static <T extends WorldsTogetherEntrypoint> List<T> getCommon(Class<T> select) {
|
||||||
return getEntryPoints(false, select);
|
return getEntryPoints(false, select);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiStatus.Internal
|
||||||
public static <T extends WorldsTogetherEntrypoint> List<T> getClient(Class<T> select) {
|
public static <T extends WorldsTogetherEntrypoint> List<T> getClient(Class<T> select) {
|
||||||
return getEntryPoints(true, select);
|
return getEntryPoints(true, select);
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,14 +74,13 @@
|
||||||
"bclib.updates.description": "Einige der installierten Mods sind veraltet. Wir verbessern und erweitern ständig unseren Inhalt und stellen wichtige Fehlerbehebungen zur Verfügung.\nBitte aktualisiere Deine Mods über die unten angegebenen Links.",
|
"bclib.updates.description": "Einige der installierten Mods sind veraltet. Wir verbessern und erweitern ständig unseren Inhalt und stellen wichtige Fehlerbehebungen zur Verfügung.\nBitte aktualisiere Deine Mods über die unten angegebenen Links.",
|
||||||
"bclib.welcome.title": "Wilkommen bei ",
|
"bclib.welcome.title": "Wilkommen bei ",
|
||||||
"bclib.welcome.description": "... und ein riesiges herzliches **Dankeschön** für das Herunterladen und Spielen unserer Mods. Wir hoffen, dass sie euch genauso viel Spaß machen wie uns.\n\nBevor wir anfangen, gibt es ein paar Dinge, die wir einrichten müssen, also lest bitte den folgenden langweiligen Teil weiter.",
|
"bclib.welcome.description": "... und ein riesiges herzliches **Dankeschön** für das Herunterladen und Spielen unserer Mods. Wir hoffen, dass sie euch genauso viel Spaß machen wie uns.\n\nBevor wir anfangen, gibt es ein paar Dinge, die wir einrichten müssen, also lest bitte den folgenden langweiligen Teil weiter.",
|
||||||
"bclib.welcome.donation": "Wenn Dir unsere Mods so gut gefallen, wie wir hoffen, dann denken Sie bitte über eine kleine Spende nach :)",
|
"bclib.welcome.donation": "Wenn Dir unsere Mods so gut gefallen, wie wir hoffen, dann denke bitte über eine kleine Spende nach :)",
|
||||||
"description.config.bclib.client.ui.check": "BCLib enthält eine einfache Versionsüberprüfung, die Dich benachrichtigen kann, wenn neue Updates unserer Mods verfügbar sind. Dazu müssen wir eine Ressource von einem unserer Webserver abrufen. Um die Anfrage zu bearbeiten versenden wir zusammen mit Deiner IP-Address (wir müssen ja wissen wohin die Antwort gehen soll) auch Deine Minecraft-Version (damit wir die richtige Mod-Version auswählen können). Die übertragenen Daten werden von uns niemals für andere Zwecke verwendet, verarbeitet oder weitergegeben, müssen aber aus rechtlichen Gründen für 4 Wochen in unseren Log-Dateien gespeichert werden.",
|
"description.config.bclib.client.version.check": "BCLib enthält eine einfache Versionsüberprüfung, die Dich benachrichtigen kann, wenn neue Updates unserer Mods verfügbar sind. Dazu müssen wir eine Ressource von einem unserer Webserver abrufen. Um die Anfrage zu bearbeiten versenden wir zusammen mit Deiner IP-Address (wir müssen ja wissen wohin die Antwort gehen soll) auch Deine Minecraft-Version (damit wir die richtige Mod-Version auswählen können). Die übertragenen Daten werden von uns niemals für andere Zwecke verwendet, verarbeitet oder weitergegeben, müssen aber aus rechtlichen Gründen für 4 Wochen in unseren Log-Dateien gespeichert werden.",
|
||||||
"title.config.bclib.client.client.ui.check": "Versionsprüfung erlauben",
|
"title.config.bclib.client.version.check": "Versionsprüfung erlauben",
|
||||||
"title.config.bclib.client.ui.showUpdateInfo": "Anzeigen wenn neue Updates verfügabr sind",
|
"title.config.bclib.client.ui.showUpdateInfo": "Anzeigen wenn neue Updates verfügabr sind",
|
||||||
"title.config.bclib.client.rendering.FogDensity": "Nebeldichte",
|
"title.config.bclib.client.rendering.FogDensity": "Nebeldichte",
|
||||||
"description.config.bclib.client.ui.suppressExperimentalDialogOnLoad": "Der Warnbildschirm wird immer dann angezeigt, wenn Deine Welt nicht die Einstellungen der Vanilla-Version verwendet. Dies kann passieren, wenn Du eine Welt in einer Vorschauversion startest, aber auch wenn Du Mods verwendest, um die Welterzeugung zu verändern. Wenn diese Option aktiviert ist, wird die Warnung übersprungen, wenn Du eine bestehende Welt lädst. Sie wird weiterhin angezeigt (als Erinnerung), wenn eine neue Welt erstellt wird.",
|
"description.config.bclib.client.ui.suppressExperimentalDialogOnLoad": "Der Warnbildschirm wird immer dann angezeigt, wenn Deine Welt nicht die Einstellungen der Vanilla-Version verwendet. Dies kann passieren, wenn Du eine Welt in einer Vorschauversion startest, aber auch wenn Du Mods verwendest, um die Welterzeugung zu verändern. Wenn diese Option aktiviert ist, wird die Warnung übersprungen, wenn Du eine bestehende Welt lädst. Sie wird weiterhin angezeigt (als Erinnerung), wenn eine neue Welt erstellt wird.",
|
||||||
"title.config.bclib.client.ui.forceBetterXPreset": "BetterX als Standard-Welt-Typ verwenden",
|
"title.config.bclib.client.ui.forceBetterXPreset": "BetterX als Standard-Welt-Typ verwenden",
|
||||||
"description.config.bclib.client.ui.forceBetterXPreset": "Der Welt-Typ bestimmt, wie eine Welt generiert wird. In den meisten Fällen solltet BetterX als Standardeinstellung beibehalten werden (Du kannst den Typ jederzeit im Welt-Erstellen-Bildschirm ändern). Dieser Typ ist für maximale Kompatibilität zwischen DataPacks, unserer Mod und anderen Fabric-Mods optimiert. Außerdem bietet er einige einzigartige Funktionen für BetterNether und BetterEnd. Du solltest diese Option nur deaktivieren, wenn Du einen Grund dazu hast!",
|
"description.config.bclib.client.ui.forceBetterXPreset": "Der Welt-Typ bestimmt, wie eine Welt generiert wird. In den meisten Fällen solltet BetterX als Standardeinstellung beibehalten werden (Du kannst den Typ jederzeit im Welt-Erstellen-Bildschirm ändern). Dieser Typ ist für maximale Kompatibilität zwischen DataPacks, unserer Mod und anderen Fabric-Mods optimiert. Außerdem bietet er einige einzigartige Funktionen für BetterNether und BetterEnd. Du solltest diese Option nur deaktivieren, wenn Du einen Grund dazu hast!",
|
||||||
"title.config.bclib.client.ui.check": "Enable Version Check",
|
|
||||||
"warning.config.bclib.client.ui.forceBetterXPreset": "IN DEN MEISTEN FÄLLEN SOLLTE DIESE OPTION AKTIVIERT BLEIBEN.\n"
|
"warning.config.bclib.client.ui.forceBetterXPreset": "IN DEN MEISTEN FÄLLEN SOLLTE DIESE OPTION AKTIVIERT BLEIBEN.\n"
|
||||||
}
|
}
|
|
@ -75,8 +75,8 @@
|
||||||
"bclib.welcome.title": "Welcome to ",
|
"bclib.welcome.title": "Welcome to ",
|
||||||
"bclib.welcome.description": "... and a huge hearty **thank you** for downloading and playing our mods. We hope you enjoy them as much as we do.\n\nBefore we start, there are a few things we need to set up, so please continue reading the following boring part.",
|
"bclib.welcome.description": "... and a huge hearty **thank you** for downloading and playing our mods. We hope you enjoy them as much as we do.\n\nBefore we start, there are a few things we need to set up, so please continue reading the following boring part.",
|
||||||
"bclib.welcome.donation": "If you enjoy our Mods as much as we hope you do, please consider a small Donation :)",
|
"bclib.welcome.donation": "If you enjoy our Mods as much as we hope you do, please consider a small Donation :)",
|
||||||
"description.config.bclib.client.ui.check": "BCLib includes a simple version checker that can notify you when new updates of our mods are available. To do this, we need to read a resource from one of our web servers. To process the request, together with your IP address (we need to know where to send the response) we also send your Minecraft version (so we can choose the right mod version). The transmitted data will never be used or processed by us for other purposes, but must be stored in our log files for 4 weeks for legal reasons.",
|
"description.config.bclib.client.version.check": "BCLib includes a simple version checker that can notify you when new updates of our mods are available. To do this, we need to read a resource from one of our web servers. To process the request, together with your IP address (we need to know where to send the response) we also send your Minecraft version (so we can choose the right mod version). The transmitted data will never be used or processed by us for other purposes, but must be stored in our log files for 4 weeks for legal reasons.",
|
||||||
"title.config.bclib.client.ui.check": "Enable Version Check",
|
"title.config.bclib.client.version.check": "Enable Version Check",
|
||||||
"title.config.bclib.client.ui.showUpdateInfo": "Allow Update Reminder Screen",
|
"title.config.bclib.client.ui.showUpdateInfo": "Allow Update Reminder Screen",
|
||||||
"title.config.bclib.client.rendering.FogDensity": "Fog Density",
|
"title.config.bclib.client.rendering.FogDensity": "Fog Density",
|
||||||
"description.config.bclib.client.ui.suppressExperimentalDialogOnLoad": "The warning screen appears whenever your world does not use the vanilla version settings. This can happen when you start a world in a preview version, but also when you use mods to change the world creation. If this option is enabled, the warning will be skipped when you load an existing world. It will still be displayed (as a reminder) when a new world is created.",
|
"description.config.bclib.client.ui.suppressExperimentalDialogOnLoad": "The warning screen appears whenever your world does not use the vanilla version settings. This can happen when you start a world in a preview version, but also when you use mods to change the world creation. If this option is enabled, the warning will be skipped when you load an existing world. It will still be displayed (as a reminder) when a new world is created.",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue