mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 13:07:29 +00:00
Large Abstract Packet By UUID
This commit is contained in:
1 parent
476efb0317
commit
19c31b985d
1 file changed
+14
-10
@@ -1,33 +1,33 @@
|
||||
// src/main/java/kamkeel/network/LargeAbstractPacket.java
|
||||
package kamkeel.network;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import kamkeel.util.ByteBufUtils;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import noppes.npcs.client.NoppesUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class LargeAbstractPacket extends AbstractPacket {
|
||||
private static final int CHUNK_SIZE = 30000;
|
||||
private static final Map<Integer, ByteBuf> packetChunks = new HashMap<>();
|
||||
private static final Map<Integer, Integer> receivedChunks = new HashMap<>();
|
||||
|
||||
public abstract void handleData(ByteBuf data, EntityPlayer player) throws IOException;
|
||||
private static final int CHUNK_SIZE = 10000;
|
||||
private static final Map<UUID, ByteBuf> packetChunks = new HashMap<>();
|
||||
private static final Map<UUID, Integer> receivedChunks = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
ByteBuf data = Unpooled.buffer();
|
||||
writeData(data);
|
||||
int totalSize = data.readableBytes();
|
||||
int packetId = this.hashCode(); // Unique ID for this packet
|
||||
UUID packetId = UUID.randomUUID(); // Unique ID for this packet
|
||||
int totalChunks = (int) Math.ceil((double) totalSize / CHUNK_SIZE);
|
||||
|
||||
for (int i = 0; i < totalSize; i += CHUNK_SIZE) {
|
||||
int chunkSize = Math.min(CHUNK_SIZE, totalSize - i);
|
||||
ByteBuf chunk = data.readBytes(chunkSize);
|
||||
out.writeInt(packetId);
|
||||
out.writeLong(packetId.getMostSignificantBits());
|
||||
out.writeLong(packetId.getLeastSignificantBits());
|
||||
out.writeInt(totalSize);
|
||||
out.writeInt(i);
|
||||
out.writeInt(totalChunks);
|
||||
@@ -37,7 +37,9 @@ public abstract class LargeAbstractPacket extends AbstractPacket {
|
||||
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
int packetId = in.readInt();
|
||||
long mostSigBits = in.readLong();
|
||||
long leastSigBits = in.readLong();
|
||||
UUID packetId = new UUID(mostSigBits, leastSigBits);
|
||||
int totalSize = in.readInt();
|
||||
int offset = in.readInt();
|
||||
int totalChunks = in.readInt();
|
||||
@@ -56,4 +58,6 @@ public abstract class LargeAbstractPacket extends AbstractPacket {
|
||||
}
|
||||
|
||||
public abstract void writeData(ByteBuf out) throws IOException;
|
||||
|
||||
public abstract void handleData(ByteBuf data, EntityPlayer player) throws IOException;
|
||||
}
|
||||
Reference in new issue
Block a user