Package codechicken.lib.data
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.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptiondefault MCDataOutputappend(byte[] bytes) Appends the content of the array to the end of this buffer.default MCDataOutputappend(io.netty.buffer.ByteBuf buf) Appends aByteBufto the end of this stream.default DataOutputWraps this stream into aDataOutputstream, any data written into the returnedDataOutputis appended to this stream.default OutputStreamWraps this stream into anOutputStream, any data written into the returnedOutputStreamis appended to this stream.writeBoolean(boolean b) Writes a boolean to the stream.default MCDataOutputwriteBooleans(boolean[] b) Writes an array to the stream, including its length.default MCDataOutputwriteBooleans(boolean[] b, int off, int len) Writes an array to the stream, including its length.writeByte(int b) Writes a byte to the stream.default MCDataOutputwriteByteBuf(io.netty.buffer.ByteBuf buf) Writes aByteBufto the stream, including its length.default MCDataOutputwriteByteBuffer(ByteBuffer buffer) Writes aByteBufferto the stream.default MCDataOutputwriteBytes(byte[] b) Writes an array to the stream, including its length.default MCDataOutputwriteBytes(byte[] b, int off, int len) Writes an array to the stream, including its length.writeChar(int c) Writes a char to the stream.default MCDataOutputwriteCharBuffer(CharBuffer buffer) Writes aCharBufferto the stream.default MCDataOutputwriteChars(char[] c) Writes an array to the stream, including its length.default MCDataOutputwriteChars(char[] c, int off, int len) Writes an array to the stream, including its length.default MCDataOutputwriteCompoundNBT(net.minecraft.nbt.CompoundTag tag) Writes aCompoundTagto the stream.default MCDataOutputwriteCuboid(Cuboid6 cuboid) Writes aCuboid6to the stream.default MCDataOutputwriteDirection(net.minecraft.core.Direction dir) Writes aDirectionto the stream.writeDouble(double d) Writes a double to the stream.default MCDataOutputwriteDoubleBuffer(DoubleBuffer buffer) Writes aDoubleBufferto the stream.default MCDataOutputwriteDoubles(double[] d) Writes an array to the stream, including its length.default MCDataOutputwriteDoubles(double[] d, int off, int len) Writes an array to the stream, including its length.default MCDataOutputWrites anEnumvalue to the stream.writeFloat(float f) Writes a float to the stream.default MCDataOutputwriteFloatBuffer(FloatBuffer buffer) Writes aFloatBufferto the stream.default MCDataOutputwriteFloats(float[] f) Writes an array to the stream, including its length.default MCDataOutputwriteFloats(float[] f, int off, int len) Writes an array to the stream, including its length.default MCDataOutputwriteFluidStack(net.minecraftforge.fluids.FluidStack stack) Writes aFluidStackto the stream.writeInt(int i) Writes a int to the stream.default MCDataOutputwriteIntBuffer(IntBuffer buffer) Writes aIntBufferto the stream.default MCDataOutputwriteInts(int[] i) Writes an array to the stream, including its length.default MCDataOutputwriteInts(int[] i, int off, int len) Writes an array to the stream, including its length.default MCDataOutputwriteItemStack(net.minecraft.world.item.ItemStack stack) Writes anItemStackto the stream.default MCDataOutputwriteItemStack(net.minecraft.world.item.ItemStack stack, boolean limitedTag) Writes anItemStackto the stream.writeLong(long l) Writes a long to the stream.default MCDataOutputwriteLongBuffer(LongBuffer buffer) Writes aLongBufferto the stream.default MCDataOutputwriteLongs(long[] l) Writes an array to the stream, including its length.default MCDataOutputwriteLongs(long[] l, int off, int len) Writes an array to the stream, including its length.default MCDataOutputwritePos(net.minecraft.core.BlockPos pos) Writes aBlockPosto the stream.default <T> MCDataOutputwriteRegistryId(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.default <T> MCDataOutputwriteRegistryId(net.minecraftforge.registries.IForgeRegistry<T> registry, T entry) Writes the given object to the stream encoding both the registry name and object's id.default <T> MCDataOutputwriteRegistryIdDirect(net.minecraftforge.registries.IForgeRegistry<T> registry, net.minecraft.resources.ResourceLocation entry) Writes the id associated with the given name to the stream.default <T> MCDataOutputwriteRegistryIdDirect(net.minecraftforge.registries.IForgeRegistry<T> registry, T entry) Writes a forge registry object's id to the stream.default MCDataOutputwriteResourceLocation(net.minecraft.resources.ResourceLocation loc) Writes aResourceLocationto the stream.writeShort(int s) Writes a short to the stream.default MCDataOutputwriteShortBuffer(ShortBuffer buffer) Writes aShortBufferto the stream.default MCDataOutputwriteShorts(short[] s) Writes an array to the stream, including its length.default MCDataOutputwriteShorts(short[] s, int off, int len) Writes an array to the stream, including its length.default MCDataOutputwriteSignedVarInt(int i) Writes a Signed Variable length int.default MCDataOutputwriteSignedVarInts(int[] i) Writes an array of Variable length Signed ints to the stream.default MCDataOutputwriteSignedVarInts(int[] i, int off, int len) Writes an array of Variable length Signed ints to the stream.default MCDataOutputwriteSignedVarLong(long i) Writes a Signed Variable length long.default MCDataOutputwriteSignedVarLongs(long[] l) Writes an array of Variable length Signed longs to the stream.default MCDataOutputwriteSignedVarLongs(long[] l, int off, int len) Writes an array of Variable length Signed longs to the stream.default MCDataOutputWrites a UTF-8 EncodedStringto the stream.default MCDataOutputwriteString(String s, int maxLen) Writes a UTF-8 EncodedStringto the stream.default MCDataOutputwriteTextComponent(net.minecraft.network.chat.Component component) Writes aComponentto the stream.default MCDataOutputWrites aUUIDto the stream.default MCDataOutputwriteVarInt(int i) Writes a Variable length int.default MCDataOutputwriteVarInts(int[] i) Writes an array of Variable length ints to the stream.default MCDataOutputwriteVarInts(int[] i, int off, int len) Writes an array of Variable length ints to the stream.default MCDataOutputwriteVarLong(long l) Writes a Variable length long.default MCDataOutputwriteVarLongs(long[] l) Writes an array of Variable length longs to the stream.default MCDataOutputwriteVarLongs(long[] l, int off, int len) Writes an array of Variable length longs to the stream.default MCDataOutputwriteVec3d(net.minecraft.world.phys.Vec3 vec) Writes aVec3to the stream.default MCDataOutputwriteVec3f(org.joml.Vector3f vec) Writes aVector3fto the stream.default MCDataOutputwriteVec3i(net.minecraft.core.Vec3i vec) Writes aVec3ito the stream.default MCDataOutputwriteVector(Vector3 vec) Writes aVector3to the stream.
-
Method Details
-
writeByte
Writes a byte to the stream.- Parameters:
b- The byte.- Returns:
- The same stream.
-
writeChar
Writes a char to the stream.- Parameters:
c- The char.- Returns:
- The same stream.
-
writeShort
Writes a short to the stream.- Parameters:
s- The short.- Returns:
- The same stream.
-
writeInt
Writes a int to the stream.- Parameters:
i- The int.- Returns:
- The same stream.
-
writeLong
Writes a long to the stream.- Parameters:
l- The long.- Returns:
- The same stream.
-
writeFloat
Writes a float to the stream.- Parameters:
f- The float.- Returns:
- The same stream.
-
writeDouble
Writes a double to the stream.- Parameters:
d- The double.- Returns:
- The same stream.
-
writeBoolean
Writes a boolean to the stream.- Parameters:
b- The boolean.- Returns:
- The same stream.
-
writeBytes
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Appends the content of the array to the end of this buffer.- Parameters:
bytes- The array.- Returns:
- The same stream.
-
writeVarInt
Writes a Variable length int. Doesn't handle Signed ints well, they end up as 5 bytes, instead of 4, UsewriteSignedVarInt(int)if you require numbers<= -1- Parameters:
i- The int.- Returns:
- The same stream.
-
writeVarLong
Writes a Variable length long. Doesn't handle Signed longs well, they end up as 10 bytes, instead of 8, UsewriteSignedVarLong(long)if you require numbers<= -1- Parameters:
l- The long.- Returns:
- The same stream.
-
writeSignedVarInt
Writes a Signed Variable length int. Favourable for numbers<= -1- Parameters:
i- The int.- Returns:
- The same stream.
-
writeSignedVarLong
Writes a Signed Variable length long. Favourable for numbers<= -1- Parameters:
i- The long.- Returns:
- The same stream.
-
writeVarInts
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
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
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
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
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
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
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
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
Writes a UTF-8 EncodedStringto the stream. Forces a length of 32767 encoded bytes.- Parameters:
s- TheString.- Returns:
- The same stream.
-
writeString
Writes a UTF-8 EncodedStringto the stream.- Parameters:
s- TheString.maxLen- The maximum number of bytes to write, extra bytes will cause an EncoderException.- Returns:
- The same stream.
-
writeUUID
Writes aUUIDto the stream.- Parameters:
uuid- TheUUID.- Returns:
- The same stream.
-
writeEnum
Writes anEnumvalue to the stream.- Parameters:
value- TheEnumvalue to write.- Returns:
- The same stream.
-
writeByteBuffer
Writes aByteBufferto the stream.- Parameters:
buffer- TheByteBuffer.- Returns:
- The same stream.
-
writeCharBuffer
Writes aCharBufferto the stream.- Parameters:
buffer- TheCharBuffer.- Returns:
- The same stream.
-
writeShortBuffer
Writes aShortBufferto the stream.- Parameters:
buffer- TheShortBuffer.- Returns:
- The same stream.
-
writeIntBuffer
Writes aIntBufferto the stream.- Parameters:
buffer- TheIntBuffer.- Returns:
- The same stream.
-
writeLongBuffer
Writes aLongBufferto the stream.- Parameters:
buffer- TheLongBuffer.- Returns:
- The same stream.
-
writeFloatBuffer
Writes aFloatBufferto the stream.- Parameters:
buffer- TheFloatBuffer.- Returns:
- The same stream.
-
writeDoubleBuffer
Writes aDoubleBufferto the stream.- Parameters:
buffer- TheDoubleBuffer.- Returns:
- The same stream.
-
writeVector
Writes aVector3to the stream.- Parameters:
vec- TheVector3.- Returns:
- The same stream.
-
writeCuboid
Writes aCuboid6to the stream.- Parameters:
cuboid- TheCuboid6- Returns:
- The same stream.
-
writeResourceLocation
Writes aResourceLocationto the stream.- Parameters:
loc- TheResourceLocation.- Returns:
- The same stream.
-
writeDirection
Writes aDirectionto the stream.- Parameters:
dir- TheDirection.- Returns:
- The same stream.
-
writePos
Writes aBlockPosto the stream.- Parameters:
pos- TheBlockPos.- Returns:
- The same stream.
-
writeVec3i
Writes aVec3ito the stream.- Parameters:
vec- TheVec3i.- Returns:
- The same stream.
-
writeVec3f
Writes aVector3fto the stream.- Parameters:
vec- TheVector3f.- Returns:
- The same stream.
-
writeVec3d
Writes aVec3to the stream.- Parameters:
vec- TheVec3.- Returns:
- The same stream.
-
writeCompoundNBT
Writes aCompoundTagto the stream.- Parameters:
tag- TheCompoundTag.- Returns:
- The same stream.
-
writeItemStack
Writes anItemStackto the stream. Overload forwriteItemStack(ItemStack, boolean)passing true.- Parameters:
stack- TheItemStack.- Returns:
- The same stream.
-
writeItemStack
Writes anItemStackto the stream. ThelimitedTagparameter, can be used to force the use of the stackIForgeItemStack.getShareTag()instead of itsItemStack.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 useIForgeItemStack.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- TheItemStack.limitedTag- Weather to use the stacksIForgeItemStack.getShareTag()instead.- Returns:
- The same stream.
-
writeFluidStack
Writes aFluidStackto the stream.- Parameters:
stack- TheFluidStack.- Returns:
- The same stream.
-
writeTextComponent
Writes aComponentto the stream.- Parameters:
component- TheComponent.- 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 ownsentry.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 ownsentry.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 ownsentry.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 ownsentry.entry- The name of the registry object to write.- Returns:
- The same stream.
-
writeByteBuf
Writes aByteBufto the stream, including its length. First writes the arrays length as a varInt, followed by the ByteBuf data.- Parameters:
buf- TheByteBuf.- Returns:
- The same stream.
-
append
Appends aByteBufto the end of this stream.- Parameters:
buf- TheByteBufto append.- Returns:
- The same stream.
-
toDataOutput
Wraps this stream into aDataOutputstream, any data written into the returnedDataOutputis appended to this stream.- Returns:
- The
DataOutputstream.
-
toOutputStream
Wraps this stream into anOutputStream, any data written into the returnedOutputStreamis appended to this stream.- Returns:
- The
OutputStreamstream.
-