From 699d883a4a8bd9073a3fd6d041241594b53f842e Mon Sep 17 00:00:00 2001 From: VendoAU Date: Wed, 14 Jul 2021 13:48:17 +1000 Subject: [PATCH] Updated to 1.17 --- build.gradle | 53 +++++++++++-------- gradle.properties | 13 +++-- settings.gradle | 3 +- .../technicianlp/reauth/gui/AuthScreen.java | 18 +++---- .../reauth/mixin/DisconnectedScreenMixin.java | 14 +++-- .../reauth/mixin/MultiplayerScreenMixin.java | 2 +- .../reauth/mixinUtil/DisconnectUtil.java | 7 +-- src/main/resources/fabric.mod.json | 2 +- src/main/resources/reauth.mixins.json | 2 +- 9 files changed, 62 insertions(+), 52 deletions(-) diff --git a/build.gradle b/build.gradle index e80d504..a4ffd00 100644 --- a/build.gradle +++ b/build.gradle @@ -1,14 +1,23 @@ plugins { - id 'fabric-loom' version '0.4-SNAPSHOT' + id 'fabric-loom' version '0.8-SNAPSHOT' id 'maven-publish' } -sourceCompatibility = JavaVersion.VERSION_1_8 -targetCompatibility = JavaVersion.VERSION_1_8 +sourceCompatibility = JavaVersion.VERSION_16 +targetCompatibility = JavaVersion.VERSION_16 archivesBaseName = project.archives_base_name version = project.mod_version +repositories { + maven { + url "https://maven.shedaniel.me/" + } + maven { + url "https://raw.githubusercontent.com/TerraformersMC/Archive/main/releases/" + } +} + dependencies { //to change the versions see the gradle.properties file minecraft "com.mojang:minecraft:${project.minecraft_version}" @@ -18,9 +27,9 @@ dependencies { // Fabric API. This is technically optional, but you probably want it anyway. modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" - modApi "me.sargunvohra.mcmods:autoconfig1u:3.2.0-unstable" - modImplementation "io.github.prospector:modmenu:1.14.6+build.31" - modApi ("me.shedaniel.cloth:config-2:4.7.0-unstable") { + modApi "me.sargunvohra.mcmods:autoconfig1u:3.3.1" + modImplementation "com.terraformersmc:modmenu:2.0.2" + modApi ("me.shedaniel.cloth:cloth-config-fabric:5.0.34") { exclude(group: "net.fabricmc.fabric-api") } // PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs. @@ -30,29 +39,27 @@ dependencies { processResources { inputs.property "version", project.version - from(sourceSets.main.resources.srcDirs) { - include "fabric.mod.json" + filesMatching("fabric.mod.json") { expand "version": project.version } - - from(sourceSets.main.resources.srcDirs) { - exclude "fabric.mod.json" - } } -// ensure that the encoding is set to UTF-8, no matter what the system default is -// this fixes some edge cases with special characters not displaying correctly -// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html -tasks.withType(JavaCompile) { - options.encoding = "UTF-8" +tasks.withType(JavaCompile).configureEach { + // ensure that the encoding is set to UTF-8, no matter what the system default is + // this fixes some edge cases with special characters not displaying correctly + // see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html + // 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 } -// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task -// if it is present. -// If you remove this task, sources will not be generated. -task sourcesJar(type: Jar, dependsOn: classes) { - classifier = "sources" - from sourceSets.main.allSource +java { + // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task + // if it is present. + // If you remove this line, sources will not be generated. + withSourcesJar() } ext { diff --git a/gradle.properties b/gradle.properties index b51e4f3..8424bc8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,14 +3,13 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/use - minecraft_version=1.16.2 - yarn_mappings=1.16.2+build.1 - loader_version=0.9.1+build.205 + minecraft_version=1.17 + yarn_mappings=1.17+build.13 + loader_version=0.11.6 # Mod Properties - mod_version = 3.9.3 - archives_base_name = ReAuth-1.16-Fabric + mod_version = 3.10.0 + archives_base_name = ReAuth-1.17-Fabric # Dependencies - # currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api - fabric_version=0.19.0+build.398-1.16 + fabric_version=0.36.0+1.17 \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index a9ae1f4..0460252 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,6 +1,5 @@ pluginManagement { repositories { - jcenter() maven { name = 'Fabric' url = 'https://maven.fabricmc.net/' @@ -9,4 +8,4 @@ pluginManagement { } } -rootProject.name='ReAuth Fabric 1.16' +rootProject.name='ReAuth Fabric 1.17' diff --git a/src/main/java/technicianlp/reauth/gui/AuthScreen.java b/src/main/java/technicianlp/reauth/gui/AuthScreen.java index 6b004bc..4b4f5df 100644 --- a/src/main/java/technicianlp/reauth/gui/AuthScreen.java +++ b/src/main/java/technicianlp/reauth/gui/AuthScreen.java @@ -54,30 +54,30 @@ public void init() { this.username = new TextFieldWidget(this.textRenderer, this.width / 2 - 155, this.baseY + 15, 2 * 155, 20, new TranslatableText("reauth.gui.auth.username")); this.username.setMaxLength(512); this.username.setText(ReAuth.config.getUsername()); - addButton(username); + addDrawableChild(username); this.pw = new PasswordFieldWidget(this.textRenderer, this.width / 2 - 155, this.baseY + 60, 2 * 155, 20, new TranslatableText("reauth.gui.auth.password")); this.pw.setMaxLength(Short.MAX_VALUE); this.pw.setText(ReAuth.config.getPassword()); - addButton(this.pw); + addDrawableChild(this.pw); setInitialFocus(username.getText().isEmpty() ? username : pw); this.save = new CheckboxWidget(this.width / 2 - 155, this.baseY + 85, 2 * 155, 20, new TranslatableText("reauth.gui.auth.checkbox"), !pw.getText().isEmpty()); if (ReAuth.config.hasCrypto()) { - addButton(this.save); + addDrawableChild(this.save); } this.confirm = new ButtonWidget(this.width / 2 - 155, this.baseY + 110, 153, 20, LiteralText.EMPTY, b -> doLogin()); - addButton(confirm); + addDrawableChild(confirm); this.cancel = new ButtonWidget(this.width / 2 + 2, this.baseY + 110, 155, 20, new TranslatableText("gui.cancel"), b -> this.client.openScreen(prev)); - addButton(cancel); + addDrawableChild(cancel); this.config = new ButtonWidget(this.width - 80, this.height - 25, 75, 20, new TranslatableText("reauth.gui.auth.config"), b -> { this.client.openScreen(ClothConfigIntegration.getConfigScreen(this)); }); if (ClothConfigIntegration.isAvailable()) { - addButton(config); + addDrawableChild(config); } if (message.isEmpty() && ReAuth.versionCheck.getStatus() == VersionChecker.Status.OUTDATED) { @@ -115,9 +115,9 @@ public void render(MatrixStack matrices, int mouseX, int mouseY, float partialTi private void focus(TextFieldWidget widget) { Element old = getFocused(); if (old instanceof TextFieldWidget) - ((TextFieldWidget) old).setSelected(false); + ((TextFieldWidget) old).setTextFieldFocused(false); if (widget != null) - widget.setSelected(true); + widget.setTextFieldFocused(true); focusOn(widget); } @@ -232,6 +232,6 @@ public String getTranslation() { * the superclass method changes from instance to static between 1.16.1 and 1.16.2 */ private void drawCenteredString2(MatrixStack matrices, TextRenderer textRenderer, String text, int centerX, int y, int color) { - textRenderer.drawWithShadow(matrices, text, (float)(centerX - textRenderer.getWidth(text) / 2), (float)y, color); + textRenderer.drawWithShadow(matrices, text, (float) (centerX - textRenderer.getWidth(text) / 2), (float) y, color); } } diff --git a/src/main/java/technicianlp/reauth/mixin/DisconnectedScreenMixin.java b/src/main/java/technicianlp/reauth/mixin/DisconnectedScreenMixin.java index dd470f2..f27a86e 100644 --- a/src/main/java/technicianlp/reauth/mixin/DisconnectedScreenMixin.java +++ b/src/main/java/technicianlp/reauth/mixin/DisconnectedScreenMixin.java @@ -3,12 +3,12 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.DisconnectedScreen; import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.widget.AbstractButtonWidget; import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.text.LiteralText; import net.minecraft.text.Text; import net.minecraft.text.TranslatableText; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.gen.Accessor; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -26,6 +26,9 @@ protected DisconnectedScreenMixin() { super(new LiteralText("Dummy Constructor")); } + @Shadow + private int reasonHeight; + @Override @Accessor("reason") public abstract Text reauthGetReason(); @@ -38,18 +41,19 @@ protected DisconnectedScreenMixin() { private void reauthInit(CallbackInfo info) { if ("connect.failed".equals(getTranslationKey(this.getTitle()))) { if (getTranslationKey(reauthGetReason()).startsWith("disconnect.loginFailed")) { - AbstractButtonWidget menu = this.buttons.get(0); + int x = this.width / 2 - 100; + int y = this.height / 2 + this.reasonHeight / 2; String key = DisconnectUtil.canRetryLogin() ? "reauth.retry" : "reauth.retry.disabled"; Text retryText = new TranslatableText(key, ReAuth.config.getProfile()); - ButtonWidget retryButton = new ButtonWidget(menu.x, menu.y + 25, 200, 20, retryText, b -> { + ButtonWidget retryButton = new ButtonWidget(x, y + 25, 200, 20, retryText, b -> { DisconnectUtil.retryLogin(); }); if (!DisconnectUtil.canRetryLogin()) { retryButton.active = false; } - this.addButton(retryButton); - this.addButton(new ButtonWidget(menu.x, menu.y + 50, 200, 20, new TranslatableText("reauth.open"), b -> { + this.addDrawableChild(retryButton); + this.addDrawableChild(new ButtonWidget(x, y + 50, 200, 20, new TranslatableText("reauth.open"), b -> { MinecraftClient.getInstance().openScreen(new AuthScreen(reauthGetParent())); })); } diff --git a/src/main/java/technicianlp/reauth/mixin/MultiplayerScreenMixin.java b/src/main/java/technicianlp/reauth/mixin/MultiplayerScreenMixin.java index b75ba7c..f697c0d 100644 --- a/src/main/java/technicianlp/reauth/mixin/MultiplayerScreenMixin.java +++ b/src/main/java/technicianlp/reauth/mixin/MultiplayerScreenMixin.java @@ -27,7 +27,7 @@ private void reauthInit(CallbackInfo info) { if(Screen.hasShiftDown()) { ReAuth.auth.getSessionStatus(true); } - addButton(new ButtonWidget(5, 5, 100, 20, new TranslatableText("reauth.gui.button"), + addDrawableChild(new ButtonWidget(5, 5, 100, 20, new TranslatableText("reauth.gui.button"), b -> MinecraftClient.getInstance().openScreen(new AuthScreen(this)))); } diff --git a/src/main/java/technicianlp/reauth/mixinUtil/DisconnectUtil.java b/src/main/java/technicianlp/reauth/mixinUtil/DisconnectUtil.java index 1d86161..6aa9e08 100644 --- a/src/main/java/technicianlp/reauth/mixinUtil/DisconnectUtil.java +++ b/src/main/java/technicianlp/reauth/mixinUtil/DisconnectUtil.java @@ -4,6 +4,7 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.ConnectScreen; import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.network.ServerAddress; import net.minecraft.client.resource.language.I18n; import net.minecraft.text.TranslatableText; import technicianlp.reauth.ReAuth; @@ -35,10 +36,10 @@ public static void retryLogin() { ReAuth.auth.login(ReAuth.config.getUsername(), ReAuth.config.getPassword(), true); if (screen != null) { SocketAddress add = screen.reauthGetConnection().getAddress(); - if (add instanceof InetSocketAddress) { - InetSocketAddress address = (InetSocketAddress) add; + if (add instanceof InetSocketAddress address) { MinecraftClient client = MinecraftClient.getInstance(); - client.openScreen(new ConnectScreen(screen.reauthGetParent(), client, address.getHostString(), address.getPort())); + ServerAddress serverAddress = new ServerAddress(address.getHostString(), address.getPort()); + ConnectScreen.connect(screen.reauthGetParent(), client, serverAddress, null); } } } catch (AuthenticationException exception) { diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 6d93600..6945ce7 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -31,7 +31,7 @@ "depends": { "fabricloader": ">=0.7.4", "fabric": "*", - "minecraft": "1.16.*", + "minecraft": "1.17.*", "autoconfig1u": "*" }, "recommends": { diff --git a/src/main/resources/reauth.mixins.json b/src/main/resources/reauth.mixins.json index c35c10d..0b90e7d 100644 --- a/src/main/resources/reauth.mixins.json +++ b/src/main/resources/reauth.mixins.json @@ -2,7 +2,7 @@ "required": true, "minVersion": "0.8", "package": "technicianlp.reauth.mixin", - "compatibilityLevel": "JAVA_8", + "compatibilityLevel": "JAVA_16", "mixins": [], "client": [ "MultiplayerScreenMixin",