From 43bf4d34274358166841164c56eb36ebbc3f1967 Mon Sep 17 00:00:00 2001 From: luisc Date: Tue, 10 Jun 2025 10:56:25 -0500 Subject: [PATCH] merged separate gui packet calls in the ProfileChangePacket --- .../player/profile/ProfileChangePacket.java | 11 +++++- .../player/profile/ProfileGetInfoPacket.java | 6 ++- .../player/profile/ProfileGetPacket.java | 6 ++- .../gui/player/inventory/GuiProfiles.java | 39 ++++++++++++------- 4 files changed, 43 insertions(+), 19 deletions(-) diff --git a/src/main/java/kamkeel/npcs/network/packets/player/profile/ProfileChangePacket.java b/src/main/java/kamkeel/npcs/network/packets/player/profile/ProfileChangePacket.java index 983e5e990..1c319753a 100644 --- a/src/main/java/kamkeel/npcs/network/packets/player/profile/ProfileChangePacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/player/profile/ProfileChangePacket.java @@ -10,8 +10,10 @@ import kamkeel.npcs.network.PacketChannel; import kamkeel.npcs.network.PacketHandler; import kamkeel.npcs.network.enums.EnumPlayerPacket; import kamkeel.npcs.network.packets.data.ChatAlertPacket; +import kamkeel.npcs.network.packets.data.large.GuiDataPacket; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.CustomNpcsPermissions; import noppes.npcs.config.ConfigMain; @@ -60,8 +62,13 @@ public final class ProfileChangePacket extends AbstractPacket { int slot = in.readInt(); ProfileOperation operation = ProfileController.Instance.changeSlot(player, slot); - ProfileGetPacket.sendProfileNBT(player); - ProfileGetInfoPacket.sendProfileInfo(player); + + NBTTagCompound compound = new NBTTagCompound(); + compound.setBoolean("CHANGE_PACKET", true); + compound.setTag("PROFILE", ProfileGetPacket.profileNBTPayload(player)); + compound.setTag("PROFILE_INFO", ProfileGetInfoPacket.profileInfoPayload(player)); + GuiDataPacket.sendGuiData((EntityPlayerMP) player, compound); + ChatAlertPacket.sendChatAlert((EntityPlayerMP) player, operation.getMessage()); } } diff --git a/src/main/java/kamkeel/npcs/network/packets/player/profile/ProfileGetInfoPacket.java b/src/main/java/kamkeel/npcs/network/packets/player/profile/ProfileGetInfoPacket.java index c4d92d674..25cb641a0 100644 --- a/src/main/java/kamkeel/npcs/network/packets/player/profile/ProfileGetInfoPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/player/profile/ProfileGetInfoPacket.java @@ -57,6 +57,10 @@ public final class ProfileGetInfoPacket extends AbstractPacket { } public static void sendProfileInfo(EntityPlayer player) { + GuiDataPacket.sendGuiData((EntityPlayerMP) player, profileInfoPayload(player)); + } + + public static NBTTagCompound profileInfoPayload(EntityPlayer player) { NBTTagCompound compound = new NBTTagCompound(); compound.setBoolean("PROFILE_INFO", true); NBTTagList slotList = new NBTTagList(); @@ -75,7 +79,7 @@ public final class ProfileGetInfoPacket extends AbstractPacket { } compound.setTag("SLOTS", slotList); } - GuiDataPacket.sendGuiData((EntityPlayerMP) player, compound); + return compound; } public static HashMap> readProfileInfo(NBTTagCompound compound) { diff --git a/src/main/java/kamkeel/npcs/network/packets/player/profile/ProfileGetPacket.java b/src/main/java/kamkeel/npcs/network/packets/player/profile/ProfileGetPacket.java index 6ef9cdefe..2b7e9801f 100644 --- a/src/main/java/kamkeel/npcs/network/packets/player/profile/ProfileGetPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/player/profile/ProfileGetPacket.java @@ -50,9 +50,13 @@ public final class ProfileGetPacket extends AbstractPacket { } public static void sendProfileNBT(EntityPlayer player) { + GuiDataPacket.sendGuiData((EntityPlayerMP) player, profileNBTPayload(player)); + } + + public static NBTTagCompound profileNBTPayload(EntityPlayer player) { Profile profile = ProfileController.Instance.getProfile(player); NBTTagCompound compound = profile.writeToNBT(); compound.setBoolean("PROFILE", true); - GuiDataPacket.sendGuiData((EntityPlayerMP) player, compound); + return compound; } } diff --git a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiProfiles.java b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiProfiles.java index 0a9f1be87..47ec2c1ef 100644 --- a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiProfiles.java +++ b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiProfiles.java @@ -335,22 +335,15 @@ public class GuiProfiles extends GuiCNPCInventory implements ISubGuiListener, IC public void setGuiData(NBTTagCompound compound) { this.slot = null; - if (compound.hasKey("PROFILE")) { - // Load Profile - this.profile = new Profile(mc.thePlayer, compound); - this.data = new HashMap<>(); - String currentSlot = "\u00A7e"; - String otherSlot = "\u00A7f"; - for (ISlot slot1 : profile.getSlots().values()) { - String name = slot1.getId() + " - " + slot1.getName(); - if (profile.currentSlotId == slot1.getId()) - name = currentSlot + name; - else - name = otherSlot + name; - this.data.put(name, slot1.getId()); - } + if (compound.hasKey("CHANGE_PACKET")) { + this.readProfileCompound( + compound.getCompoundTag("PROFILE")); + this.slotInfoMap = ProfileGetInfoPacket.readProfileInfo( + compound.getCompoundTag("PROFILE_INFO")); + } else if (compound.hasKey("PROFILE")) { + this.readProfileCompound(compound); } else if (compound.hasKey("PROFILE_INFO")) { - slotInfoMap = ProfileGetInfoPacket.readProfileInfo(compound); + this.slotInfoMap = ProfileGetInfoPacket.readProfileInfo(compound); } if (scroll != null) { scroll.setSelected(""); @@ -358,6 +351,22 @@ public class GuiProfiles extends GuiCNPCInventory implements ISubGuiListener, IC initGui(); } + private void readProfileCompound(NBTTagCompound compound) { + // Load Profile + this.profile = new Profile(mc.thePlayer, compound); + this.data = new HashMap<>(); + String currentSlot = "\u00A7e"; + String otherSlot = "\u00A7f"; + for (ISlot slot1 : profile.getSlots().values()) { + String name = slot1.getId() + " - " + slot1.getName(); + if (profile.currentSlotId == slot1.getId()) + name = currentSlot + name; + else + name = otherSlot + name; + this.data.put(name, slot1.getId()); + } + } + /** * Handles mouse clicks for the scrollbar. */