Skip to content

Commit

Permalink
build: add support for Minecraft 1.20.5+
Browse files Browse the repository at this point in the history
Release-As: 8.0.0+1.20.5
  • Loading branch information
axieum committed Apr 28, 2024
1 parent 0e44c7f commit def4453
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 134 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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.6-SNAPSHOT'
}
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ mod_version = 8.0.0+1.20.4
minecraft_version = 1.20.5
loader_version = 0.15.10
yarn_mappings = 1.20.5+build.1
fabric_version = 0.97.5+1.20.5
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
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.6-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
57 changes: 19 additions & 38 deletions src/main/java/me/axieum/mcmod/authme/impl/gui/AuthMethodScreen.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
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;
Expand All @@ -25,8 +24,6 @@ public class AuthMethodScreen extends Screen
{
// The parent (or last) screen that opened this screen
private final Screen parentScreen;
private TextWidget greetingsWidget;
private TextWidget titleWidget;

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

titleWidget = this.addDrawableChild(new TextWidget(this.width, this.height, title, this.textRenderer))
.setTextColor(0xffffff);

// A greeting message shown for the current session
Text 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
);

greetingsWidget = this.addDrawableChild(new TextWidget(this.width, this.height, greeting, this.textRenderer))
.setTextColor(0xa0a0a0);
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 @@ -143,31 +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
if (titleWidget != null) {
int xPos = width / 2 - titleWidget.getWidth() / 2;
int yPos = height / 2 - titleWidget.getHeight() / 2;
titleWidget.setPosition(xPos, yPos - 27);
}

if (greetingsWidget != null) {
int xPos = width / 2 - greetingsWidget.getWidth() / 2;
int yPos = height / 2 - greetingsWidget.getHeight() / 2;
greetingsWidget.setPosition(xPos, yPos - 47);
}

// 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,7 +6,6 @@

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;
Expand All @@ -30,8 +29,6 @@ public class MicrosoftAuthScreen extends AuthScreen
private CompletableFuture<Void> task = null;
// The current progress/status of the login task
private TextWidget statusWidget = null;
// The title of the screen
private TextWidget titleWidget = null;
// True if Microsoft should prompt to select an account
private final boolean selectAccount;

Expand All @@ -55,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 @@ -69,11 +80,8 @@ protected void init()
// Prevent the task from starting several times
if (task != null) return;

titleWidget = this.addDrawableChild(new TextWidget(this.width, this.height, title, this.textRenderer))
.setTextColor(0xffffff);

// Set the initial progress/status of the login task
setStatusWidget(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 @@ -89,33 +97,33 @@ protected void init()

// Exchange the Microsoft auth code for an access token
.thenComposeAsync(msAuthCode -> {
setStatusWidget(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 -> {
setStatusWidget(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 -> {
setStatusWidget(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 -> {
setStatusWidget(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 -> {
setStatusWidget(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 @@ -143,38 +151,12 @@ protected void init()
} else {
key = "gui.authme.error.generic";
}
setStatusWidget(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
if (titleWidget != null) {
int xPos = width / 2 - titleWidget.getWidth() / 2;
int yPos = height / 2 - titleWidget.getHeight() / 2;
titleWidget.setPosition(xPos, yPos - 32);
}

// Render the current progress/status of the login, if present
if (statusWidget != null) {
int xPos = width / 2 - statusWidget.getWidth() / 2;
int yPos = height / 2 - statusWidget.getHeight() / 2;
statusWidget.setPosition(xPos, yPos - 6);
}

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

@Override
public void close()
{
Expand All @@ -187,11 +169,4 @@ public void close()
// Cascade the closing
super.close();
}

private void setStatusWidget(Text status)
{
this.remove(statusWidget);
statusWidget = this.addDrawableChild(new TextWidget(status, this.textRenderer))
.setTextColor(0xdddddd);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
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;
Expand All @@ -23,9 +22,6 @@ public class OfflineAuthScreen extends AuthScreen
private TextFieldWidget usernameField;
// The login button widget
private ButtonWidget loginBtn;
// The title of the screen
private TextWidget titleWidget = null;
private TextWidget usernameFieldMessageWidget = null;

/**
* Constructs a new offline authentication screen.
Expand All @@ -45,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 @@ -59,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 All @@ -79,14 +90,6 @@ protected void init()
width / 2 + 2, height / 2 + 26, 100, 20
).build()
);

titleWidget = this.addDrawableChild(
new TextWidget(this.width, this.height, title, this.textRenderer))
.setTextColor(0xffffff);

usernameFieldMessageWidget = this.addDrawableChild(
new TextWidget(this.width, this.height, usernameField.getMessage(), this.textRenderer))
.setTextColor(0xa0a0a0);
}

/**
Expand Down Expand Up @@ -130,30 +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
if (titleWidget != null) {
int xPos = width / 2 - titleWidget.getWidth() / 2;
int yPos = height / 2 - titleWidget.getHeight() / 2;
titleWidget.setPosition(xPos, yPos - 16 - 23);
}

// Render the username field label
if (usernameFieldMessageWidget != null) {
int xPos = width / 2 - usernameFieldMessageWidget.getWidth() / 2;
int yPos = height / 2 - usernameFieldMessageWidget.getHeight() / 2;
usernameFieldMessageWidget.setPosition(xPos, yPos - 16);
}

// Cascade the rendering
super.render(context, mouseX, mouseY, delta);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
Expand Down Expand Up @@ -74,6 +75,7 @@ private void init(CallbackInfo ci)
* @param reason disconnect reason text
* @return true if the disconnection reason is user or session related
*/
@Unique
private static boolean isUserRelated(final @Nullable Text reason)
{
if (reason != null && reason.getContent() instanceof TranslatableTextContent content) {
Expand Down
Loading

0 comments on commit def4453

Please sign in to comment.