mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-20 11:09:42 +00:00
New Packet Things - WIP
This commit is contained in:
1 parent
17eac9a690
commit
be6c318619
9 files changed
+209
-68
No files matched your search
@@ -0,0 +1,63 @@
|
||||
package kamkeel.util;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTSizeTracker;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.village.MerchantRecipeList;
|
||||
import noppes.npcs.LogWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ByteBufUtils extends cpw.mods.fml.common.network.ByteBufUtils {
|
||||
|
||||
public static void writeIntArray(ByteBuf buffer, int[] arr) {
|
||||
buffer.writeInt(arr.length);
|
||||
for (int i : arr) {
|
||||
buffer.writeInt(i);
|
||||
}
|
||||
}
|
||||
|
||||
public static int[] readIntArray(ByteBuf buffer) {
|
||||
int length = buffer.readInt();
|
||||
int[] arr = new int[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
arr[i] = buffer.readInt();
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
public static void writeNBT(ByteBuf buffer, NBTTagCompound compound) throws IOException {
|
||||
byte[] bytes = CompressedStreamTools.compress(compound);
|
||||
buffer.writeShort((short)bytes.length);
|
||||
buffer.writeBytes(bytes);
|
||||
}
|
||||
|
||||
public static NBTTagCompound readNBT(ByteBuf buffer) throws IOException {
|
||||
byte[] bytes = new byte[buffer.readShort()];
|
||||
buffer.readBytes(bytes);
|
||||
return CompressedStreamTools.func_152457_a(bytes, new NBTSizeTracker(2097152L));
|
||||
}
|
||||
|
||||
public static void writeString(ByteBuf buffer, String s){
|
||||
byte[] bytes = s.getBytes(Charsets.UTF_8);
|
||||
buffer.writeShort((short)bytes.length);
|
||||
buffer.writeBytes(bytes);
|
||||
}
|
||||
|
||||
public static String readString(ByteBuf buffer){
|
||||
try{
|
||||
byte[] bytes = new byte[buffer.readShort()];
|
||||
buffer.readBytes(bytes);
|
||||
return new String(bytes, Charsets.UTF_8);
|
||||
}
|
||||
catch(IndexOutOfBoundsException ex){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user