aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoranhgelus <anhgelus.morhtuuzh@proton.me>2024-08-23 13:41:22 +0000
committeranhgelus <anhgelus.morhtuuzh@proton.me>2024-08-23 13:41:22 +0000
commit7f6043a230b83cff57126625cd8b19063c85a599 (patch)
treec78c1d9cba4e6512220966399333a78578416078
parenta93a8da00657da855a99ca6b0a842bbf30481d90 (diff)
feat(config): packet sending config to client
-rw-r--r--src/client/java/world/anhgelus/molehunt/client/MolehuntClient.java35
-rw-r--r--src/client/java/world/anhgelus/molehunt/client/mixin/NoSkin.java4
-rw-r--r--src/main/java/world/anhgelus/molehunt/Molehunt.java4
-rw-r--r--src/main/java/world/anhgelus/molehunt/config/ConfigPayload.java25
4 files changed, 57 insertions, 11 deletions
diff --git a/src/client/java/world/anhgelus/molehunt/client/MolehuntClient.java b/src/client/java/world/anhgelus/molehunt/client/MolehuntClient.java
index e6de219..5f6b735 100644
--- a/src/client/java/world/anhgelus/molehunt/client/MolehuntClient.java
+++ b/src/client/java/world/anhgelus/molehunt/client/MolehuntClient.java
@@ -1,20 +1,37 @@
package world.anhgelus.molehunt.client;
-import com.mojang.authlib.GameProfile;
import net.fabricmc.api.ClientModInitializer;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.UUID;
+import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
+import world.anhgelus.molehunt.config.ConfigPayload;
public class MolehuntClient implements ClientModInitializer {
- public static final String MOD_ID = "molehunt";
- public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
-
- public final static GameProfile ANONYMOUS_PROFILE = new GameProfile(UUID.fromString("015f3266-4e0a-412e-9b80-1ca76af79453"), "Molehunt");
+ private static boolean SHOW_SKINS = false;
+ private static boolean SHOW_NAMETAGS = false;
+ private static boolean SHOW_TAB = false;
@Override
public void onInitializeClient() {
+ ClientPlayNetworking.registerGlobalReceiver(ConfigPayload.ID, (payload, context) -> {
+ try (final var client = context.client()) {
+ client.execute(() -> {
+ SHOW_SKINS = payload.showSkins();
+ SHOW_NAMETAGS = payload.showNametag();
+ SHOW_TAB = payload.showNametag();
+ });
+ }
+ });
+ }
+
+ public static boolean showSkins() {
+ return SHOW_SKINS;
+ }
+
+ public static boolean showNameTags() {
+ return SHOW_NAMETAGS;
+ }
+
+ public static boolean showTab() {
+ return SHOW_TAB;
}
}
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 edbfd15..425ded7 100644
--- a/src/client/java/world/anhgelus/molehunt/client/mixin/NoSkin.java
+++ b/src/client/java/world/anhgelus/molehunt/client/mixin/NoSkin.java
@@ -7,14 +7,14 @@ import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
-import world.anhgelus.molehunt.client.MolehuntClient;
+import world.anhgelus.molehunt.Molehunt;
@Mixin(AbstractClientPlayerEntity.class)
public class NoSkin {
@Inject(at = @At("HEAD"), method = "getSkinTextures", cancellable = true)
public void getSkin(CallbackInfoReturnable<SkinTextures> cir) {
cir.setReturnValue(new SkinTextures(
- Identifier.of(MolehuntClient.MOD_ID, "textures/skin.png"),
+ Identifier.of(Molehunt.MOD_ID, "textures/skin.png"),
null,
null,
null,
diff --git a/src/main/java/world/anhgelus/molehunt/Molehunt.java b/src/main/java/world/anhgelus/molehunt/Molehunt.java
index 5df63b1..140ab14 100644
--- a/src/main/java/world/anhgelus/molehunt/Molehunt.java
+++ b/src/main/java/world/anhgelus/molehunt/Molehunt.java
@@ -7,6 +7,7 @@ import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.entity.event.v1.ServerLivingEntityEvents;
import net.fabricmc.fabric.api.entity.event.v1.ServerPlayerEvents;
import net.fabricmc.fabric.api.message.v1.ServerMessageEvents;
+import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
import net.minecraft.network.packet.s2c.play.OverlayMessageS2CPacket;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
@@ -15,6 +16,7 @@ import net.minecraft.world.GameMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import world.anhgelus.molehunt.config.Config;
+import world.anhgelus.molehunt.config.ConfigPayload;
import java.util.HashMap;
@@ -93,5 +95,7 @@ public class Molehunt implements ModInitializer {
if (game.getMoles().contains(oldPlayer)) game.updateMole(oldPlayer, newPlayer);
newPlayer.changeGameMode(GameMode.SPECTATOR);
});
+
+ PayloadTypeRegistry.playS2C().register(ConfigPayload.ID, ConfigPayload.CODEC);
}
}
diff --git a/src/main/java/world/anhgelus/molehunt/config/ConfigPayload.java b/src/main/java/world/anhgelus/molehunt/config/ConfigPayload.java
new file mode 100644
index 0000000..a884c9a
--- /dev/null
+++ b/src/main/java/world/anhgelus/molehunt/config/ConfigPayload.java
@@ -0,0 +1,25 @@
+package world.anhgelus.molehunt.config;
+
+import net.minecraft.network.RegistryByteBuf;
+import net.minecraft.network.codec.PacketCodec;
+import net.minecraft.network.codec.PacketCodecs;
+import net.minecraft.network.packet.CustomPayload;
+import net.minecraft.util.Identifier;
+import world.anhgelus.molehunt.Molehunt;
+
+public record ConfigPayload(boolean showNametag, boolean showSkins, boolean showTab) implements CustomPayload {
+ public static final Identifier CONFIG_PACKET_ID = Identifier.of(Molehunt.MOD_ID, "config");
+
+ public static final CustomPayload.Id<ConfigPayload> ID = new CustomPayload.Id<>(CONFIG_PACKET_ID);
+ public static final PacketCodec<RegistryByteBuf, ConfigPayload> CODEC = PacketCodec.tuple(
+ PacketCodecs.BOOL, ConfigPayload::showNametag,
+ PacketCodecs.BOOL, ConfigPayload::showSkins,
+ PacketCodecs.BOOL, ConfigPayload::showTab,
+ ConfigPayload::new
+ );
+
+ @Override
+ public Id<? extends CustomPayload> getId() {
+ return ID;
+ }
+}