Skip to content

Commit

Permalink
build: add support for Minecraft 1.21+ (#115)
Browse files Browse the repository at this point in the history
Co-authored-by: Jonathan Hiles <jonathan@hil.es>
Release-As: 8.0.0+1.21
  • Loading branch information
Kneelawk and axieum authored Jun 13, 2024
1 parent a467fe3 commit ef410a0
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 26 deletions.
8 changes: 6 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,14 @@ allprojects {
modImplementation include(fabricApi.module("fabric-resource-loader-v0", project.fabric_version))
modImplementation "com.terraformersmc:modmenu:${project.mod_menu_version}"
modImplementation include("me.shedaniel.cloth:cloth-config-fabric:${project.cloth_config_version}") {
exclude module: 'modmenu'
exclude module: 'fabric-api'
exclude group: 'com.terraformersmc'
exclude group: 'net.fabricmc.fabric-api'
}

// Needed by ModMenu
modLocalRuntime fabricApi.module("fabric-screen-api-v1", project.fabric_version)
modLocalRuntime fabricApi.module("fabric-key-binding-api-v1", project.fabric_version)

// Code Quality
compileOnly "org.jetbrains:annotations:${project.jetbrains_annotations_version}"
testImplementation "org.junit.jupiter:junit-jupiter-api:${project.junit_jupiter_version}"
Expand Down
16 changes: 8 additions & 8 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.5
## {x-release-please-end}

# Fabric
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
minecraft_version = 1.21
loader_version = 0.15.11
yarn_mappings = 1.21+build.1
fabric_version = 0.100.1+1.21

# Dependencies
cloth_config_version = 14.0.126
mod_menu_version = 10.0.0-beta.1
cloth_config_version = 15.0.127
mod_menu_version = 11.0.0-beta.1

checkstyle_version = 10.15.0
jetbrains_annotations_version = 24.1.0
junit_jupiter_version = 5.10.2

# CurseForge
cf_project_id = 356643
cf_game_versions = Fabric, Java 21, 1.20.5
cf_game_versions = Fabric, Java 21, 1.21
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.5
mr_game_versions = 1.21
mr_relations_required = P7dR8mSH
mr_relations_optional = mOgUt4GM
mr_relations_incompatible =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ public class AuthButtonWidget extends TexturedButtonWidget

// 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")
Identifier.of("widget/locked_button"),
Identifier.of("widget/locked_button_disabled"),
Identifier.of("widget/locked_button_highlighted")
);
// The session status icon texture
public static final Identifier SESSION_STATUS_TEXTURE = new Identifier("authme", "textures/gui/session_status.png");
public static final Identifier SESSION_STATUS_TEXTURE = Identifier.of("authme", "textures/gui/session_status.png");

/**
* Constructs a fixed (no drag) authentication button.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.minecraft.client.session.ProfileKeys;
import net.minecraft.client.session.Session;
import net.minecraft.client.session.report.AbuseReportContext;
import net.minecraft.util.Util;

import me.axieum.mcmod.authme.mixin.AbuseReportContextAccessor;
import me.axieum.mcmod.authme.mixin.MinecraftClientAccessor;
Expand Down Expand Up @@ -62,6 +63,11 @@ public static void setSession(Session session)
((MinecraftClientAccessor) client).setSession(session);
((SplashTextResourceSupplierAccessor) client.getSplashTextLoader()).setSession(session);

// Re-create the game profile future
((MinecraftClientAccessor) client).setGameProfileFuture(
CompletableFuture.supplyAsync(() -> client.getSessionService().fetchProfile(session.getUuidOrNull(), true),
Util.getDownloadWorkerExecutor()));

// Re-create the user API service (ignore offline session)
UserApiService userApiService = UserApiService.OFFLINE;
if (!OFFLINE_TOKEN.equals(session.getAccessToken())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@ public class AuthMethodScreen extends Screen

// The 'Microsoft' authentication method button textures
public static final ButtonTextures MICROSOFT_BUTTON_TEXTURES = new ButtonTextures(
new Identifier("authme", "widget/microsoft_button"),
new Identifier("authme", "widget/microsoft_button_disabled"),
new Identifier("authme", "widget/microsoft_button_focused")
Identifier.of("authme", "widget/microsoft_button"),
Identifier.of("authme", "widget/microsoft_button_disabled"),
Identifier.of("authme", "widget/microsoft_button_focused")
);
// The 'Mojang (or legacy)' authentication method button textures
public static final ButtonTextures MOJANG_BUTTON_TEXTURES = new ButtonTextures(
new Identifier("authme", "widget/mojang_button"),
new Identifier("authme", "widget/mojang_button_disabled"),
new Identifier("authme", "widget/mojang_button_focused")
Identifier.of("authme", "widget/mojang_button"),
Identifier.of("authme", "widget/mojang_button_disabled"),
Identifier.of("authme", "widget/mojang_button_focused")
);
// The 'Offline' authentication method button textures
public static final ButtonTextures OFFLINE_BUTTON_TEXTURES = new ButtonTextures(
new Identifier("authme", "widget/offline_button"),
new Identifier("authme", "widget/offline_button_disabled"),
new Identifier("authme", "widget/offline_button_focused")
Identifier.of("authme", "widget/offline_button"),
Identifier.of("authme", "widget/offline_button_disabled"),
Identifier.of("authme", "widget/offline_button_focused")
);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.minecraft.client.gui.screen.DisconnectedScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.network.DisconnectionInfo;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableTextContent;

Expand All @@ -30,7 +31,7 @@ public abstract class DisconnectedScreenMixin extends Screen

@Shadow
@Final
private Text reason;
private DisconnectionInfo info;

private DisconnectedScreenMixin(Text title)
{
Expand All @@ -46,7 +47,7 @@ private DisconnectedScreenMixin(Text title)
private void init(CallbackInfo ci)
{
// Determine if the disconnection reason is user or session related
if (isUserRelated(reason)) {
if (isUserRelated(info.reason())) {
LOGGER.info("Adding auth button to the disconnected screen");
assert client != null;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package me.axieum.mcmod.authme.mixin;

import java.util.concurrent.CompletableFuture;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.gen.Accessor;

import com.mojang.authlib.minecraft.UserApiService;
import com.mojang.authlib.yggdrasil.ProfileResult;
import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService;

import net.minecraft.client.MinecraftClient;
Expand All @@ -29,6 +32,15 @@ public interface MinecraftClientAccessor
@Mutable
void setSession(Session session);

/**
* Sets the game profile.
*
* @param future the future of the new game profile
*/
@Accessor
@Mutable
void setGameProfileFuture(CompletableFuture<ProfileResult> future);

/**
* Returns the Minecraft authentication service.
*
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
],
"depends": {
"java": ">=21",
"minecraft": "~1.20.5",
"minecraft": "~1.21",
"fabricloader": ">=0.14.18",
"fabric-lifecycle-events-v1": "*",
"fabric-resource-loader-v0": "*",
Expand Down

0 comments on commit ef410a0

Please sign in to comment.