From 52dd4db7d99297031e4f2a073e5d62d93da35d56 Mon Sep 17 00:00:00 2001 From: Aizistral Date: Tue, 27 Jan 2026 16:22:45 +0100 Subject: [PATCH] Update mixins and code for 1.18.2 --- .../WrappedSocialInteractionsService.java | 41 --------------- .../core/WrappedUserApiService.java | 51 +++++++++++++++++++ .../mixins/MixinMinecraft.java | 16 +++--- .../WrappedSocialInteractionsService.java | 41 --------------- .../core/WrappedUserApiService.java | 51 +++++++++++++++++++ .../mixins/MixinMinecraft.java | 16 +++--- 6 files changed, 118 insertions(+), 98 deletions(-) delete mode 100644 Fabric/src/main/java/com/aizistral/nochatrestrictions/core/WrappedSocialInteractionsService.java create mode 100644 Fabric/src/main/java/com/aizistral/nochatrestrictions/core/WrappedUserApiService.java delete mode 100644 Forge/src/main/java/com/aizistral/nochatrestrictions/core/WrappedSocialInteractionsService.java create mode 100644 Forge/src/main/java/com/aizistral/nochatrestrictions/core/WrappedUserApiService.java diff --git a/Fabric/src/main/java/com/aizistral/nochatrestrictions/core/WrappedSocialInteractionsService.java b/Fabric/src/main/java/com/aizistral/nochatrestrictions/core/WrappedSocialInteractionsService.java deleted file mode 100644 index 1d3d2b1..0000000 --- a/Fabric/src/main/java/com/aizistral/nochatrestrictions/core/WrappedSocialInteractionsService.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.aizistral.nochatrestrictions.core; - -import java.util.UUID; -import com.mojang.authlib.minecraft.SocialInteractionsService; - -public class WrappedSocialInteractionsService implements SocialInteractionsService { - private final SocialInteractionsService service; - - public WrappedSocialInteractionsService(SocialInteractionsService service) { - if (service == null) - throw new NullPointerException("'service' argument cannot be null!"); - - this.service = service; - } - - @Override - public boolean serversAllowed() { - return true; - } - - @Override - public boolean realmsAllowed() { - return true; - } - - @Override - public boolean chatAllowed() { - return true; - } - - @Override - public boolean telemetryAllowed() { - return false; - } - - @Override - public boolean isBlockedPlayer(UUID playerID) { - return this.service.isBlockedPlayer(playerID); - } - -} diff --git a/Fabric/src/main/java/com/aizistral/nochatrestrictions/core/WrappedUserApiService.java b/Fabric/src/main/java/com/aizistral/nochatrestrictions/core/WrappedUserApiService.java new file mode 100644 index 0000000..2206cd8 --- /dev/null +++ b/Fabric/src/main/java/com/aizistral/nochatrestrictions/core/WrappedUserApiService.java @@ -0,0 +1,51 @@ +package com.aizistral.nochatrestrictions.core; + +import java.util.UUID; +import java.util.concurrent.Executor; + +import com.google.common.collect.ImmutableSet; +import com.mojang.authlib.minecraft.TelemetrySession; +import com.mojang.authlib.minecraft.UserApiService; + +public class WrappedUserApiService implements UserApiService { + private static final UserProperties FORCED_PROPERTIES; + + static { + ImmutableSet.Builder flags = ImmutableSet.builder(); + + flags.add(UserFlag.CHAT_ALLOWED); // always let the player access chat + flags.add(UserFlag.SERVERS_ALLOWED); // always let the player open multiplayer menu + flags.add(UserFlag.REALMS_ALLOWED); // always let the player open Realms menu + // flags.add(UserFlag.TELEMETRY_ENABLED); // not adding this for obvious reasons + // flags.add(UserFlag.PROFANITY_FILTER_ENABLED) // not adding this one either + + FORCED_PROPERTIES = new UserProperties(flags.build()); + } + + private final UserApiService service; + + public WrappedUserApiService(UserApiService service) { + this.service = service; + } + + @Override + public UserProperties properties() { + return FORCED_PROPERTIES; + } + + @Override + public boolean isBlockedPlayer(UUID playerID) { + return this.service.isBlockedPlayer(playerID); + } + + @Override + public void refreshBlockList() { + this.service.refreshBlockList(); + } + + @Override + public TelemetrySession newTelemetrySession(Executor executor) { + return TelemetrySession.DISABLED; + } + +} diff --git a/Fabric/src/main/java/com/aizistral/nochatrestrictions/mixins/MixinMinecraft.java b/Fabric/src/main/java/com/aizistral/nochatrestrictions/mixins/MixinMinecraft.java index 86c35d4..4b2b473 100644 --- a/Fabric/src/main/java/com/aizistral/nochatrestrictions/mixins/MixinMinecraft.java +++ b/Fabric/src/main/java/com/aizistral/nochatrestrictions/mixins/MixinMinecraft.java @@ -6,8 +6,8 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import com.aizistral.nochatrestrictions.core.NCRCore; -import com.aizistral.nochatrestrictions.core.WrappedSocialInteractionsService; -import com.mojang.authlib.minecraft.SocialInteractionsService; +import com.aizistral.nochatrestrictions.core.WrappedUserApiService; +import com.mojang.authlib.minecraft.UserApiService; import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService; import net.minecraft.client.Minecraft; @@ -16,14 +16,14 @@ import net.minecraft.client.main.GameConfig; @Mixin(Minecraft.class) public class MixinMinecraft { - @Inject(method = { "func_244735_a", "createSocialInteractions" }, at = @At("RETURN"), cancellable = true) - public void onCreateSocialInteractions(YggdrasilAuthenticationService authService, GameConfig gameConfig, - CallbackInfoReturnable info) { - SocialInteractionsService returnedService = info.getReturnValue(); + @Inject(method = { "m_193585_", "createUserApiService" }, at = @At("RETURN"), cancellable = true) + public void onCreateUserApi(YggdrasilAuthenticationService authService, GameConfig gameConfig, + CallbackInfoReturnable info) { + UserApiService returnedService = info.getReturnValue(); assert returnedService != null; - info.setReturnValue(new WrappedSocialInteractionsService(returnedService)); + info.setReturnValue(new WrappedUserApiService(returnedService)); - NCRCore.LOGGER.info("Successfully supplanted SocialInteractionsService with a wrapped version."); + NCRCore.LOGGER.info("Successfully supplanted UserApiService with a wrapped version."); } } diff --git a/Forge/src/main/java/com/aizistral/nochatrestrictions/core/WrappedSocialInteractionsService.java b/Forge/src/main/java/com/aizistral/nochatrestrictions/core/WrappedSocialInteractionsService.java deleted file mode 100644 index 1d3d2b1..0000000 --- a/Forge/src/main/java/com/aizistral/nochatrestrictions/core/WrappedSocialInteractionsService.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.aizistral.nochatrestrictions.core; - -import java.util.UUID; -import com.mojang.authlib.minecraft.SocialInteractionsService; - -public class WrappedSocialInteractionsService implements SocialInteractionsService { - private final SocialInteractionsService service; - - public WrappedSocialInteractionsService(SocialInteractionsService service) { - if (service == null) - throw new NullPointerException("'service' argument cannot be null!"); - - this.service = service; - } - - @Override - public boolean serversAllowed() { - return true; - } - - @Override - public boolean realmsAllowed() { - return true; - } - - @Override - public boolean chatAllowed() { - return true; - } - - @Override - public boolean telemetryAllowed() { - return false; - } - - @Override - public boolean isBlockedPlayer(UUID playerID) { - return this.service.isBlockedPlayer(playerID); - } - -} diff --git a/Forge/src/main/java/com/aizistral/nochatrestrictions/core/WrappedUserApiService.java b/Forge/src/main/java/com/aizistral/nochatrestrictions/core/WrappedUserApiService.java new file mode 100644 index 0000000..2206cd8 --- /dev/null +++ b/Forge/src/main/java/com/aizistral/nochatrestrictions/core/WrappedUserApiService.java @@ -0,0 +1,51 @@ +package com.aizistral.nochatrestrictions.core; + +import java.util.UUID; +import java.util.concurrent.Executor; + +import com.google.common.collect.ImmutableSet; +import com.mojang.authlib.minecraft.TelemetrySession; +import com.mojang.authlib.minecraft.UserApiService; + +public class WrappedUserApiService implements UserApiService { + private static final UserProperties FORCED_PROPERTIES; + + static { + ImmutableSet.Builder flags = ImmutableSet.builder(); + + flags.add(UserFlag.CHAT_ALLOWED); // always let the player access chat + flags.add(UserFlag.SERVERS_ALLOWED); // always let the player open multiplayer menu + flags.add(UserFlag.REALMS_ALLOWED); // always let the player open Realms menu + // flags.add(UserFlag.TELEMETRY_ENABLED); // not adding this for obvious reasons + // flags.add(UserFlag.PROFANITY_FILTER_ENABLED) // not adding this one either + + FORCED_PROPERTIES = new UserProperties(flags.build()); + } + + private final UserApiService service; + + public WrappedUserApiService(UserApiService service) { + this.service = service; + } + + @Override + public UserProperties properties() { + return FORCED_PROPERTIES; + } + + @Override + public boolean isBlockedPlayer(UUID playerID) { + return this.service.isBlockedPlayer(playerID); + } + + @Override + public void refreshBlockList() { + this.service.refreshBlockList(); + } + + @Override + public TelemetrySession newTelemetrySession(Executor executor) { + return TelemetrySession.DISABLED; + } + +} diff --git a/Forge/src/main/java/com/aizistral/nochatrestrictions/mixins/MixinMinecraft.java b/Forge/src/main/java/com/aizistral/nochatrestrictions/mixins/MixinMinecraft.java index 86c35d4..4b2b473 100644 --- a/Forge/src/main/java/com/aizistral/nochatrestrictions/mixins/MixinMinecraft.java +++ b/Forge/src/main/java/com/aizistral/nochatrestrictions/mixins/MixinMinecraft.java @@ -6,8 +6,8 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import com.aizistral.nochatrestrictions.core.NCRCore; -import com.aizistral.nochatrestrictions.core.WrappedSocialInteractionsService; -import com.mojang.authlib.minecraft.SocialInteractionsService; +import com.aizistral.nochatrestrictions.core.WrappedUserApiService; +import com.mojang.authlib.minecraft.UserApiService; import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService; import net.minecraft.client.Minecraft; @@ -16,14 +16,14 @@ import net.minecraft.client.main.GameConfig; @Mixin(Minecraft.class) public class MixinMinecraft { - @Inject(method = { "func_244735_a", "createSocialInteractions" }, at = @At("RETURN"), cancellable = true) - public void onCreateSocialInteractions(YggdrasilAuthenticationService authService, GameConfig gameConfig, - CallbackInfoReturnable info) { - SocialInteractionsService returnedService = info.getReturnValue(); + @Inject(method = { "m_193585_", "createUserApiService" }, at = @At("RETURN"), cancellable = true) + public void onCreateUserApi(YggdrasilAuthenticationService authService, GameConfig gameConfig, + CallbackInfoReturnable info) { + UserApiService returnedService = info.getReturnValue(); assert returnedService != null; - info.setReturnValue(new WrappedSocialInteractionsService(returnedService)); + info.setReturnValue(new WrappedUserApiService(returnedService)); - NCRCore.LOGGER.info("Successfully supplanted SocialInteractionsService with a wrapped version."); + NCRCore.LOGGER.info("Successfully supplanted UserApiService with a wrapped version."); } }