diff --git a/src/main/java/kamkeel/npcs/controllers/SyncMaster.java b/src/main/java/kamkeel/npcs/controllers/SyncMaster.java index 7b9048210..3b166459e 100644 --- a/src/main/java/kamkeel/npcs/controllers/SyncMaster.java +++ b/src/main/java/kamkeel/npcs/controllers/SyncMaster.java @@ -65,7 +65,7 @@ public class SyncMaster { NBTTagCompound compound = new NBTTagCompound(); NBTTagList categoryList = new NBTTagList(); for(DialogCategory category : DialogController.Instance.categories.values()){ - NBTTagCompound questCompound = new NBTTagCompound();; + NBTTagCompound questCompound = new NBTTagCompound(); NBTTagList dialogList = new NBTTagList(); for(int dialogID : category.dialogs.keySet()){ Dialog quest = category.dialogs.get(dialogID); @@ -73,11 +73,30 @@ public class SyncMaster { } questCompound.setTag("Data", dialogList); questCompound.setTag("CatNBT", category.writeSmallNBT(new NBTTagCompound())); + categoryList.appendTag(questCompound); } compound.setTag("DialogCategories", categoryList); return compound; } + public static NBTTagCompound questCategoriesNBT(){ + NBTTagCompound compound = new NBTTagCompound(); + NBTTagList categoryList = new NBTTagList(); + for(QuestCategory category : QuestController.Instance.categories.values()){ + NBTTagCompound questCompound = new NBTTagCompound();; + NBTTagList questList = new NBTTagList(); + for(int questID : category.quests.keySet()){ + Quest quest = category.quests.get(questID); + questList.appendTag(quest.writeToNBT(new NBTTagCompound())); + } + questCompound.setTag("Data", questList); + questCompound.setTag("CatNBT", category.writeSmallNBT(new NBTTagCompound())); + categoryList.appendTag(questCompound); + } + compound.setTag("QuestCategories", categoryList); + return compound; + } + public static void syncPlayerData(EntityPlayerMP player, boolean update){ PlayerData data = PlayerData.get(player); if(data != null){ @@ -125,23 +144,6 @@ public class SyncMaster { )); } - public static NBTTagCompound questCategoriesNBT(){ - NBTTagCompound compound = new NBTTagCompound(); - NBTTagList categoryList = new NBTTagList(); - for(QuestCategory category : QuestController.Instance.categories.values()){ - NBTTagCompound questCompound = new NBTTagCompound();; - NBTTagList questList = new NBTTagList(); - for(int questID : category.quests.keySet()){ - Quest quest = category.quests.get(questID); - questList.appendTag(quest.writeToNBT(new NBTTagCompound())); - } - questCompound.setTag("Data", questList); - questCompound.setTag("CatNBT", category.writeSmallNBT(new NBTTagCompound())); - } - compound.setTag("QuestCategories", categoryList); - return compound; - } - @SideOnly(Side.CLIENT) public static void clientSync(EnumSyncType enumSyncType, NBTTagCompound fullCompound) { switch (enumSyncType){ diff --git a/src/main/java/kamkeel/npcs/network/PacketHandler.java b/src/main/java/kamkeel/npcs/network/PacketHandler.java index 80fee9beb..6ef7210e2 100644 --- a/src/main/java/kamkeel/npcs/network/PacketHandler.java +++ b/src/main/java/kamkeel/npcs/network/PacketHandler.java @@ -107,8 +107,10 @@ public final class PacketHandler { } catch (IndexOutOfBoundsException e) { LogWriter.error("Error: IndexOutOfBoundsException in handlePacket: " + e.getMessage()); + e.printStackTrace(); } catch (Exception e) { LogWriter.error("Error: Exception in handlePacket: " + e.getMessage()); + e.printStackTrace(); } } diff --git a/src/main/java/kamkeel/npcs/network/packets/client/large/sync/LargeSyncPacket.java b/src/main/java/kamkeel/npcs/network/packets/client/large/sync/LargeSyncPacket.java index 617188531..250fdfca2 100644 --- a/src/main/java/kamkeel/npcs/network/packets/client/large/sync/LargeSyncPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/client/large/sync/LargeSyncPacket.java @@ -12,9 +12,12 @@ import kamkeel.npcs.network.enums.EnumSyncAction; import kamkeel.npcs.network.enums.EnumSyncType; import kamkeel.npcs.util.ByteBufUtils; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.CustomNpcs; +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; import java.io.IOException; /** @@ -60,7 +63,7 @@ public final class LargeSyncPacket extends LargeAbstractPacket { // 3) Optional Category ID buffer.writeInt(operationID); // 4) Write the NBTTagCompound - ByteBufUtils.writeNBT(buffer, syncData); + ByteBufUtils.writeBigNBT(buffer, syncData); // Copy the buffer’s readable bytes into a byte[] byte[] bytes = new byte[buffer.readableBytes()]; @@ -80,7 +83,7 @@ public final class LargeSyncPacket extends LargeAbstractPacket { EnumSyncType type = EnumSyncType.values()[syncTypeOrdinal]; EnumSyncAction action = EnumSyncAction.values()[syncActionOrdinal]; - NBTTagCompound tag = ByteBufUtils.readNBT(data); + NBTTagCompound tag = ByteBufUtils.readBigNBT(data); // Now do your client-side logic (similar to your old clientSync() or clientSyncUpdate() approach) handleSyncPacketClient(type, action, categoryID, tag); diff --git a/src/main/java/kamkeel/npcs/util/ByteBufUtils.java b/src/main/java/kamkeel/npcs/util/ByteBufUtils.java index 0c7bfa779..06b512228 100644 --- a/src/main/java/kamkeel/npcs/util/ByteBufUtils.java +++ b/src/main/java/kamkeel/npcs/util/ByteBufUtils.java @@ -9,6 +9,8 @@ import net.minecraft.network.PacketBuffer; import net.minecraft.village.MerchantRecipeList; import noppes.npcs.LogWriter; +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; import java.io.IOException; import java.util.Arrays; import java.util.List; @@ -100,6 +102,19 @@ public class ByteBufUtils extends cpw.mods.fml.common.network.ByteBufUtils { return CompressedStreamTools.func_152457_a(bytes, new NBTSizeTracker(2097152L)); } + public static void writeBigNBT(ByteBuf buffer, NBTTagCompound compound) throws IOException { + byte[] bytes = CompressedStreamTools.compress(compound); + buffer.writeInt(bytes.length); + buffer.writeBytes(bytes); + } + + public static NBTTagCompound readBigNBT(ByteBuf buffer) throws IOException { + int length = buffer.readInt(); + byte[] bytes = new byte[length]; + buffer.readBytes(bytes); + return CompressedStreamTools.func_152457_a(bytes, new NBTSizeTracker(10485760L)); + } + public static void writeString(ByteBuf buffer, String s){ byte[] bytes = s.getBytes(Charsets.UTF_8); buffer.writeShort((short)bytes.length);