mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-22 07:22:20 +00:00
Fix Player Quest Data being too Large
This commit is contained in:
1 parent
0fa1d8ffa4
commit
c8e1855da6
8 files changed
+95
-16
No files matched your search
@@ -6,6 +6,8 @@ import net.minecraft.client.audio.PositionedSoundRecord;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTSizeTracker;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
@@ -30,6 +32,7 @@ import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.scripted.ScriptParticle;
|
||||
import org.lwjgl.Sys;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
@@ -326,4 +329,38 @@ public class NoppesUtil {
|
||||
public static void isGUIOpen(boolean isGUIOpen) {
|
||||
Client.sendData(EnumPacketServer.IsGuiOpen, isGUIOpen);
|
||||
}
|
||||
|
||||
|
||||
private static byte[] accumulatedData = new byte[0];
|
||||
public static void handleLargeData(byte[] chunk) {
|
||||
// Append the chunk to the accumulated data
|
||||
accumulatedData = concatByteArrays(accumulatedData, chunk);
|
||||
}
|
||||
|
||||
public static void handlePlayerDataEnd(boolean sync) {
|
||||
NBTTagCompound compound;
|
||||
try {
|
||||
compound = CompressedStreamTools.func_152457_a(accumulatedData, new NBTSizeTracker(2097152L));
|
||||
if(sync){
|
||||
ClientCacheHandler.playerData.setSyncNBT(compound);
|
||||
}
|
||||
else {
|
||||
ClientCacheHandler.playerData.setNBT(compound);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
} finally {
|
||||
// Reset the accumulated data after processing
|
||||
accumulatedData = new byte[0];
|
||||
}
|
||||
}
|
||||
|
||||
// Utility method to concatenate two byte arrays
|
||||
private static byte[] concatByteArrays(byte[] a, byte[] b) {
|
||||
byte[] result = new byte[a.length + b.length];
|
||||
System.arraycopy(a, 0, result, 0, a.length);
|
||||
System.arraycopy(b, 0, result, a.length, b.length);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -112,15 +112,20 @@ public class PacketHandlerClient extends PacketHandlerServer{
|
||||
RecipeController.Instance.anvilRecipes = RecipeController.syncRecipes;
|
||||
RecipeController.syncRecipes = new HashMap<Integer, RecipeCarpentry>();
|
||||
}
|
||||
else if(type == EnumPacketClient.LARGE_NBT_PART){
|
||||
byte[] chunk = new byte[buffer.readShort()];
|
||||
buffer.readBytes(chunk);
|
||||
NoppesUtil.handleLargeData(chunk);
|
||||
}
|
||||
else if(type == EnumPacketClient.SYNC_PLAYER){
|
||||
boolean sync = buffer.readBoolean();
|
||||
NoppesUtil.handlePlayerDataEnd(sync);
|
||||
}
|
||||
else if(type == EnumPacketClient.SYNC_ADD || type == EnumPacketClient.SYNC_END){
|
||||
int synctype = buffer.readInt();
|
||||
NBTTagCompound compound = Server.readNBT(buffer);
|
||||
|
||||
SyncController.clientSync(synctype, compound, type == EnumPacketClient.SYNC_END);
|
||||
|
||||
if(synctype == SyncType.PLAYER_DATA){
|
||||
ClientCacheHandler.playerData.setNBT(compound);
|
||||
}
|
||||
}
|
||||
else if(type == EnumPacketClient.SYNC_UPDATE){
|
||||
int synctype = buffer.readInt();
|
||||
|
||||
Reference in new issue
Block a user