diff options
| author | Anhgelus Morhtuuzh <william@herges.fr> | 2026-03-17 17:17:25 +0100 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <william@herges.fr> | 2026-03-17 18:06:18 +0100 |
| commit | 8df7794e7413165f972adcaa3516d449265d8aa3 (patch) | |
| tree | fe57a350c4c7e00969730890a7e16f3dc3e104c6 /src/client | |
| parent | 365a7e7906c3623eddef7401b27c1db635439787 (diff) | |
fix(): crash while joining a world
Diffstat (limited to 'src/client')
| -rw-r--r-- | src/client/java/world/anhgelus/molehunt/client/MolehuntClient.java | 39 | ||||
| -rw-r--r-- | src/client/java/world/anhgelus/molehunt/client/mixin/NoCustomizableSkinOverlay.java | 37 |
2 files changed, 49 insertions, 27 deletions
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<ClientInformation> 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() + ) + ); + } } |
