From 8df7794e7413165f972adcaa3516d449265d8aa3 Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Tue, 17 Mar 2026 17:17:25 +0100 Subject: fix(): crash while joining a world --- .../anhgelus/molehunt/client/MolehuntClient.java | 39 +++++++--------------- .../client/mixin/NoCustomizableSkinOverlay.java | 37 ++++++++++++++++++++ 2 files changed, 49 insertions(+), 27 deletions(-) (limited to 'src/client') diff --git a/src/client/java/world/anhgelus/molehunt/client/MolehuntClient.java b/src/client/java/world/anhgelus/molehunt/client/MolehuntClient.java index 79ff436..18aca76 100644 --- a/src/client/java/world/anhgelus/molehunt/client/MolehuntClient.java +++ b/src/client/java/world/anhgelus/molehunt/client/MolehuntClient.java @@ -1,15 +1,17 @@ package world.anhgelus.molehunt.client; import net.fabricmc.api.ClientModInitializer; -import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; -import net.minecraft.client.Minecraft; -import net.minecraft.world.entity.player.PlayerModelPart; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import world.anhgelus.molehunt.Molehunt; import world.anhgelus.molehunt.config.ConfigPayload; import world.anhgelus.molehunt.game.GamePayload; public class MolehuntClient implements ClientModInitializer { + public static final Logger LOGGER = LoggerFactory.getLogger(Molehunt.MOD_ID + " - client"); + private static boolean SHOW_SKINS = false; private static boolean SHOW_NAMETAGS = false; private static boolean SHOW_TAB = false; @@ -32,33 +34,16 @@ public class MolehuntClient implements ClientModInitializer { return GAME_STARTED; } - public static void updateClient(Minecraft client) { - if (SHOW_SKINS) return; - var options = client.options; - - options.setModelPart(PlayerModelPart.CAPE, true); - options.setModelPart(PlayerModelPart.HAT, true); - options.setModelPart(PlayerModelPart.JACKET, true); - options.setModelPart(PlayerModelPart.LEFT_SLEEVE, true); - options.setModelPart(PlayerModelPart.RIGHT_SLEEVE, true); - options.setModelPart(PlayerModelPart.LEFT_PANTS_LEG, true); - options.setModelPart(PlayerModelPart.RIGHT_PANTS_LEG, true); - } - @Override public void onInitializeClient() { + LOGGER.info("Initializing client"); ClientPlayNetworking.registerGlobalReceiver(ConfigPayload.ID, (payload, context) -> { - try (final var client = context.client()) { - SHOW_SKINS = payload.showSkins(); - SHOW_NAMETAGS = payload.showNametags(); - SHOW_TAB = payload.showTab(); - - updateClient(client); - } + SHOW_SKINS = payload.showSkins(); + SHOW_NAMETAGS = payload.showNametags(); + SHOW_TAB = payload.showTab(); + }); + ClientPlayNetworking.registerGlobalReceiver(GamePayload.ID, (payload, context) -> { + GAME_STARTED = payload.gameLaunched(); }); - ClientPlayNetworking.registerGlobalReceiver(GamePayload.ID, (payload, context) -> GAME_STARTED = payload.gameLaunched()); - - // Needed because else `client.options` is null - ClientLifecycleEvents.CLIENT_STARTED.register(MolehuntClient::updateClient); } } diff --git a/src/client/java/world/anhgelus/molehunt/client/mixin/NoCustomizableSkinOverlay.java b/src/client/java/world/anhgelus/molehunt/client/mixin/NoCustomizableSkinOverlay.java index bdba025..c394dd3 100644 --- a/src/client/java/world/anhgelus/molehunt/client/mixin/NoCustomizableSkinOverlay.java +++ b/src/client/java/world/anhgelus/molehunt/client/mixin/NoCustomizableSkinOverlay.java @@ -1,18 +1,55 @@ package world.anhgelus.molehunt.client.mixin; +import net.minecraft.client.Minecraft; import net.minecraft.client.Options; +import net.minecraft.server.level.ClientInformation; import net.minecraft.world.entity.player.PlayerModelPart; 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; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import world.anhgelus.molehunt.client.MolehuntClient; @Mixin(Options.class) public abstract class NoCustomizableSkinOverlay { + @Unique + private static int fullParts; + + static { + for (PlayerModelPart part : PlayerModelPart.values()) { + fullParts |= part.getMask(); + } + } + + @Shadow + protected Minecraft minecraft; + @Inject(at = @At("HEAD"), method = "setModelPart", cancellable = true) public void togglePlayerModelPart(PlayerModelPart part, boolean enabled, CallbackInfo ci) { if (MolehuntClient.showSkins()) return; ci.cancel(); } + + @Inject(at = @At("RETURN"), method = "buildPlayerInformation", cancellable = true) + public void buildPlayerInformation(CallbackInfoReturnable cir) { + if (MolehuntClient.showSkins()) return; + final var opts = (Options) (Object) this; + + cir.setReturnValue( + new ClientInformation( + opts.languageCode, + opts.renderDistance().get(), + opts.chatVisibility().get(), + opts.chatColors().get(), + fullParts, + opts.mainHand().get(), + this.minecraft.isTextFilteringEnabled(), + opts.allowServerListing().get(), + opts.particles().get() + ) + ); + } } -- cgit v1.2.3