From dfbc5bbfd20a22edb2596b4d73248df57a4cce20 Mon Sep 17 00:00:00 2001 From: anhgelus Date: Sat, 24 Aug 2024 13:05:11 +0000 Subject: feat(network): send game state to client and disable mixins when game is not launched --- .../java/world/anhgelus/molehunt/client/MolehuntClient.java | 12 ++++++++++++ .../world/anhgelus/molehunt/client/mixin/NoNametags.java | 2 +- .../anhgelus/molehunt/client/mixin/NoPlayerListHud.java | 2 +- .../java/world/anhgelus/molehunt/client/mixin/NoSkin.java | 2 +- 4 files changed, 15 insertions(+), 3 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 1f92573..c8a4d95 100644 --- a/src/client/java/world/anhgelus/molehunt/client/MolehuntClient.java +++ b/src/client/java/world/anhgelus/molehunt/client/MolehuntClient.java @@ -3,6 +3,7 @@ package world.anhgelus.molehunt.client; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import world.anhgelus.molehunt.config.ConfigPayload; +import world.anhgelus.molehunt.game.GamePayload; public class MolehuntClient implements ClientModInitializer { @@ -10,6 +11,8 @@ public class MolehuntClient implements ClientModInitializer { private static boolean SHOW_NAMETAGS = false; private static boolean SHOW_TAB = false; + private static boolean GAME_STARTED = false; + @Override public void onInitializeClient() { ClientPlayNetworking.registerGlobalReceiver(ConfigPayload.ID, (payload, context) -> { @@ -19,6 +22,11 @@ public class MolehuntClient implements ClientModInitializer { SHOW_TAB = payload.showTab(); }); }); + ClientPlayNetworking.registerGlobalReceiver(GamePayload.ID, (payload, context) -> { + context.client().execute(() -> { + GAME_STARTED = payload.gameLaunched(); + }); + }); } public static boolean showSkins() { @@ -32,4 +40,8 @@ public class MolehuntClient implements ClientModInitializer { public static boolean showTab() { return SHOW_TAB; } + + public static boolean gameStarted() { + return GAME_STARTED; + } } diff --git a/src/client/java/world/anhgelus/molehunt/client/mixin/NoNametags.java b/src/client/java/world/anhgelus/molehunt/client/mixin/NoNametags.java index 3482abb..7f334a0 100644 --- a/src/client/java/world/anhgelus/molehunt/client/mixin/NoNametags.java +++ b/src/client/java/world/anhgelus/molehunt/client/mixin/NoNametags.java @@ -15,7 +15,7 @@ import world.anhgelus.molehunt.client.MolehuntClient; public class NoNametags { @Inject(at = @At("HEAD"), method = "render", cancellable = true) private void renderLabelOrNot(T entity, float yaw, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci) { - if (!(entity instanceof PlayerEntity) || MolehuntClient.showNameTags()) return; + if (!(entity instanceof PlayerEntity) || MolehuntClient.showNameTags() || !MolehuntClient.gameStarted()) return; ci.cancel(); } } \ No newline at end of file diff --git a/src/client/java/world/anhgelus/molehunt/client/mixin/NoPlayerListHud.java b/src/client/java/world/anhgelus/molehunt/client/mixin/NoPlayerListHud.java index 00308ea..4473b12 100644 --- a/src/client/java/world/anhgelus/molehunt/client/mixin/NoPlayerListHud.java +++ b/src/client/java/world/anhgelus/molehunt/client/mixin/NoPlayerListHud.java @@ -11,7 +11,7 @@ import world.anhgelus.molehunt.client.MolehuntClient; public class NoPlayerListHud { @Inject(at = @At("HEAD"), method = "render", cancellable = true) public void render(CallbackInfo ci) { - if (MolehuntClient.showTab()) return; + if (MolehuntClient.showTab() || !MolehuntClient.gameStarted()) return; ci.cancel(); } } diff --git a/src/client/java/world/anhgelus/molehunt/client/mixin/NoSkin.java b/src/client/java/world/anhgelus/molehunt/client/mixin/NoSkin.java index 775d789..6638c1b 100644 --- a/src/client/java/world/anhgelus/molehunt/client/mixin/NoSkin.java +++ b/src/client/java/world/anhgelus/molehunt/client/mixin/NoSkin.java @@ -14,7 +14,7 @@ import world.anhgelus.molehunt.client.MolehuntClient; public class NoSkin { @Inject(at = @At("HEAD"), method = "getSkinTextures", cancellable = true) public void getSkin(CallbackInfoReturnable cir) { - if (MolehuntClient.showSkins()) return; + if (MolehuntClient.showSkins() || !MolehuntClient.gameStarted()) return; cir.setReturnValue(new SkinTextures( Identifier.of(Molehunt.MOD_ID, "textures/skin.png"), null, -- cgit v1.2.3