From 9a341209f1fa3db529a3e063f585047e4b5bcfac Mon Sep 17 00:00:00 2001 From: SettingDust Date: Sat, 11 Jun 2022 22:48:30 +0800 Subject: [PATCH 1/5] feat(deps): support for 1.18.2 --- build.gradle | 18 ++++++++--- gradle.properties | 12 +++---- .../thatorthis/gui/ChoiceScreen.java | 4 +-- .../thatorthis/internal/ModInjector.java | 31 +++++++++++-------- ...ThatOrThisDirectoryModCandidateFinder.java | 13 +++++--- .../ThatOrThisLoadedModCandidateFinder.java | 2 +- src/main/resources/fabric.mod.json | 6 ++-- 7 files changed, 52 insertions(+), 34 deletions(-) diff --git a/build.gradle b/build.gradle index cc630c6..b57bf96 100755 --- a/build.gradle +++ b/build.gradle @@ -1,15 +1,23 @@ plugins { - id 'fabric-loom' version '0.9-SNAPSHOT' + id 'fabric-loom' version '0.12-SNAPSHOT' id 'maven-publish' } -sourceCompatibility = JavaVersion.VERSION_16 -targetCompatibility = JavaVersion.VERSION_16 +sourceCompatibility = JavaVersion.VERSION_17 +targetCompatibility = JavaVersion.VERSION_17 archivesBaseName = project.archives_base_name version = project.mod_version group = project.maven_group +loom { + mods { + thatorthis { + sourceSet sourceSets.main + } + } +} + repositories { // Add repositories to retrieve artifacts from in here. // You should only use this when depending on other mods because @@ -51,8 +59,8 @@ tasks.withType(JavaCompile).configureEach { // If Javadoc is generated, this must be specified in that task too. it.options.encoding = "UTF-8" - // Minecraft 1.17 (21w19a) upwards uses Java 16. - it.options.release = 16 + // Minecraft 1.18 upwards uses Java 17. + it.options.release = 17 } java { diff --git a/gradle.properties b/gradle.properties index d13ccce..1de1ac5 100755 --- a/gradle.properties +++ b/gradle.properties @@ -3,16 +3,16 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/versions.html - minecraft_version=1.17.1 - yarn_mappings=1.17.1+build.63 - loader_version=0.12.3 + minecraft_version=1.18.2 + yarn_mappings=1.18.2+build.3 + loader_version=0.14.7 # Mod Properties - mod_version = 0.2.6+1.17 + mod_version = 0.2.6+1.18 maven_group = io.github.ezforever archives_base_name = thatorthis # Dependencies #fabric_version=0.41.0+1.17 - modmenu_version=2.0.14 - gson_version=2.8.0 + modmenu_version=3.2.2 + gson_version=2.9.0 diff --git a/src/main/java/io/github/ezforever/thatorthis/gui/ChoiceScreen.java b/src/main/java/io/github/ezforever/thatorthis/gui/ChoiceScreen.java index 13bc0c4..2072cf8 100755 --- a/src/main/java/io/github/ezforever/thatorthis/gui/ChoiceScreen.java +++ b/src/main/java/io/github/ezforever/thatorthis/gui/ChoiceScreen.java @@ -155,12 +155,12 @@ public void setLocked(boolean locked) { disableButton.active = ruleHolder.canDisable(); addDrawableChild(disableButton); - doneButton = new ButtonWidget(width / 2 - 155 + 160, height - 27, 150, 20, Texts.DONE.get(), (ButtonWidget button) -> onClose()); + doneButton = new ButtonWidget(width / 2 - 155 + 160, height - 27, 150, 20, Texts.DONE.get(), (ButtonWidget button) -> close()); addDrawableChild(doneButton); } @Override - public void onClose() { + public void close() { Screen nextScreen; if(dirty) { setDirty(false); diff --git a/src/main/java/io/github/ezforever/thatorthis/internal/ModInjector.java b/src/main/java/io/github/ezforever/thatorthis/internal/ModInjector.java index ef804f6..05eab06 100755 --- a/src/main/java/io/github/ezforever/thatorthis/internal/ModInjector.java +++ b/src/main/java/io/github/ezforever/thatorthis/internal/ModInjector.java @@ -5,6 +5,8 @@ import net.fabricmc.loader.impl.ModContainerImpl; import net.fabricmc.loader.impl.discovery.*; import net.fabricmc.loader.impl.gui.FabricGuiEntry; +import net.fabricmc.loader.impl.metadata.DependencyOverrides; +import net.fabricmc.loader.impl.metadata.VersionOverrides; import net.fabricmc.loader.impl.util.SystemProperties; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -20,6 +22,8 @@ public class ModInjector { private final Map> modDirs; private List mods; + private ModDiscoverer discoverer; + private Map> envDisabledMods = new HashMap<>(); public ModInjector(Map> modDirs) { this.modDirs = Collections.unmodifiableMap(modDirs); @@ -62,21 +66,21 @@ private void trigger() { } private Collection discover() { - ModDiscoverer discoverer = new ModDiscoverer(); + this.discoverer = new ModDiscoverer(new VersionOverrides(), new DependencyOverrides(Util.loader.getConfigDir())); // Include loaded mods for resolving dependencies discoverer.addCandidateFinder(new ThatOrThisLoadedModCandidateFinder(this.mods)); this.modDirs.forEach((String modDir, Set blacklist) -> { Path path = Util.getModsDir().resolve(modDir); - if(Files.exists(path) && Files.isDirectory(path)) { + if (Files.exists(path) && Files.isDirectory(path)) { DirectoryModCandidateFinder finder; - if(blacklist == null) { + if (blacklist == null) { finder = new DirectoryModCandidateFinder(path, Util.loader.isDevelopmentEnvironment()); } else { finder = new ThatOrThisDirectoryModCandidateFinder(path, Util.loader.isDevelopmentEnvironment(), (ModCandidate candidate) -> { boolean blacklisted = blacklist.contains(candidate.getId()); - if(blacklisted) + if (blacklisted) LOGGER.debug("Skipping mod {} as per user request", candidate.getId()); return !blacklisted; }); @@ -88,7 +92,8 @@ private Collection discover() { }); try { - return discoverer.discoverMods(Util.loader); + envDisabledMods = new HashMap<>(); + return discoverer.discoverMods(Util.loader, envDisabledMods); } catch (ModResolutionException e) { FabricGuiEntry.displayCriticalError(e, true); return null; // Never reached @@ -100,7 +105,7 @@ private Collection resolve(Collection candidates) { .map((ModContainerImpl container) -> container.getMetadata().getId()) .collect(Collectors.toSet()); try { - candidates = ModResolver.resolve(candidates, Util.loader.getEnvironmentType()).stream() + candidates = ModResolver.resolve(candidates, Util.loader.getEnvironmentType(), envDisabledMods).stream() .filter((ModCandidate candidate) -> !loadedMods.contains(candidate.getId())) .collect(Collectors.toList()); } catch (ModResolutionException e) { @@ -108,7 +113,7 @@ private Collection resolve(Collection candidates) { return null; // Never reached } - if(Util.loader.isDevelopmentEnvironment() && System.getProperty(SystemProperties.REMAP_CLASSPATH_FILE) != null) { + if (Util.loader.isDevelopmentEnvironment() && System.getProperty(SystemProperties.REMAP_CLASSPATH_FILE) != null) { Path cacheDir = Util.loader.getGameDir().resolve(FabricLoaderImpl.CACHE_DIR_NAME); RuntimeModRemapper.remap(candidates, cacheDir.resolve("tmp"), cacheDir.resolve("processedMods")); } @@ -119,13 +124,13 @@ private Collection resolve(Collection candidates) { } private void inject(Collection candidates) { - for(ModCandidate candidate : candidates) { + for (ModCandidate candidate : candidates) { try { Util.addModMethod.invoke(Util.loader, candidate); } catch (InvocationTargetException | IllegalAccessException e) { throw new RuntimeException("Failed to inject mod into Fabric Loader", e); } - Util.launcher.addToClassPath(candidate.getPath()); + candidate.getPaths().forEach(Util.launcher::addToClassPath); } } @@ -138,14 +143,14 @@ private void fixup(Collection candidates) { throw new RuntimeException("Failed to fix LanguageAdapter mods", e); } - for(ModCandidate candidate : candidates) { + for (ModCandidate candidate : candidates) { Map definitions = candidate.getMetadata().getLanguageAdapterDefinitions(); - if(definitions.isEmpty()) + if (definitions.isEmpty()) continue; LOGGER.warn("LanguageAdapter found in mod {}! Trying to fix", candidate.getId()); - for(Map.Entry entry : definitions.entrySet()) { - if(adapterMap.containsKey(entry.getKey())) + for (Map.Entry entry : definitions.entrySet()) { + if (adapterMap.containsKey(entry.getKey())) throw new RuntimeException("Duplicate language adapter key: " + entry.getKey() + "! (" + entry.getValue() + ", " + adapterMap.get(entry.getKey()).getClass().getName() + ")"); LanguageAdapter adapter; diff --git a/src/main/java/net/fabricmc/loader/impl/discovery/ThatOrThisDirectoryModCandidateFinder.java b/src/main/java/net/fabricmc/loader/impl/discovery/ThatOrThisDirectoryModCandidateFinder.java index 81c65da..beb58e2 100755 --- a/src/main/java/net/fabricmc/loader/impl/discovery/ThatOrThisDirectoryModCandidateFinder.java +++ b/src/main/java/net/fabricmc/loader/impl/discovery/ThatOrThisDirectoryModCandidateFinder.java @@ -1,23 +1,28 @@ package net.fabricmc.loader.impl.discovery; +import net.fabricmc.loader.api.FabricLoader; +import net.fabricmc.loader.impl.metadata.DependencyOverrides; +import net.fabricmc.loader.impl.metadata.VersionOverrides; + import java.nio.file.Path; import java.util.function.Predicate; public class ThatOrThisDirectoryModCandidateFinder extends DirectoryModCandidateFinder { - private static final ModDiscoverer DUMMY_DISCOVERER = new ModDiscoverer(); + private final ModDiscoverer discoverer; private final Predicate predicate; public ThatOrThisDirectoryModCandidateFinder(Path path, boolean requiresRemap, Predicate predicate) { super(path, requiresRemap); this.predicate = predicate; + this.discoverer = new ModDiscoverer(new VersionOverrides(), new DependencyOverrides(FabricLoader.getInstance().getConfigDir())); } @Override public void findCandidates(ModCandidateConsumer out) { - super.findCandidates((Path path, boolean requiresRemap) -> { - ModCandidate candidate = DUMMY_DISCOVERER.new ModScanTask(path, requiresRemap).compute(); - if(predicate.test(candidate)) + super.findCandidates((final var path, final var requiresRemap) -> { + ModCandidate candidate = discoverer.new ModScanTask(path, requiresRemap).compute(); + if (predicate.test(candidate)) out.accept(path, requiresRemap); }); } diff --git a/src/main/java/net/fabricmc/loader/impl/discovery/ThatOrThisLoadedModCandidateFinder.java b/src/main/java/net/fabricmc/loader/impl/discovery/ThatOrThisLoadedModCandidateFinder.java index e6d051a..6cecad3 100755 --- a/src/main/java/net/fabricmc/loader/impl/discovery/ThatOrThisLoadedModCandidateFinder.java +++ b/src/main/java/net/fabricmc/loader/impl/discovery/ThatOrThisLoadedModCandidateFinder.java @@ -16,7 +16,7 @@ public void findCandidates(ModCandidateConsumer out) { containers.forEach((ModContainerImpl container) -> { // Built-in mods are added in ModResolver#resolve if(!container.getMetadata().getType().equals("builtin")) - out.accept(container.getOriginPath(), false); + out.accept(container.getOrigin().getPaths(), false); }); } } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 456cb15..8d5f914 100755 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -27,11 +27,11 @@ ], "depends": { - "minecraft": "1.17.x", - "fabricloader": "0.12.x" + "minecraft": "1.18.x", + "fabricloader": "0.14.x" }, "recommends": { - "modmenu": ">=2.0.2" + "modmenu": ">=3.0.0" }, "breaks": { "modsmod": "*" From 227395d83de2b521325ecce460a421828756fc9c Mon Sep 17 00:00:00 2001 From: SettingDust Date: Wed, 15 Jun 2022 22:37:49 +0800 Subject: [PATCH 2/5] feat(core): support for 1.18.2 mod load changes --- build.gradle | 15 +------ gradle.properties | 1 - .../config/EnumClassTypeAdapter.java | 7 ++-- .../thatorthis/internal/BidirectionalMap.java | 39 +++++++++++++++++++ .../thatorthis/internal/ModInjector.java | 3 +- .../ThatOrThisLoadedModCandidateFinder.java | 3 +- 6 files changed, 47 insertions(+), 21 deletions(-) create mode 100644 src/main/java/io/github/ezforever/thatorthis/internal/BidirectionalMap.java diff --git a/build.gradle b/build.gradle index b57bf96..aec67c8 100755 --- a/build.gradle +++ b/build.gradle @@ -41,7 +41,6 @@ dependencies { // You may need to force-disable transitiveness on them. modImplementation "com.terraformersmc:modmenu:${project.modmenu_version}" - implementation "com.google.code.gson:gson:${project.gson_version}" } processResources { @@ -70,23 +69,11 @@ java { withSourcesJar() } -jar { - from("LICENSE") { - rename { "${it}_${project.archivesBaseName}"} - } -} - // configure the maven publication publishing { publications { mavenJava(MavenPublication) { - // add all the jars that should be included when publishing to maven - artifact(remapJar) { - builtBy remapJar - } - artifact(sourcesJar) { - builtBy remapSourcesJar - } + from components.java } } diff --git a/gradle.properties b/gradle.properties index 1de1ac5..7e3cdba 100755 --- a/gradle.properties +++ b/gradle.properties @@ -15,4 +15,3 @@ org.gradle.jvmargs=-Xmx1G # Dependencies #fabric_version=0.41.0+1.17 modmenu_version=3.2.2 - gson_version=2.9.0 diff --git a/src/main/java/io/github/ezforever/thatorthis/config/EnumClassTypeAdapter.java b/src/main/java/io/github/ezforever/thatorthis/config/EnumClassTypeAdapter.java index 996a43d..c30bc31 100755 --- a/src/main/java/io/github/ezforever/thatorthis/config/EnumClassTypeAdapter.java +++ b/src/main/java/io/github/ezforever/thatorthis/config/EnumClassTypeAdapter.java @@ -1,7 +1,5 @@ package io.github.ezforever.thatorthis.config; -import com.google.common.collect.BiMap; -import com.google.common.collect.HashBiMap; import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; @@ -9,6 +7,7 @@ import com.google.gson.JsonParseException; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; +import io.github.ezforever.thatorthis.internal.BidirectionalMap; import java.lang.reflect.Type; @@ -20,10 +19,10 @@ public class EnumClassTypeAdapter // --- - private final BiMap> nameClassMap; + private final BidirectionalMap> nameClassMap; public & EnumClassType> EnumClassTypeAdapter(Class classOfU) { - this.nameClassMap = HashBiMap.create(); + this.nameClassMap = new BidirectionalMap<>(); for(U value : classOfU.getEnumConstants()) this.nameClassMap.put(value.name(), value.getClazz()); } diff --git a/src/main/java/io/github/ezforever/thatorthis/internal/BidirectionalMap.java b/src/main/java/io/github/ezforever/thatorthis/internal/BidirectionalMap.java new file mode 100644 index 0000000..04f7f67 --- /dev/null +++ b/src/main/java/io/github/ezforever/thatorthis/internal/BidirectionalMap.java @@ -0,0 +1,39 @@ +package io.github.ezforever.thatorthis.internal; + +import java.io.Serial; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; + +/** + * https://stackoverflow.com/a/54871433
+ * Fabric not allow use other packages when loading {@link net.fabricmc.loader.impl.launch.knot.KnotClassDelegate#isValidParentUrl(URL, String)} + */ +@SuppressWarnings("JavadocReference") +public class BidirectionalMap extends HashMap { + @Serial + private static final long serialVersionUID = 1L; + public HashMap inversedMap = new HashMap<>(); + + public Map inverse() { + return Map.copyOf(inversedMap); + } + + @Override + public V remove(Object key) { + V val = super.remove(key); + inversedMap.remove(val); + return val; + } + + @Override + public V get(Object key) { + return super.get(key); + } + + @Override + public V put(K key, V value) { + inversedMap.put(value, key); + return super.put(key, value); + } +} diff --git a/src/main/java/io/github/ezforever/thatorthis/internal/ModInjector.java b/src/main/java/io/github/ezforever/thatorthis/internal/ModInjector.java index 05eab06..95bca93 100755 --- a/src/main/java/io/github/ezforever/thatorthis/internal/ModInjector.java +++ b/src/main/java/io/github/ezforever/thatorthis/internal/ModInjector.java @@ -14,6 +14,7 @@ import java.lang.reflect.InvocationTargetException; import java.nio.file.Files; import java.nio.file.Path; +import java.text.MessageFormat; import java.util.*; import java.util.stream.Collectors; @@ -58,7 +59,7 @@ private void trigger() { }; LOGGER.info("[ThatOrThis] " + modText, candidates.size(), candidates.stream() - .map((ModCandidate candidate) -> String.format("\t- %s@%s", candidate.getId(), candidate.getVersion().getFriendlyString())) + .map((ModCandidate candidate) -> MessageFormat.format("\t- {0}@{1}", candidate.getId(), candidate.getVersion().getFriendlyString())) .collect(Collectors.joining("\n"))); this.inject(candidates); diff --git a/src/main/java/net/fabricmc/loader/impl/discovery/ThatOrThisLoadedModCandidateFinder.java b/src/main/java/net/fabricmc/loader/impl/discovery/ThatOrThisLoadedModCandidateFinder.java index 6cecad3..bcc8f5b 100755 --- a/src/main/java/net/fabricmc/loader/impl/discovery/ThatOrThisLoadedModCandidateFinder.java +++ b/src/main/java/net/fabricmc/loader/impl/discovery/ThatOrThisLoadedModCandidateFinder.java @@ -1,5 +1,6 @@ package net.fabricmc.loader.impl.discovery; +import net.fabricmc.loader.api.metadata.ModOrigin; import net.fabricmc.loader.impl.ModContainerImpl; import java.util.List; @@ -15,7 +16,7 @@ public ThatOrThisLoadedModCandidateFinder(List containers) { public void findCandidates(ModCandidateConsumer out) { containers.forEach((ModContainerImpl container) -> { // Built-in mods are added in ModResolver#resolve - if(!container.getMetadata().getType().equals("builtin")) + if (container.getOrigin().getKind().equals(ModOrigin.Kind.PATH)) out.accept(container.getOrigin().getPaths(), false); }); } From ac4cf9cefd301a1414cece5e98b75cf2922a3362 Mon Sep 17 00:00:00 2001 From: Norbiros Date: Mon, 22 May 2023 16:55:17 +0200 Subject: [PATCH 3/5] feat(core): Support 1.19.3 --- README.md | 2 +- gradle.properties | 12 +++++----- .../thatorthis/gui/ChoiceScreen.java | 22 +++++++++---------- .../thatorthis/gui/RuleButtonListWidget.java | 2 +- .../thatorthis/gui/RuleButtonWidget.java | 5 ++--- .../ezforever/thatorthis/gui/Texts.java | 13 +++++------ .../mixin/ModMenuButtonWidgetMixin.java | 12 ++++++---- .../ModMenuTexturedButtonWidgetMixin.java | 9 ++++---- src/main/resources/fabric.mod.json | 4 ++-- 9 files changed, 42 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index e7d700f..85ed171 100755 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ *A Fabric mod for choosing between sets of Fabric mods.* -This branch (`master`) is the active development branch for latest Minecraft (currently 1.17.1). +This branch (`master`) is the active development branch for latest Minecraft (currently 1.19.3). ## What is this diff --git a/gradle.properties b/gradle.properties index 7e3cdba..5835704 100755 --- a/gradle.properties +++ b/gradle.properties @@ -3,15 +3,15 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/versions.html - minecraft_version=1.18.2 - yarn_mappings=1.18.2+build.3 - loader_version=0.14.7 + minecraft_version=1.19.3 + yarn_mappings=1.19.3+build.5 + loader_version=0.14.19 # Mod Properties - mod_version = 0.2.6+1.18 + mod_version = 0.2.6+1.19 maven_group = io.github.ezforever archives_base_name = thatorthis # Dependencies - #fabric_version=0.41.0+1.17 - modmenu_version=3.2.2 + #fabric_version=0.87.1+1.19.3 + modmenu_version=5.0.2 diff --git a/src/main/java/io/github/ezforever/thatorthis/gui/ChoiceScreen.java b/src/main/java/io/github/ezforever/thatorthis/gui/ChoiceScreen.java index 2072cf8..d4bfeca 100755 --- a/src/main/java/io/github/ezforever/thatorthis/gui/ChoiceScreen.java +++ b/src/main/java/io/github/ezforever/thatorthis/gui/ChoiceScreen.java @@ -15,10 +15,9 @@ import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.gui.widget.LockButtonWidget; import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.text.LiteralText; import net.minecraft.text.MutableText; import net.minecraft.text.Text; -import net.minecraft.text.TranslatableText; +import net.minecraft.text.TranslatableTextContent; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -79,7 +78,6 @@ public static Screen create(Screen parent) { private RuleButtonListWidget ruleButtons; private ButtonWidget discardOrDefaultButton; private LockButtonWidget disableButton; - private ButtonWidget doneButton; private boolean dirty = false; public ChoiceScreen(Screen parent, @@ -117,16 +115,15 @@ protected void init() { ruleButtons.setChoices(shownChoices); addDrawableChild(ruleButtons); - discardOrDefaultButton = new ButtonWidget( - width / 2 - 155, height - 27, 150 - 20, 20, - LiteralText.EMPTY, - (ButtonWidget button) -> { + discardOrDefaultButton = ButtonWidget.builder(Text.empty(), (ButtonWidget button) -> { shownChoices = (dirty ? initialChoices.choices : ruleHolder.getDefaultChoices()).copy(); ruleButtons.setChoices(shownChoices); disableButton.setLocked(dirty && ruleHolder.canDisable() && initialChoices.disabled != null && initialChoices.disabled); setDirty(!dirty); - } - ); + }) + .position(width / 2 - 155, height - 27) + .size(150 - 20, 20) + .build(); setDirty(dirty); // Reset button caption addDrawableChild(discardOrDefaultButton); @@ -141,7 +138,7 @@ protected void init() { ) { @Override // Erase difficulty info in narration message protected MutableText getNarrationMessage() { - return new TranslatableText("gui.narrate.button", getMessage()); + return MutableText.of(new TranslatableTextContent("gui.narrate.button", getMessage())); } @Override // Sync "locked"/"disabled" status to the buttons list @@ -155,7 +152,10 @@ public void setLocked(boolean locked) { disableButton.active = ruleHolder.canDisable(); addDrawableChild(disableButton); - doneButton = new ButtonWidget(width / 2 - 155 + 160, height - 27, 150, 20, Texts.DONE.get(), (ButtonWidget button) -> close()); + ButtonWidget doneButton = ButtonWidget.builder(Texts.DONE.get(), (ButtonWidget button) -> close()) + .position(width / 2 - 155 + 160, height - 27) + .size(150, 20) + .build(); addDrawableChild(doneButton); } diff --git a/src/main/java/io/github/ezforever/thatorthis/gui/RuleButtonListWidget.java b/src/main/java/io/github/ezforever/thatorthis/gui/RuleButtonListWidget.java index f68987e..92b61e6 100755 --- a/src/main/java/io/github/ezforever/thatorthis/gui/RuleButtonListWidget.java +++ b/src/main/java/io/github/ezforever/thatorthis/gui/RuleButtonListWidget.java @@ -41,7 +41,7 @@ public List selectableChildren() { @Override public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { this.buttons.forEach((button) -> { - button.y = y; + button.setY(y); button.render(matrices, mouseX, mouseY, tickDelta); if(hovered && button.isHovered() && !button.isFocused()) RuleButtonListWidget.this.hoveredButton = button; diff --git a/src/main/java/io/github/ezforever/thatorthis/gui/RuleButtonWidget.java b/src/main/java/io/github/ezforever/thatorthis/gui/RuleButtonWidget.java index c354e2b..332ee53 100755 --- a/src/main/java/io/github/ezforever/thatorthis/gui/RuleButtonWidget.java +++ b/src/main/java/io/github/ezforever/thatorthis/gui/RuleButtonWidget.java @@ -5,7 +5,6 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.gui.widget.ButtonWidget; -import net.minecraft.text.LiteralText; import net.minecraft.text.Text; @Environment(EnvType.CLIENT) @@ -14,12 +13,12 @@ public class RuleButtonWidget extends ButtonWidget { private Choice choice; public RuleButtonWidget(int x, int y, int width, int height, VisibleRule rule, RuleButtonListWidget.UpdateAction updateAction) { - super(x, y, width, height, LiteralText.EMPTY, (ButtonWidget button) -> { + super(x, y, width, height, Text.empty(), (ButtonWidget button) -> { RuleButtonWidget self = (RuleButtonWidget)button; SingleThreadFuture newChoice = rule.updateChoice(self.choice) .then(self::setChoice); updateAction.onUpdate(rule, newChoice); - }); + }, null); this.rule = rule; rule.initButton(this); diff --git a/src/main/java/io/github/ezforever/thatorthis/gui/Texts.java b/src/main/java/io/github/ezforever/thatorthis/gui/Texts.java index 7a7d393..f18d82b 100755 --- a/src/main/java/io/github/ezforever/thatorthis/gui/Texts.java +++ b/src/main/java/io/github/ezforever/thatorthis/gui/Texts.java @@ -1,8 +1,7 @@ package io.github.ezforever.thatorthis.gui; -import net.minecraft.text.LiteralText; +import net.minecraft.text.MutableText; import net.minecraft.text.Text; -import net.minecraft.text.TranslatableText; public enum Texts { TITLE("thatorthis.choice.title"), @@ -41,23 +40,23 @@ public static Text getText(String keyOrLiteral, Object... params) { isKey = false; } return isKey - ? new TranslatableText(keyOrLiteral, params) - : new LiteralText(String.format(keyOrLiteral, params)); + ? Text.translatable(keyOrLiteral, params) + : Text.of(String.format(keyOrLiteral, params)); } // --- private final String key; - private TranslatableText text; + private MutableText text; public Text get() { if(text == null) - text = new TranslatableText(key); + text = Text.translatable(key); return text; } public Text get(Object... args) { - return new TranslatableText(key, args); + return Text.translatable(key, args); } Texts(String key) { diff --git a/src/main/java/io/github/ezforever/thatorthis/mixin/ModMenuButtonWidgetMixin.java b/src/main/java/io/github/ezforever/thatorthis/mixin/ModMenuButtonWidgetMixin.java index 19cfb4e..d39d5ef 100755 --- a/src/main/java/io/github/ezforever/thatorthis/mixin/ModMenuButtonWidgetMixin.java +++ b/src/main/java/io/github/ezforever/thatorthis/mixin/ModMenuButtonWidgetMixin.java @@ -18,16 +18,19 @@ @Environment(EnvType.CLIENT) @Mixin(ModMenuButtonWidget.class) public abstract class ModMenuButtonWidgetMixin extends ButtonWidget { - public ModMenuButtonWidgetMixin(int x, int y, int width, int height, Text message, PressAction onPress) { - super(x, y, width, height, message, onPress); + public ModMenuButtonWidgetMixin(int x, int y, int width, int height, Text message, PressAction onPress, NarrationSupplier narrationSupplier) { + super(x, y, width, height, message, onPress, narrationSupplier); } @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { + System.out.println("CLICKED"); if (super.mouseClicked(mouseX, mouseY, button)) return true; + System.out.println("CLICKED 2.0"); if(clicked(mouseX, mouseY) && button == 1) { + System.out.println("CLICK 3.0"); MinecraftClient minecraftClient = MinecraftClient.getInstance(); playDownSound(minecraftClient.getSoundManager()); minecraftClient.setScreen(ChoiceScreen.create(minecraftClient.currentScreen)); @@ -38,8 +41,9 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) { } @Override - public void renderTooltip(MatrixStack matrices, int mouseX, int mouseY) { - if(!active) + public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { + super.render(matrices, mouseX, mouseY, delta); + if (!active || !isHovered()) return; Optional.ofNullable(MinecraftClient.getInstance().currentScreen) .ifPresent((Screen currentScreen) -> Util.renderWarpedTooltip(currentScreen, matrices, Texts.MODMENU_TOOLTIP.get(), mouseX, mouseY)); diff --git a/src/main/java/io/github/ezforever/thatorthis/mixin/ModMenuTexturedButtonWidgetMixin.java b/src/main/java/io/github/ezforever/thatorthis/mixin/ModMenuTexturedButtonWidgetMixin.java index c30c370..94ff474 100755 --- a/src/main/java/io/github/ezforever/thatorthis/mixin/ModMenuTexturedButtonWidgetMixin.java +++ b/src/main/java/io/github/ezforever/thatorthis/mixin/ModMenuTexturedButtonWidgetMixin.java @@ -33,12 +33,13 @@ private boolean isModMenuButton() { return FABRIC_ICON_BUTTON_LOCATION.equals(texture); } - public ModMenuTexturedButtonWidgetMixin(int x, int y, int width, int height, Text message, PressAction onPress) { - super(x, y, width, height, message, onPress); + public ModMenuTexturedButtonWidgetMixin(int x, int y, int width, int height, Text message, PressAction onPress, NarrationSupplier narrationSupplier) { + super(x, y, width, height, message, onPress, narrationSupplier); } @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { + System.out.println("CLICKED 2"); if(super.mouseClicked(mouseX, mouseY, button)) return true; @@ -53,9 +54,9 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) { } @Override - public void renderTooltip(MatrixStack matrices, int mouseX, int mouseY) { + public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { if(!isModMenuButton()) { - super.renderTooltip(matrices, mouseX, mouseY); + super.render(matrices, mouseX, mouseY, delta); } else if(active) { Optional.ofNullable(MinecraftClient.getInstance().currentScreen) .ifPresent((Screen currentScreen) -> Util.renderWarpedTooltip(currentScreen, matrices, Texts.MODMENU_TOOLTIP.get(), mouseX, mouseY)); diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 8d5f914..d373629 100755 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -27,11 +27,11 @@ ], "depends": { - "minecraft": "1.18.x", + "minecraft": "1.19.x", "fabricloader": "0.14.x" }, "recommends": { - "modmenu": ">=3.0.0" + "modmenu": ">=5.0.0" }, "breaks": { "modsmod": "*" From eb0aed69bbae715aa881be1cd9929092b3c964b4 Mon Sep 17 00:00:00 2001 From: Norbiros Date: Mon, 22 May 2023 17:00:05 +0200 Subject: [PATCH 4/5] feat(translations): Added `pl_pl.json` --- .../assets/thatorthis/lang/pl_pl.json | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 src/main/resources/assets/thatorthis/lang/pl_pl.json diff --git a/src/main/resources/assets/thatorthis/lang/pl_pl.json b/src/main/resources/assets/thatorthis/lang/pl_pl.json new file mode 100755 index 0000000..92a5fa1 --- /dev/null +++ b/src/main/resources/assets/thatorthis/lang/pl_pl.json @@ -0,0 +1,23 @@ +{ + "modmenu.descriptionTranslation.thatorthis": "Wybierz pomiędzy zestawami modów", + "thatorthis.choice.title": "Ustawienia ThatOrThis", + "thatorthis.choice.subtitle": "Menu Główne", + "thatorthis.choice.discard": "Odrzuć zmiany", + "thatorthis.choice.default": "Ustawienia domyślne", + "thatorthis.choice.lock": "Wyłącz wszystkie zestawy modów", + "thatorthis.choice.lock.on": "Wszystkie zestawy modów na tym ekranie są teraz wyłączone.\nTe mody nie zostaną załadowane.", + "thatorthis.choice.lock.off": "Kliknij przycisk blokady, aby wyłączyć wszystkie mody na tym ekranie.", + "thatorthis.choice.done": "Gotowe", + "thatorthis.choice.disabled.title": "§e§lWyłączone ustawienia§r", + "thatorthis.choice.disabled.message": "Ustawienia są wyłączone z powodu nieodwracalnych błędów.\nSprawdź dziennik gry, aby uzyskać szczegóły.\nOtworzyć katalog dziennika?", + "thatorthis.confirm.title": "§e§lUstawienia zapisane§r", + "thatorthis.confirm.message": "Nowe ustawienia zostaną zastosowane po ponownym uruchomieniu.\nZakończyć Minecraft teraz?", + "thatorthis.generated.format": "%s: %%s", + "thatorthis.generated.on": "WŁ.", + "thatorthis.generated.off": "WYŁ.", + "thatorthis.modmenu.tooltip": "Kliknij, aby otworzyć ModMenu.\nKliknij prawym przyciskiem, aby otworzyć ustawienia ThatOrThis.", + "thatorthis.rule.usage.caption": "Jak korzystać z tego ekranu", + "thatorthis.rule.usage.tooltip": "§a§lJak korzystać z tego ekranu§r\n§91.§r Utwórz folder „§bthatorthis§r” w folderze „§bmods§r”;\n§92.§r Umieść w nim mody;\n§93.§r Uruchom ponownie grę;\n§94.§r Kliknij „§bWybór modów§r” i ciesz się.", + "thatorthis.rule.default.caption": "Wybór modów", + "thatorthis.rule.default.tooltip": "§a§lWybór modów§r\nWłącz lub wyłącz mody w folderze „§bthatorthis§r”.\nWszystkie mody są domyślnie włączone." +} \ No newline at end of file From f98834d65da3422ba72ab26a911b343d3557befe Mon Sep 17 00:00:00 2001 From: Norbiros Date: Tue, 23 May 2023 17:36:00 +0200 Subject: [PATCH 5/5] Some small fixes... --- README.md | 3 +-- .../ezforever/thatorthis/mixin/ModMenuButtonWidgetMixin.java | 3 --- .../thatorthis/mixin/ModMenuTexturedButtonWidgetMixin.java | 1 - src/main/resources/assets/thatorthis/lang/pl_pl.json | 4 ++-- 4 files changed, 3 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 85ed171..2447845 100755 --- a/README.md +++ b/README.md @@ -69,5 +69,4 @@ NOTE: ThatOrThis is only **intended for small, client-side mods**. It may cause [moddirector]: https://www.curseforge.com/minecraft/mc-mods/moddirector [fabric-language-kotlin]: https://www.curseforge.com/minecraft/mc-mods/fabric-language-kotlin [fabric-language-scala]: https://www.curseforge.com/minecraft/mc-mods/fabric-language-scala -[fabric-language-groovy]: https://www.curseforge.com/minecraft/mc-mods/fabric-language-groovy - +[fabric-language-groovy]: https://www.curseforge.com/minecraft/mc-mods/fabric-language-groovy \ No newline at end of file diff --git a/src/main/java/io/github/ezforever/thatorthis/mixin/ModMenuButtonWidgetMixin.java b/src/main/java/io/github/ezforever/thatorthis/mixin/ModMenuButtonWidgetMixin.java index d39d5ef..46a10fa 100755 --- a/src/main/java/io/github/ezforever/thatorthis/mixin/ModMenuButtonWidgetMixin.java +++ b/src/main/java/io/github/ezforever/thatorthis/mixin/ModMenuButtonWidgetMixin.java @@ -24,13 +24,10 @@ public ModMenuButtonWidgetMixin(int x, int y, int width, int height, Text messag @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { - System.out.println("CLICKED"); if (super.mouseClicked(mouseX, mouseY, button)) return true; - System.out.println("CLICKED 2.0"); if(clicked(mouseX, mouseY) && button == 1) { - System.out.println("CLICK 3.0"); MinecraftClient minecraftClient = MinecraftClient.getInstance(); playDownSound(minecraftClient.getSoundManager()); minecraftClient.setScreen(ChoiceScreen.create(minecraftClient.currentScreen)); diff --git a/src/main/java/io/github/ezforever/thatorthis/mixin/ModMenuTexturedButtonWidgetMixin.java b/src/main/java/io/github/ezforever/thatorthis/mixin/ModMenuTexturedButtonWidgetMixin.java index 94ff474..c7f5745 100755 --- a/src/main/java/io/github/ezforever/thatorthis/mixin/ModMenuTexturedButtonWidgetMixin.java +++ b/src/main/java/io/github/ezforever/thatorthis/mixin/ModMenuTexturedButtonWidgetMixin.java @@ -39,7 +39,6 @@ public ModMenuTexturedButtonWidgetMixin(int x, int y, int width, int height, Tex @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { - System.out.println("CLICKED 2"); if(super.mouseClicked(mouseX, mouseY, button)) return true; diff --git a/src/main/resources/assets/thatorthis/lang/pl_pl.json b/src/main/resources/assets/thatorthis/lang/pl_pl.json index 92a5fa1..0822a75 100755 --- a/src/main/resources/assets/thatorthis/lang/pl_pl.json +++ b/src/main/resources/assets/thatorthis/lang/pl_pl.json @@ -1,5 +1,5 @@ { - "modmenu.descriptionTranslation.thatorthis": "Wybierz pomiędzy zestawami modów", + "modmenu.descriptionTranslation.thatorthis": "Pozwala włączać i wyłączać mody.", "thatorthis.choice.title": "Ustawienia ThatOrThis", "thatorthis.choice.subtitle": "Menu Główne", "thatorthis.choice.discard": "Odrzuć zmiany", @@ -11,7 +11,7 @@ "thatorthis.choice.disabled.title": "§e§lWyłączone ustawienia§r", "thatorthis.choice.disabled.message": "Ustawienia są wyłączone z powodu nieodwracalnych błędów.\nSprawdź dziennik gry, aby uzyskać szczegóły.\nOtworzyć katalog dziennika?", "thatorthis.confirm.title": "§e§lUstawienia zapisane§r", - "thatorthis.confirm.message": "Nowe ustawienia zostaną zastosowane po ponownym uruchomieniu.\nZakończyć Minecraft teraz?", + "thatorthis.confirm.message": "Nowe ustawienia zostaną zastosowane po ponownym uruchomieniu.\nZrestartować Minecraft teraz?", "thatorthis.generated.format": "%s: %%s", "thatorthis.generated.on": "WŁ.", "thatorthis.generated.off": "WYŁ.",