mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-18 12:39:05 +00:00
DBC FORM SYNC
This commit is contained in:
1 parent
bb0d90f754
commit
4590275695
5 files changed
+46
-2
No files matched your search
@@ -866,6 +866,27 @@ public class NoppesUtilServer {
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendDBCCompound(EntityPlayerMP player, NBTTagCompound compound) {
|
||||
try {
|
||||
byte[] bytes = CompressedStreamTools.compress(compound);
|
||||
|
||||
// Split byte array into chunks and send each chunk
|
||||
int chunkSize = 16000;
|
||||
int totalChunks = (int) Math.ceil((double) bytes.length / chunkSize);
|
||||
for (int i = 0; i < totalChunks; i++) {
|
||||
int start = i * chunkSize;
|
||||
int length = Math.min(bytes.length - start, chunkSize);
|
||||
byte[] chunk = new byte[length];
|
||||
System.arraycopy(bytes, start, chunk, 0, length);
|
||||
Server.sendData(player, EnumPacketClient.LARGE_NBT_PART, (Object) chunk);
|
||||
}
|
||||
// Send end packet
|
||||
Server.sendData(player, EnumPacketClient.DBC_FORM);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static boolean isOp(EntityPlayer player) {
|
||||
return MinecraftServer.getServer().getConfigurationManager().func_152596_g(player.getGameProfile());
|
||||
|
||||
@@ -356,6 +356,19 @@ public class NoppesUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static void handleFormEnd() {
|
||||
NBTTagCompound compound;
|
||||
try {
|
||||
compound = CompressedStreamTools.func_152457_a(accumulatedData, new NBTSizeTracker(2097152L));
|
||||
ClientCacheHandler.playerData.setDBCSync(compound);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
} finally {
|
||||
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];
|
||||
|
||||
@@ -448,5 +448,8 @@ public class PacketHandlerClient extends PacketHandlerServer{
|
||||
if(gui instanceof IPartyData)
|
||||
((IPartyData)gui).setPartyData(Server.readNBT(buffer));
|
||||
}
|
||||
else if(type == EnumPacketClient.DBC_FORM){
|
||||
NoppesUtil.handleFormEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -56,6 +56,7 @@ public enum EnumPacketClient {
|
||||
SYNC_WEAPON,
|
||||
MARK_DATA,
|
||||
SYNC_ADD, SYNC_END, SYNC_UPDATE, SYNC_REMOVE, SYNC_PLAYER,
|
||||
DBC_FORM,
|
||||
LARGE_NBT_PART, LARGE_NBT_END,
|
||||
PARTY_DATA
|
||||
}
|
||||
@@ -155,7 +155,6 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
dialogData.saveNBTData(compound);
|
||||
questData.saveNBTData(compound);
|
||||
factionData.saveNBTData(compound);
|
||||
DBCAddon.instance.writeToNBT(this, compound);
|
||||
return compound;
|
||||
}
|
||||
|
||||
@@ -163,7 +162,6 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
dialogData.loadNBTData(data);
|
||||
questData.loadNBTData(data);
|
||||
factionData.loadNBTData(data);
|
||||
DBCAddon.instance.readFromNBT(this, data);
|
||||
}
|
||||
|
||||
public NBTTagCompound getSyncNBTFull() {
|
||||
@@ -202,6 +200,14 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
DBCAddon.instance.readFromNBT(this, data);
|
||||
}
|
||||
|
||||
public void getDBCSync(NBTTagCompound compound){
|
||||
DBCAddon.instance.writeToNBT(this, compound);
|
||||
}
|
||||
|
||||
public void setDBCSync(NBTTagCompound data){
|
||||
DBCAddon.instance.readFromNBT(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(Entity entity, World world) {
|
||||
|
||||
|
||||
Reference in new issue
Block a user