Interface MCDataOutput

All Known Implementing Classes:
MCByteStream, MCDataByteBuf, MCDataOutputStream, PacketCustom

public interface MCDataOutput
Provides the ability to write various datas to some sort of data stream. See MCDataOutputStream to wrap an OutputStream to this. See MCByteStream to wrap an ByteBuf to this.

Created by covers1624 on 4/15/20.

  • Method Details

    • writeByte

      MCDataOutput writeByte(int b)
      Writes a byte to the stream.
      Parameters:
      b - The byte.
      Returns:
      The same stream.
    • writeChar

      MCDataOutput writeChar(int c)
      Writes a char to the stream.
      Parameters:
      c - The char.
      Returns:
      The same stream.
    • writeShort

      MCDataOutput writeShort(int s)
      Writes a short to the stream.
      Parameters:
      s - The short.
      Returns:
      The same stream.
    • writeInt

      MCDataOutput writeInt(int i)
      Writes a int to the stream.
      Parameters:
      i - The int.
      Returns:
      The same stream.
    • writeLong

      MCDataOutput writeLong(long l)
      Writes a long to the stream.
      Parameters:
      l - The long.
      Returns:
      The same stream.
    • writeFloat

      MCDataOutput writeFloat(float f)
      Writes a float to the stream.
      Parameters:
      f - The float.
      Returns:
      The same stream.
    • writeDouble

      MCDataOutput writeDouble(double d)
      Writes a double to the stream.
      Parameters:
      d - The double.
      Returns:
      The same stream.
    • writeBoolean

      MCDataOutput writeBoolean(boolean b)
      Writes a boolean to the stream.
      Parameters:
      b - The boolean.
      Returns:
      The same stream.
    • writeBytes

      default MCDataOutput writeBytes(byte[] b)
      Writes an array to the stream, including its length. First writes the arrays length as a varInt, followed by the array data.
      Parameters:
      b - The array.
      Returns:
      The same stream.
    • writeBytes

      default MCDataOutput writeBytes(byte[] b, int off, int len)
      Writes an array to the stream, including its length. First writes the arrays length as a varInt, followed by the array data.
      Parameters:
      b - The array.
      off - An offset into the array to start reading from.
      len - How many elements to read.
      Returns:
      The same stream.
    • writeChars

      default MCDataOutput writeChars(char[] c)
      Writes an array to the stream, including its length. First writes the arrays length as a varInt, followed by the array data.
      Parameters:
      c - The array.
      Returns:
      The same stream.
    • writeChars

      default MCDataOutput writeChars(char[] c, int off, int len)
      Writes an array to the stream, including its length. First writes the arrays length as a varInt, followed by the array data.
      Parameters:
      c - The array.
      off - An offset into the array to start reading from.
      len - How many elements to read.
      Returns:
      The same stream.
    • writeShorts

      default MCDataOutput writeShorts(short[] s)
      Writes an array to the stream, including its length. First writes the arrays length as a varInt, followed by the array data.
      Parameters:
      s - The array.
      Returns:
      The same stream.
    • writeShorts

      default MCDataOutput writeShorts(short[] s, int off, int len)
      Writes an array to the stream, including its length. First writes the arrays length as a varInt, followed by the array data.
      Parameters:
      s - The array.
      off - An offset into the array to start reading from.
      len - How many elements to read.
      Returns:
      The same stream.
    • writeInts

      default MCDataOutput writeInts(int[] i)
      Writes an array to the stream, including its length. First writes the arrays length as a varInt, followed by the array data.
      Parameters:
      i - The array.
      Returns:
      The same stream.
    • writeInts

      default MCDataOutput writeInts(int[] i, int off, int len)
      Writes an array to the stream, including its length. First writes the arrays length as a varInt, followed by the array data.
      Parameters:
      i - The array.
      off - An offset into the array to start reading from.
      len - How many elements to read.
      Returns:
      The same stream.
    • writeLongs

      default MCDataOutput writeLongs(long[] l)
      Writes an array to the stream, including its length. First writes the arrays length as a varInt, followed by the array data.
      Parameters:
      l - The array.
      Returns:
      The same stream.
    • writeLongs

      default MCDataOutput writeLongs(long[] l, int off, int len)
      Writes an array to the stream, including its length. First writes the arrays length as a varInt, followed by the array data.
      Parameters:
      l - The array.
      off - An offset into the array to start reading from.
      len - How many elements to read.
      Returns:
      The same stream.
    • writeFloats

      default MCDataOutput writeFloats(float[] f)
      Writes an array to the stream, including its length. First writes the arrays length as a varInt, followed by the array data.
      Parameters:
      f - The array.
      Returns:
      The same stream.
    • writeFloats

      default MCDataOutput writeFloats(float[] f, int off, int len)
      Writes an array to the stream, including its length. First writes the arrays length as a varInt, followed by the array data.
      Parameters:
      f - The array.
      off - An offset into the array to start reading from.
      len - How many elements to read.
      Returns:
      The same stream.
    • writeDoubles

      default MCDataOutput writeDoubles(double[] d)
      Writes an array to the stream, including its length. First writes the arrays length as a varInt, followed by the array data.
      Parameters:
      d - The array.
      Returns:
      The same stream.
    • writeDoubles

      default MCDataOutput writeDoubles(double[] d, int off, int len)
      Writes an array to the stream, including its length. First writes the arrays length as a varInt, followed by the array data.
      Parameters:
      d - The array.
      off - An offset into the array to start reading from.
      len - How many elements to read.
      Returns:
      The same stream.
    • writeBooleans

      default MCDataOutput writeBooleans(boolean[] b)
      Writes an array to the stream, including its length. First writes the arrays length as a varInt, followed by the array data.
      Parameters:
      b - The array.
      Returns:
      The same stream.
    • writeBooleans

      default MCDataOutput writeBooleans(boolean[] b, int off, int len)
      Writes an array to the stream, including its length. First writes the arrays length as a varInt, followed by the array data.
      Parameters:
      b - The array.
      off - An offset into the array to start reading from.
      len - How many elements to read.
      Returns:
      The same stream.
    • append

      default MCDataOutput append(byte[] bytes)
      Appends the content of the array to the end of this buffer.
      Parameters:
      bytes - The array.
      Returns:
      The same stream.
    • writeVarInt

      default MCDataOutput writeVarInt(int i)
      Writes a Variable length int. Doesn't handle Signed ints well, they end up as 5 bytes, instead of 4, Use writeSignedVarInt(int) if you require numbers <= -1
      Parameters:
      i - The int.
      Returns:
      The same stream.
    • writeVarLong

      default MCDataOutput writeVarLong(long l)
      Writes a Variable length long. Doesn't handle Signed longs well, they end up as 10 bytes, instead of 8, Use writeSignedVarLong(long) if you require numbers <= -1
      Parameters:
      l - The long.
      Returns:
      The same stream.
    • writeSignedVarInt

      default MCDataOutput writeSignedVarInt(int i)
      Writes a Signed Variable length int. Favourable for numbers <= -1
      Parameters:
      i - The int.
      Returns:
      The same stream.
    • writeSignedVarLong

      default MCDataOutput writeSignedVarLong(long i)
      Writes a Signed Variable length long. Favourable for numbers <= -1
      Parameters:
      i - The long.
      Returns:
      The same stream.
    • writeVarInts

      default MCDataOutput writeVarInts(int[] i)
      Writes an array of Variable length ints to the stream. First writes the arrays length as a varInt, followed by the array data.
      Parameters:
      i - The array.
      Returns:
      The same stream.
    • writeVarInts

      default MCDataOutput writeVarInts(int[] i, int off, int len)
      Writes an array of Variable length ints to the stream. First writes the arrays length as a varInt, followed by the array data.
      Parameters:
      i - The array.
      off - An offset into the array to start reading from.
      len - How many elements to read.
      Returns:
      The same stream.
    • writeVarLongs

      default MCDataOutput writeVarLongs(long[] l)
      Writes an array of Variable length longs to the stream. First writes the arrays length as a varInt, followed by the array data.
      Parameters:
      l - The array.
      Returns:
      The same stream.
    • writeVarLongs

      default MCDataOutput writeVarLongs(long[] l, int off, int len)
      Writes an array of Variable length longs to the stream. First writes the arrays length as a varInt, followed by the array data.
      Parameters:
      l - The array.
      off - An offset into the array to start reading from.
      len - How many elements to read.
      Returns:
      The same stream.
    • writeSignedVarInts

      default MCDataOutput writeSignedVarInts(int[] i)
      Writes an array of Variable length Signed ints to the stream. First writes the arrays length as a varInt, followed by the array data.
      Parameters:
      i - The array.
      Returns:
      The same stream.
    • writeSignedVarInts

      default MCDataOutput writeSignedVarInts(int[] i, int off, int len)
      Writes an array of Variable length Signed ints to the stream. First writes the arrays length as a varInt, followed by the array data.
      Parameters:
      i - The array.
      off - An offset into the array to start reading from.
      len - How many elements to read.
      Returns:
      The same stream.
    • writeSignedVarLongs

      default MCDataOutput writeSignedVarLongs(long[] l)
      Writes an array of Variable length Signed longs to the stream. First writes the arrays length as a varInt, followed by the array data.
      Parameters:
      l - The array.
      Returns:
      The same stream.
    • writeSignedVarLongs

      default MCDataOutput writeSignedVarLongs(long[] l, int off, int len)
      Writes an array of Variable length Signed longs to the stream. First writes the arrays length as a varInt, followed by the array data.
      Parameters:
      l - The array.
      off - An offset into the array to start reading from.
      len - How many elements to read.
      Returns:
      The same stream.
    • writeString

      default MCDataOutput writeString(String s)
      Writes a UTF-8 Encoded String to the stream. Forces a length of 32767 encoded bytes.
      Parameters:
      s - The String.
      Returns:
      The same stream.
    • writeString

      default MCDataOutput writeString(String s, int maxLen)
      Writes a UTF-8 Encoded String to the stream.
      Parameters:
      s - The String.
      maxLen - The maximum number of bytes to write, extra bytes will cause an EncoderException.
      Returns:
      The same stream.
    • writeUUID

      default MCDataOutput writeUUID(UUID uuid)
      Writes a UUID to the stream.
      Parameters:
      uuid - The UUID.
      Returns:
      The same stream.
    • writeEnum

      default MCDataOutput writeEnum(Enum<?> value)
      Writes an Enum value to the stream.
      Parameters:
      value - The Enum value to write.
      Returns:
      The same stream.
    • writeByteBuffer

      default MCDataOutput writeByteBuffer(ByteBuffer buffer)
      Writes a ByteBuffer to the stream.
      Parameters:
      buffer - The ByteBuffer.
      Returns:
      The same stream.
    • writeCharBuffer

      default MCDataOutput writeCharBuffer(CharBuffer buffer)
      Writes a CharBuffer to the stream.
      Parameters:
      buffer - The CharBuffer.
      Returns:
      The same stream.
    • writeShortBuffer

      default MCDataOutput writeShortBuffer(ShortBuffer buffer)
      Writes a ShortBuffer to the stream.
      Parameters:
      buffer - The ShortBuffer.
      Returns:
      The same stream.
    • writeIntBuffer

      default MCDataOutput writeIntBuffer(IntBuffer buffer)
      Writes a IntBuffer to the stream.
      Parameters:
      buffer - The IntBuffer.
      Returns:
      The same stream.
    • writeLongBuffer

      default MCDataOutput writeLongBuffer(LongBuffer buffer)
      Writes a LongBuffer to the stream.
      Parameters:
      buffer - The LongBuffer.
      Returns:
      The same stream.
    • writeFloatBuffer

      default MCDataOutput writeFloatBuffer(FloatBuffer buffer)
      Writes a FloatBuffer to the stream.
      Parameters:
      buffer - The FloatBuffer.
      Returns:
      The same stream.
    • writeDoubleBuffer

      default MCDataOutput writeDoubleBuffer(DoubleBuffer buffer)
      Writes a DoubleBuffer to the stream.
      Parameters:
      buffer - The DoubleBuffer.
      Returns:
      The same stream.
    • writeVector

      default MCDataOutput writeVector(Vector3 vec)
      Writes a Vector3 to the stream.
      Parameters:
      vec - The Vector3.
      Returns:
      The same stream.
    • writeCuboid

      default MCDataOutput writeCuboid(Cuboid6 cuboid)
      Writes a Cuboid6 to the stream.
      Parameters:
      cuboid - The Cuboid6
      Returns:
      The same stream.
    • writeResourceLocation

      default MCDataOutput writeResourceLocation(net.minecraft.resources.ResourceLocation loc)
      Writes a ResourceLocation to the stream.
      Parameters:
      loc - The ResourceLocation.
      Returns:
      The same stream.
    • writeDirection

      default MCDataOutput writeDirection(net.minecraft.core.Direction dir)
      Writes a Direction to the stream.
      Parameters:
      dir - The Direction.
      Returns:
      The same stream.
    • writePos

      default MCDataOutput writePos(net.minecraft.core.BlockPos pos)
      Writes a BlockPos to the stream.
      Parameters:
      pos - The BlockPos.
      Returns:
      The same stream.
    • writeVec3i

      default MCDataOutput writeVec3i(net.minecraft.core.Vec3i vec)
      Writes a Vec3i to the stream.
      Parameters:
      vec - The Vec3i.
      Returns:
      The same stream.
    • writeVec3f

      default MCDataOutput writeVec3f(org.joml.Vector3f vec)
      Writes a Vector3f to the stream.
      Parameters:
      vec - The Vector3f.
      Returns:
      The same stream.
    • writeVec3d

      default MCDataOutput writeVec3d(net.minecraft.world.phys.Vec3 vec)
      Writes a Vec3 to the stream.
      Parameters:
      vec - The Vec3.
      Returns:
      The same stream.
    • writeCompoundNBT

      default MCDataOutput writeCompoundNBT(net.minecraft.nbt.CompoundTag tag)
      Writes a CompoundTag to the stream.
      Parameters:
      tag - The CompoundTag.
      Returns:
      The same stream.
    • writeItemStack

      default MCDataOutput writeItemStack(net.minecraft.world.item.ItemStack stack)
      Writes an ItemStack to the stream. Overload for writeItemStack(ItemStack, boolean) passing true.
      Parameters:
      stack - The ItemStack.
      Returns:
      The same stream.
    • writeItemStack

      default MCDataOutput writeItemStack(net.minecraft.world.item.ItemStack stack, boolean limitedTag)
      Writes an ItemStack to the stream. The limitedTag parameter, can be used to force the use of the stack IForgeItemStack.getShareTag() instead of its ItemStack.getTag(). Under normal circumstances in Server -> Client sync, not all NBT tags are required, to be sent to the client. For Example, the inventory of a pouch / bag(Containers sync it). However, in Client -> Server sync, the entire tag may be required, modders can choose, if they want a stacks full tag or not. The default is to use IForgeItemStack.getShareTag().

      It should also be noted that this implementation writes the ItemStack.getCount() as a varInt opposed to a byte, as that is favourable in some cases.

      Parameters:
      stack - The ItemStack.
      limitedTag - Weather to use the stacks IForgeItemStack.getShareTag() instead.
      Returns:
      The same stream.
    • writeFluidStack

      default MCDataOutput writeFluidStack(net.minecraftforge.fluids.FluidStack stack)
      Writes a FluidStack to the stream.
      Parameters:
      stack - The FluidStack.
      Returns:
      The same stream.
    • writeTextComponent

      default MCDataOutput writeTextComponent(net.minecraft.network.chat.Component component)
      Writes a Component to the stream.
      Parameters:
      component - The Component.
      Returns:
      The same stream.
    • writeRegistryIdDirect

      default <T> MCDataOutput writeRegistryIdDirect(net.minecraftforge.registries.IForgeRegistry<T> registry, T entry)
      Writes a forge registry object's id to the stream. This method does not encode the Registry name to the packet, only the object's id.
      Parameters:
      registry - The registry that owns entry.
      entry - The object to write to the stream.
      Returns:
      The same stream.
    • writeRegistryIdDirect

      default <T> MCDataOutput writeRegistryIdDirect(net.minecraftforge.registries.IForgeRegistry<T> registry, net.minecraft.resources.ResourceLocation entry)
      Writes the id associated with the given name to the stream. This method does not encode the Registry name to the packet, only the id.
      Parameters:
      registry - The registry that owns entry.
      entry - The name of the registry object to write.
      Returns:
      The same stream.
    • writeRegistryId

      default <T> MCDataOutput writeRegistryId(net.minecraftforge.registries.IForgeRegistry<T> registry, T entry)
      Writes the given object to the stream encoding both the registry name and object's id.
      Parameters:
      registry - The registry that owns entry.
      entry - The object to write to the stream.
      Returns:
      The same stream.
    • writeRegistryId

      default <T> MCDataOutput writeRegistryId(net.minecraftforge.registries.IForgeRegistry<T> registry, net.minecraft.resources.ResourceLocation entry)
      Writes the id associated with the given name to the stream encoding both the registry name and object's id.
      Parameters:
      registry - The registry that owns entry.
      entry - The name of the registry object to write.
      Returns:
      The same stream.
    • writeByteBuf

      default MCDataOutput writeByteBuf(io.netty.buffer.ByteBuf buf)
      Writes a ByteBuf to the stream, including its length. First writes the arrays length as a varInt, followed by the ByteBuf data.
      Parameters:
      buf - The ByteBuf.
      Returns:
      The same stream.
    • append

      default MCDataOutput append(io.netty.buffer.ByteBuf buf)
      Appends a ByteBuf to the end of this stream.
      Parameters:
      buf - The ByteBuf to append.
      Returns:
      The same stream.
    • toDataOutput

      default DataOutput toDataOutput()
      Wraps this stream into a DataOutput stream, any data written into the returned DataOutput is appended to this stream.
      Returns:
      The DataOutput stream.
    • toOutputStream

      default OutputStream toOutputStream()
      Wraps this stream into an OutputStream, any data written into the returned OutputStream is appended to this stream.
      Returns:
      The OutputStream stream.