Skip to content

Commit

Permalink
feat: upgrade to Minecraft 1.20.2
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Mojang (or legacy) authentication is no longer available, see https://aka.ms/MinecraftPostMigrationFAQ
  • Loading branch information
axieum committed Oct 15, 2023
1 parent a1f44fd commit 9438410
Show file tree
Hide file tree
Showing 45 changed files with 207 additions and 555 deletions.
4 changes: 2 additions & 2 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.7.5'
id 'com.modrinth.minotaur' version '2.8.4'
id 'com.matthewprenger.cursegradle' version '1.4.0'
id 'fabric-loom' version '1.2-SNAPSHOT'
id 'fabric-loom' version '1.4-SNAPSHOT'
}

allprojects {
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 = 7.0.2+1.20
## {x-release-please-end}

# Fabric
minecraft_version = 1.20
loader_version = 0.14.21
yarn_mappings = 1.20+build.1
fabric_version = 0.83.0+1.20
minecraft_version = 1.20.2
loader_version = 0.14.23
yarn_mappings = 1.20.2+build.4
fabric_version = 0.90.0+1.20.2

# Dependencies
cloth_config_version = 11.0.98
mod_menu_version = 7.0.0
cloth_config_version = 12.0.109
mod_menu_version = 8.0.0

checkstyle_version = 10.9.3
checkstyle_version = 10.12.4
jetbrains_annotations_version = 24.0.1
junit_jupiter_version = 5.9.2
junit_jupiter_version = 5.10.0

# CurseForge
cf_project_id = 356643
cf_game_versions = Fabric, Java 17, 1.20
cf_game_versions = Fabric, Java 17, 1.20.2
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
mr_game_versions = 1.20.2
mr_relations_required = P7dR8mSH
mr_relations_optional = mOgUt4GM
mr_relations_incompatible =
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
22 changes: 13 additions & 9 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -130,26 +131,29 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -198,11 +202,11 @@ fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
import org.jetbrains.annotations.Nullable;

import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.ButtonTextures;
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.TexturedButtonWidget;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

import me.axieum.mcmod.authme.api.util.SessionUtils;
import me.axieum.mcmod.authme.api.util.SessionUtils.SessionStatus;
import me.axieum.mcmod.authme.impl.AuthMe;

/**
* The textured button widget for opening the authentication screens.
Expand All @@ -27,6 +28,15 @@ public class AuthButtonWidget extends TexturedButtonWidget
// The last known status of the Minecraft session
private SessionStatus sessionStatus = SessionStatus.UNKNOWN;

// The authentication button textures
public static final ButtonTextures BUTTON_TEXTURES = new ButtonTextures(
new Identifier("widget/locked_button"),
new Identifier("widget/locked_button_disabled"),
new Identifier("widget/locked_button_highlighted")
);
// The session status icon texture
public static final Identifier SESSION_STATUS_TEXTURE = new Identifier("authme", "textures/gui/session_status.png");

/**
* Constructs a fixed (no drag) authentication button.
*
Expand Down Expand Up @@ -132,7 +142,7 @@ public AuthButtonWidget(
Text message
)
{
super(x, y, 20, 20, 0, 146, 20, ButtonWidget.WIDGETS_TEXTURE, 256, 256, pressAction, message);
super(x, y, 20, 20, BUTTON_TEXTURES, pressAction, message);
this.screen = screen;
this.moveAction = moveAction;
this.setTooltip(tooltip);
Expand Down Expand Up @@ -243,7 +253,7 @@ public void renderButton(DrawContext context, int mouseX, int mouseY, float delt
case OFFLINE -> u = 8;
default -> u = 16;
}
context.drawTexture(AuthMe.WIDGETS_TEXTURE, getX() + width - 6, getY() - 1, u, 60, 8, 8, 128, 128);
context.drawTexture(SESSION_STATUS_TEXTURE, getX() + width - 6, getY() - 1, u, 0, 8, 8, 24, 8);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
Expand Down Expand Up @@ -37,7 +38,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import net.minecraft.client.util.Session;
import net.minecraft.client.session.Session;
import net.minecraft.util.JsonHelper;
import net.minecraft.util.Util;

Expand Down Expand Up @@ -562,6 +563,13 @@ public static CompletableFuture<Session> login(final String mcToken, final Execu
return Optional.ofNullable(json.get("id"))
.map(JsonElement::getAsString)
.filter(uuid -> !uuid.isBlank())
// Parse the UUID (without hyphens)
.map(uuid -> UUID.fromString(
uuid.replaceFirst(
"([0-9a-fA-F]{8})([0-9a-fA-F]{4})([0-9a-fA-F]{4})([0-9a-fA-F]{4})([0-9a-fA-F]+)",
"$1-$2-$3-$4-$5"
)
))
// If present, log success, build a new session and return
.map(uuid -> {
LOGGER.info("Fetched Minecraft profile! (name={}, uuid={})",
Expand Down
67 changes: 0 additions & 67 deletions src/main/java/me/axieum/mcmod/authme/api/util/MojangUtils.java

This file was deleted.

52 changes: 13 additions & 39 deletions src/main/java/me/axieum/mcmod/authme/api/util/SessionUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,23 @@
import java.util.UUID;
import java.util.concurrent.CompletableFuture;

import com.mojang.authlib.Agent;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.exceptions.AuthenticationException;
import com.mojang.authlib.minecraft.UserApiService;
import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService;
import com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService;
import com.mojang.authlib.yggdrasil.YggdrasilUserAuthentication;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.SocialInteractionsManager;
import net.minecraft.client.realms.RealmsClient;
import net.minecraft.client.realms.RealmsPeriodicCheckers;
import net.minecraft.client.report.AbuseReportContext;
import net.minecraft.client.util.ProfileKeys;
import net.minecraft.client.util.Session;
import net.minecraft.client.session.ProfileKeys;
import net.minecraft.client.session.Session;
import net.minecraft.client.session.report.AbuseReportContext;

import me.axieum.mcmod.authme.mixin.AbuseReportContextAccessor;
import me.axieum.mcmod.authme.mixin.MinecraftClientAccessor;
import me.axieum.mcmod.authme.mixin.RealmsMainScreenAccessor;
import me.axieum.mcmod.authme.mixin.RealmsAvailabilityAccessor;
import me.axieum.mcmod.authme.mixin.SplashTextResourceSupplierAccessor;
import me.axieum.mcmod.authme.mixin.YggdrasilAuthenticationServiceAccessor;
import static me.axieum.mcmod.authme.impl.AuthMe.LOGGER;

/**
Expand Down Expand Up @@ -66,10 +62,6 @@ public static void setSession(Session session)
((MinecraftClientAccessor) client).setSession(session);
((SplashTextResourceSupplierAccessor) client.getSplashTextLoader()).setSession(session);

// Refresh the session properties
client.getSessionProperties().clear();
client.getSessionProperties();

// Re-create the user API service (ignore offline session)
UserApiService userApiService = UserApiService.OFFLINE;
if (!OFFLINE_TOKEN.equals(session.getAccessToken())) {
Expand Down Expand Up @@ -102,14 +94,15 @@ public static void setSession(Session session)
// Necessary for Realms to re-check for a valid session
RealmsClient realmsClient = RealmsClient.createRealmsClient(client);
((MinecraftClientAccessor) client).setRealmsPeriodicCheckers(new RealmsPeriodicCheckers(realmsClient));
RealmsMainScreenAccessor.setCheckedClientCompatibility(false);
RealmsMainScreenAccessor.setRealmsGenericErrorScreen(null);
RealmsAvailabilityAccessor.setCurrentFuture(null);

// The cached status is now stale
lastStatus = SessionStatus.UNKNOWN;
lastStatusCheck = 0;

LOGGER.info("Minecraft session for {} (uuid={}) has been applied", session.getUsername(), session.getUuid());
LOGGER.info(
"Minecraft session for {} (uuid={}) has been applied", session.getUsername(), session.getUuidOrNull()
);
}

/**
Expand All @@ -123,7 +116,7 @@ public static Session offline(String username)
{
return new Session(
username,
UUID.nameUUIDFromBytes(("offline:" + username).getBytes()).toString(),
UUID.nameUUIDFromBytes(("offline:" + username).getBytes()),
OFFLINE_TOKEN,
Optional.empty(),
Optional.empty(),
Expand Down Expand Up @@ -152,16 +145,14 @@ public static CompletableFuture<SessionStatus> getStatus()
return CompletableFuture.supplyAsync(() -> {
// Fetch the current session
final Session session = getSession();
final GameProfile profile = session.getProfile();
final String token = session.getAccessToken();
final String id = UUID.randomUUID().toString();
final String serverId = UUID.randomUUID().toString();

// Attempt to join the Minecraft Session Service server
final YggdrasilMinecraftSessionService sessionService = getSessionService();
try {
LOGGER.info("Verifying Minecraft session...");
sessionService.joinServer(profile, token, id);
if (sessionService.hasJoinedServer(profile, id, null).isComplete()) {
sessionService.joinServer(session.getUuidOrNull(), session.getAccessToken(), serverId);
if (sessionService.hasJoinedServer(session.getUsername(), serverId, null) != null) {
LOGGER.info("The Minecraft session is valid");
lastStatus = SessionStatus.VALID;
} else {
Expand Down Expand Up @@ -196,24 +187,7 @@ public static YggdrasilMinecraftSessionService getSessionService()
*/
public static YggdrasilAuthenticationService getAuthService()
{
final YggdrasilAuthenticationService authService = getSessionService().getAuthenticationService();

// Provide a random client token if not set
if (((YggdrasilAuthenticationServiceAccessor) authService).getClientToken() == null) {
((YggdrasilAuthenticationServiceAccessor) authService).setClientToken(UUID.randomUUID().toString());
}

return authService;
}

/**
* Returns the Yggdrasil User Authentication provider.
*
* @return Yggdrasil User Authentication instance
*/
public static YggdrasilUserAuthentication getAuthProvider()
{
return (YggdrasilUserAuthentication) getAuthService().createUserAuthentication(Agent.MINECRAFT);
return ((MinecraftClientAccessor) MinecraftClient.getInstance()).getAuthenticationService();
}

/**
Expand Down
Loading

0 comments on commit 9438410

Please sign in to comment.