aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/java/world/anhgelus/molehunt/client/MolehuntClient.java39
-rw-r--r--src/client/java/world/anhgelus/molehunt/client/mixin/NoCustomizableSkinOverlay.java37
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()
+ )
+ );
+ }
}