more moving.

This commit is contained in:
cp committed 2014-02-28 00:08:24 +08:00
1 parent ce486c0540
commit bef5f6193e
510 files changed

No files matched your search

@@ -0,0 +1,44 @@
package crazypants.enderio.network;
import cpw.mods.fml.common.FMLCommonHandler;
import io.netty.buffer.ByteBuf;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import java.io.IOException;
/**
* Created by CrazyPants on 27/02/14.
*/
public class NetworkUtil {
public static NBTTagCompound readNBTTagCompound(ByteBuf dataIn) {
try {
short size = dataIn.readShort();
if(size < 0) {
return null;
} else {
byte[] buffer = new byte[size];
dataIn.readBytes(buffer);
return CompressedStreamTools.decompress(buffer);
}
} catch (IOException e) {
FMLCommonHandler.instance().raiseException(e, "Custom Packet", true);
return null;
}
}
public static void writeNBTTagCompound(NBTTagCompound compound, ByteBuf dataout) {
try {
if(compound == null) {
dataout.writeShort(-1);
} else {
byte[] buf = CompressedStreamTools.compress(compound);
dataout.writeShort((short) buf.length);
dataout.writeBytes(buf);
}
} catch (IOException e) {
FMLCommonHandler.instance().raiseException(e, "PacketUtil.readTileEntityPacket.writeNBTTagCompound", true);
}
}
}