From 516d8842212bf972eaf511a86e5a3ca3dbf01f5f Mon Sep 17 00:00:00 2001 From: Meredith Espinosa Date: Thu, 16 May 2019 19:27:39 -0700 Subject: [PATCH] update to a working crochet version, fix level sync --- build.gradle | 6 ++-- .../skillcheck/util/SkillCheckNetworking.java | 28 +++++++++++++++---- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/build.gradle b/build.gradle index d7ba89e..69c65be 100644 --- a/build.gradle +++ b/build.gradle @@ -34,7 +34,7 @@ if(rootProject.file('private.gradle').exists()) { //Publishing details archivesBaseName = "skillcheck" group = "io.github.cottonmc" -version = "1.0.4+1.14.1" +version = "1.0.5+1.14.1" minecraft { refmapName = 'mixins.skillcheck.refmap.json' @@ -58,8 +58,8 @@ dependencies { modCompile "io.github.prospector.modmenu:ModMenu:1.5.3-84" modCompile "io.github.cottonmc:cotton:0.6.6+1.14.1-SNAPSHOT" include "io.github.cottonmc:cotton:0.6.6+1.14.1-SNAPSHOT" - modCompile "crochet:Crochet:1.0.2" - include "crochet:Crochet:1.0.2" + modCompile "crochet:Crochet:1.0.3:1" + include "crochet:Crochet:1.0.3:1" modCompile "cloth-config:ClothConfig:0.2.1.14" include "cloth-config:ClothConfig:0.2.1.14" diff --git a/src/main/java/io/github/cottonmc/skillcheck/util/SkillCheckNetworking.java b/src/main/java/io/github/cottonmc/skillcheck/util/SkillCheckNetworking.java index 5e11db9..73161f9 100644 --- a/src/main/java/io/github/cottonmc/skillcheck/util/SkillCheckNetworking.java +++ b/src/main/java/io/github/cottonmc/skillcheck/util/SkillCheckNetworking.java @@ -6,9 +6,12 @@ import io.netty.buffer.Unpooled; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.fabricmc.fabric.api.network.ClientSidePacketRegistry; import net.fabricmc.fabric.api.network.ServerSidePacketRegistry; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.network.packet.CustomPayloadS2CPacket; import net.minecraft.container.Container; +import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.packet.CustomPayloadC2SPacket; import net.minecraft.util.Identifier; import net.minecraft.util.PacketByteBuf; @@ -17,22 +20,29 @@ public class SkillCheckNetworking { public static final Identifier SYNC_SELECTION = new Identifier(SkillCheck.MOD_ID, "sync_selection"); public static final Identifier SYNC_LEVELUP = new Identifier(SkillCheck.MOD_ID, "sync_levelup"); + public static final Identifier SYNC_PLAYER_LEVEL = new Identifier(SkillCheck.MOD_ID, "sync_player_level"); public static void init() { - ServerSidePacketRegistry.INSTANCE.register(SYNC_SELECTION, ((packetContext, packetByteBuf) -> { + ServerSidePacketRegistry.INSTANCE.register(SYNC_SELECTION, (packetContext, packetByteBuf) -> { Container container = packetContext.getPlayer().container; if (container instanceof CharacterSheetContainer) { int index = packetByteBuf.readInt(); CharacterSheetContainer table = (CharacterSheetContainer)container; table.setCurrentSkill(index); } - })); - ServerSidePacketRegistry.INSTANCE.register(SYNC_LEVELUP, (((packetContext, packetByteBuf) -> { + }); + ServerSidePacketRegistry.INSTANCE.register(SYNC_LEVELUP, (packetContext, packetByteBuf) -> { Identifier id = packetByteBuf.readIdentifier(); int xpCost = packetByteBuf.readInt(); - if (!packetContext.getPlayer().isCreative()) packetContext.getPlayer().experienceLevel -= xpCost; + if (!packetContext.getPlayer().isCreative()) { + packetContext.getPlayer().experienceLevel -= xpCost; + setSyncPlayerLevel(packetContext.getPlayer().experienceLevel, (ServerPlayerEntity)packetContext.getPlayer()); + } ClassManager.levelUp(packetContext.getPlayer(), id); - }))); + }); + ClientSidePacketRegistry.INSTANCE.register(SYNC_PLAYER_LEVEL, (packetContext, packetByteBuf) -> { + packetContext.getPlayer().experienceLevel = packetByteBuf.readInt(); + }); } @Environment(EnvType.CLIENT) @@ -42,10 +52,18 @@ public static void syncSelection(int index) { MinecraftClient.getInstance().getNetworkHandler().getClientConnection().send(new CustomPayloadC2SPacket(SYNC_SELECTION, buf)); } + @Environment(EnvType.CLIENT) public static void syncLevelup(Identifier id, int xpCost) { PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer()); buf.writeIdentifier(id); buf.writeInt(xpCost); MinecraftClient.getInstance().getNetworkHandler().getClientConnection().send(new CustomPayloadC2SPacket(SYNC_LEVELUP, buf)); } + + @Environment(EnvType.CLIENT) + public static void setSyncPlayerLevel(int level, ServerPlayerEntity player) { + PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer()); + buf.writeInt(level); + player.networkHandler.sendPacket(new CustomPayloadS2CPacket(SYNC_PLAYER_LEVEL, buf)); + } } \ No newline at end of file