package cc.maxmc.servux.util import io.netty.buffer.ByteBuf import io.netty.buffer.ByteBufOutputStream import io.netty.handler.codec.EncoderException import net.minecraft.nbt.NBTCompressedStreamTools import net.minecraft.nbt.NBTTagCompound import java.io.IOException fun ByteBuf.writeVarInt(value: Int): ByteBuf { var value = value while (value and -128 != 0) { this.writeByte(value and 127 or 128) value = value ushr 7 } this.writeByte(value) return this } fun ByteBuf.writeNBT(compound: NBTTagCompound?): ByteBuf { if (compound == null) { this.writeByte(0) } else { try { NBTCompressedStreamTools.write(compound, ByteBufOutputStream(this)) } catch (var3: IOException) { throw EncoderException(var3) } } return this }