Skip to content

Commit

Permalink
build: add support for Minecraft 1.20.5+ (#113)
Browse files Browse the repository at this point in the history
Co-authored-by: Thorge Engelmann <56771258+teddybear2004@users.noreply.github.com>
Co-authored-by: Jonathan Hiles <jonathan@hil.es>
Release-As: 8.0.0+1.20.5
  • Loading branch information
3 people authored Apr 28, 2024
1 parent 23a07ca commit 456a273
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 104 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ jobs:
- name: ✨ Checkout repository
uses: actions/checkout@v4

- name: ☕ Set up JDK 17
- name: ☕ Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: 17
java-version: 21
distribution: temurin

- name: 🐘 Set up Gradle
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ jobs:
- name: ✨ Checkout repository
uses: actions/checkout@v4

- name: ☕ Set up JDK 17
- name: ☕ Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: 17
java-version: 21
distribution: temurin

- name: 🐘 Set up Gradle
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ plugins {
id 'java'
id 'checkstyle'
id 'maven-publish'
id 'com.modrinth.minotaur' version '2.8.4'
id 'com.modrinth.minotaur' version '2.8.7'
id 'com.matthewprenger.cursegradle' version '1.4.0'
id 'fabric-loom' version '1.4-SNAPSHOT'
id 'fabric-loom' version '1.6-SNAPSHOT'
}

allprojects {
Expand All @@ -17,7 +17,7 @@ allprojects {
version = project.mod_version
archivesBaseName = project.mod_id

sourceCompatibility = targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_21

// Configure Loom
loom {
Expand Down
20 changes: 10 additions & 10 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ mod_version = 8.0.0+1.20.4
## {x-release-please-end}

# Fabric
minecraft_version = 1.20.4
loader_version = 0.15.1
yarn_mappings = 1.20.4+build.1
fabric_version = 0.91.2+1.20.4
minecraft_version = 1.20.5
loader_version = 0.15.10
yarn_mappings = 1.20.5+build.1
fabric_version = 0.97.7+1.20.5

# Dependencies
cloth_config_version = 13.0.114
mod_menu_version = 9.0.0-pre.1
cloth_config_version = 14.0.126
mod_menu_version = 10.0.0-beta.1

checkstyle_version = 10.12.5
checkstyle_version = 10.15.0
jetbrains_annotations_version = 24.1.0
junit_jupiter_version = 5.10.1
junit_jupiter_version = 5.10.2

# CurseForge
cf_project_id = 356643
cf_game_versions = Fabric, Java 17, 1.20.3, 1.20.4
cf_game_versions = Fabric, Java 21, 1.20.5
cf_relations_required = fabric-api
cf_relations_optional = modmenu
cf_relations_embedded = cloth-config
Expand All @@ -31,7 +31,7 @@ cf_relations_incompatible =

# Modrinth
mr_project_id = yjgIrBjZ
mr_game_versions = 1.20.3, 1.20.4
mr_game_versions = 1.20.5
mr_relations_required = P7dR8mSH
mr_relations_optional = mOgUt4GM
mr_relations_incompatible =
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public PasswordFieldWidget(TextRenderer textRenderer, int x, int y, int width, i
);
// NB: Overriding the rendered characters affects interaction, as the
// rendered characters have different widths to the actual underlying text.
// i.e. setRenderTextProvider((value, limit) -> StringUtils.repeat('\u204E', value.length()));
// i.e. setRenderTextProvider((value, limit) -> StringUtils.repeat('', value.length()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
/**
* Utility methods for authenticating via Microsoft.
*
* <p>For more information refer to: https://wiki.vg/Microsoft_Authentication_Scheme
* <p>For more information refer to:
* <a href="https://wiki.vg/Microsoft_Authentication_Scheme">https://wiki.vg/Microsoft_Authentication_Scheme</a>
*/
public final class MicrosoftUtils
{
Expand Down
47 changes: 20 additions & 27 deletions src/main/java/me/axieum/mcmod/authme/impl/gui/AuthMethodScreen.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package me.axieum.mcmod.authme.impl.gui;

import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.ButtonTextures;
import net.minecraft.client.gui.screen.ConfirmLinkScreen;
import net.minecraft.client.gui.screen.ConfirmScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.tooltip.Tooltip;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.TextWidget;
import net.minecraft.client.gui.widget.TexturedButtonWidget;
import net.minecraft.client.util.InputUtil;
import net.minecraft.text.Text;
Expand All @@ -24,8 +24,6 @@ public class AuthMethodScreen extends Screen
{
// The parent (or last) screen that opened this screen
private final Screen parentScreen;
// A greeting message shown for the current session
private Text greeting = null;

// The 'Microsoft' authentication method button textures
public static final ButtonTextures MICROSOFT_BUTTON_TEXTURES = new ButtonTextures(
Expand Down Expand Up @@ -63,11 +61,26 @@ protected void init()
super.init();
assert client != null;

// Set the greeting message
greeting = Text.translatable(
"gui.authme.method.greeting",
Text.literal(SessionUtils.getSession().getUsername()).formatted(Formatting.YELLOW)
// Add a title
TextWidget titleWidget = new TextWidget(width, height, title, textRenderer);
titleWidget.setTextColor(0xffffff);
titleWidget.setPosition(width / 2 - titleWidget.getWidth() / 2, height / 2 - titleWidget.getHeight() / 2 - 22);
addDrawableChild(titleWidget);

// Add a greeting message
TextWidget greetingWidget = new TextWidget(
width, height,
Text.translatable(
"gui.authme.method.greeting",
Text.literal(SessionUtils.getSession().getUsername()).formatted(Formatting.YELLOW)
),
textRenderer
);
greetingWidget.setTextColor(0xa0a0a0);
greetingWidget.setPosition(
width / 2 - greetingWidget.getWidth() / 2, height / 2 - greetingWidget.getHeight() / 2 - 42
);
addDrawableChild(greetingWidget);

// Add a button for the 'Microsoft' authentication method
TexturedButtonWidget msButton = new TexturedButtonWidget(
Expand Down Expand Up @@ -136,26 +149,6 @@ protected void init()
);
}

@Override
public void render(DrawContext context, int mouseX, int mouseY, float delta)
{
assert client != null;

// Render the background before any widgets
renderBackground(context, mouseX, mouseY, delta);

// Render a title for the screen
context.drawCenteredTextWithShadow(client.textRenderer, title, width / 2, height / 2 - 27, 0xffffff);

// Render a greeting for the current session
if (greeting != null) {
context.drawCenteredTextWithShadow(client.textRenderer, greeting, width / 2, height / 2 - 47, 0xa0a0a0);
}

// Cascade the rendering
super.render(context, mouseX, mouseY, delta);
}

@Override
public void close()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

import org.apache.http.conn.ConnectTimeoutException;

import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.TextWidget;
import net.minecraft.client.toast.SystemToast;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
Expand All @@ -28,7 +28,7 @@ public class MicrosoftAuthScreen extends AuthScreen
// The completable future for all Microsoft login tasks
private CompletableFuture<Void> task = null;
// The current progress/status of the login task
private Text status = null;
private TextWidget statusWidget = null;
// True if Microsoft should prompt to select an account
private final boolean selectAccount;

Expand All @@ -52,6 +52,20 @@ protected void init()
super.init();
assert client != null;

// Add a title
TextWidget titleWidget = new TextWidget(width, height, title, textRenderer);
titleWidget.setTextColor(0xffffff);
titleWidget.setPosition(width / 2 - titleWidget.getWidth() / 2, height / 2 - titleWidget.getHeight() / 2 - 27);
addDrawableChild(titleWidget);

// Add a status message
statusWidget = new TextWidget(width, height, title, textRenderer);
statusWidget.setTextColor(0xdddddd);
statusWidget.setPosition(
width / 2 - statusWidget.getWidth() / 2, height / 2 - statusWidget.getHeight() / 2 - 1
);
addDrawableChild(statusWidget);

// Add a cancel button to abort the task
final ButtonWidget cancelBtn;
addDrawableChild(
Expand All @@ -67,7 +81,7 @@ protected void init()
if (task != null) return;

// Set the initial progress/status of the login task
status = Text.translatable("gui.authme.microsoft.status.checkBrowser");
statusWidget.setMessage(Text.translatable("gui.authme.microsoft.status.checkBrowser"));

// Prepare a new executor thread to run the login task on
executor = Executors.newSingleThreadExecutor();
Expand All @@ -83,33 +97,33 @@ protected void init()

// Exchange the Microsoft auth code for an access token
.thenComposeAsync(msAuthCode -> {
status = Text.translatable("gui.authme.microsoft.status.msAccessToken");
statusWidget.setMessage(Text.translatable("gui.authme.microsoft.status.msAccessToken"));
return MicrosoftUtils.acquireMSAccessToken(msAuthCode, executor);
})

// Exchange the Microsoft access token for an Xbox access token
.thenComposeAsync(msAccessToken -> {
status = Text.translatable("gui.authme.microsoft.status.xboxAccessToken");
statusWidget.setMessage(Text.translatable("gui.authme.microsoft.status.xboxAccessToken"));
return MicrosoftUtils.acquireXboxAccessToken(msAccessToken, executor);
})

// Exchange the Xbox access token for an XSTS token
.thenComposeAsync(xboxAccessToken -> {
status = Text.translatable("gui.authme.microsoft.status.xboxXstsToken");
statusWidget.setMessage(Text.translatable("gui.authme.microsoft.status.xboxXstsToken"));
return MicrosoftUtils.acquireXboxXstsToken(xboxAccessToken, executor);
})

// Exchange the Xbox XSTS token for a Minecraft access token
.thenComposeAsync(xboxXstsData -> {
status = Text.translatable("gui.authme.microsoft.status.mcAccessToken");
statusWidget.setMessage(Text.translatable("gui.authme.microsoft.status.mcAccessToken"));
return MicrosoftUtils.acquireMCAccessToken(
xboxXstsData.get("Token"), xboxXstsData.get("uhs"), executor
);
})

// Build a new Minecraft session with the Minecraft access token
.thenComposeAsync(mcToken -> {
status = Text.translatable("gui.authme.microsoft.status.mcProfile");
statusWidget.setMessage(Text.translatable("gui.authme.microsoft.status.mcProfile"));
return MicrosoftUtils.login(mcToken, executor);
})

Expand Down Expand Up @@ -137,32 +151,12 @@ protected void init()
} else {
key = "gui.authme.error.generic";
}
status = Text.translatable(key).formatted(Formatting.RED);
statusWidget.setMessage(Text.translatable(key).formatted(Formatting.RED));
cancelBtn.setMessage(Text.translatable("gui.back"));
return null; // return a default value
});
}

@Override
public void render(DrawContext context, int mouseX, int mouseY, float delta)
{
assert client != null;

// Render the background before any widgets
renderBackground(context, mouseX, mouseY, delta);

// Render a title for the screen
context.drawCenteredTextWithShadow(client.textRenderer, title, width / 2, height / 2 - 32, 0xffffff);

// Render the current progress/status of the login, if present
if (status != null) {
context.drawCenteredTextWithShadow(client.textRenderer, status, width / 2, height / 2 - 6, 0xdddddd);
}

// Cascade the rendering
super.render(context, mouseX, mouseY, delta);
}

@Override
public void close()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package me.axieum.mcmod.authme.impl.gui;

import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.client.gui.widget.TextWidget;
import net.minecraft.client.toast.SystemToast;
import net.minecraft.text.Text;

Expand Down Expand Up @@ -41,6 +41,12 @@ protected void init()
super.init();
assert client != null;

// Add a title
TextWidget titleWidget = new TextWidget(width, height, title, textRenderer);
titleWidget.setTextColor(0xffffff);
titleWidget.setPosition(width / 2 - titleWidget.getWidth() / 2, height / 2 - titleWidget.getHeight() / 2 - 40);
addDrawableChild(titleWidget);

// Add a username text field
addDrawableChild(
usernameField = new TextFieldWidget(
Expand All @@ -55,6 +61,15 @@ protected void init()
}
usernameField.setChangedListener(value -> loginBtn.active = isFormValid());

// Add a label for the username field
TextWidget labelWidget = new TextWidget(width, height, usernameField.getMessage(), textRenderer);
labelWidget.setTextColor(0xdddddd);
labelWidget.setPosition(
width / 2 - labelWidget.getWidth() / 2 - 51,
height / 2 - labelWidget.getHeight() / 2 - 17
);
addDrawableChild(labelWidget);

// Add a login button to submit the form
addDrawableChild(
loginBtn = ButtonWidget.builder(
Expand Down Expand Up @@ -118,28 +133,4 @@ public boolean isFormValid()
{
return !usernameField.getText().isBlank();
}

@Override
public void render(DrawContext context, int mouseX, int mouseY, float delta)
{
assert client != null;

// Render the background before any widgets
renderBackground(context, mouseX, mouseY, delta);

// Render a title for the screen
context.drawCenteredTextWithShadow(client.textRenderer, title, width / 2,
usernameField.getY() - 16 - 23, 0xffffff);

// Render the username field label
context.drawTextWithShadow(
client.textRenderer,
usernameField.getMessage(),
usernameField.getX(), usernameField.getY() - 16,
0xa0a0a0
);

// Cascade the rendering
super.render(context, mouseX, mouseY, delta);
}
}
Loading

0 comments on commit 456a273

Please sign in to comment.