Class ByteBufHelper<T>
java.lang.Object
net.darkhax.bookshelf.api.data.bytebuf.ByteBufHelper<T>
- Type Parameters:
T- The type being serialized.
- Direct Known Subclasses:
RegistryByteBufHelper
Logic for serializing data using a byte buffer.
-
Constructor Summary
ConstructorsConstructorDescriptionByteBufHelper(Function<net.minecraft.network.FriendlyByteBuf, T> reader, BiConsumer<net.minecraft.network.FriendlyByteBuf, T> writer, T... vargs) -
Method Summary
Modifier and TypeMethodDescriptionread(net.minecraft.network.FriendlyByteBuf buffer) Reads the data from the buffer directly.T[]readArray(net.minecraft.network.FriendlyByteBuf buffer) Reads an array of values from the buffer.<C extends Collection<T>>
CreadCollection(net.minecraft.network.FriendlyByteBuf buffer, Supplier<C> collectionSupplier) Reads a collection of values from the buffer.readList(net.minecraft.network.FriendlyByteBuf buffer) Reads a list of values from the buffer.readNullable(net.minecraft.network.FriendlyByteBuf buffer) Read a nullable value from the buffer.readOptional(net.minecraft.network.FriendlyByteBuf buffer) Reads an optional value from the buffer.readSet(net.minecraft.network.FriendlyByteBuf buffer) Reads a set of values from the buffer.net.minecraft.util.random.WeightedEntry.Wrapper<T>readWeighted(net.minecraft.network.FriendlyByteBuf buffer) Read a weighted value from the buffer.net.minecraft.util.random.SimpleWeightedRandomList<T>readWeightedList(net.minecraft.network.FriendlyByteBuf buffer) Read a weighted random list from the buffer.voidWrites the data to the buffer directly.voidwriteArray(net.minecraft.network.FriendlyByteBuf buffer, T[] array) Writes an array of values to the buffer.voidwriteCollection(net.minecraft.network.FriendlyByteBuf buffer, Collection<T> collection) Writes a collection of values to the buffer.voidWrites a list of values to the buffer.voidwriteNullable(net.minecraft.network.FriendlyByteBuf buffer, T value) Writes a nullable value to the buffer.voidwriteOptional(net.minecraft.network.FriendlyByteBuf buffer, Optional<T> optional) Writes an optional value to the buffer.voidWrites a set of values to the buffer.voidwriteWeighted(net.minecraft.network.FriendlyByteBuf buffer, net.minecraft.util.random.WeightedEntry.Wrapper<T> toWrite) Write a weighted value to the buffer.voidwriteWeightedList(net.minecraft.network.FriendlyByteBuf buffer, net.minecraft.util.random.SimpleWeightedRandomList<T> list) Write a weighted random list to the buffer.
-
Constructor Details
-
ByteBufHelper
public ByteBufHelper(Function<net.minecraft.network.FriendlyByteBuf, T> reader, BiConsumer<net.minecraft.network.FriendlyByteBuf, T> writer, T... vargs)
-
-
Method Details
-
read
Reads the data from the buffer directly.- Parameters:
buffer- The buffer to read from.- Returns:
- The value that was read.
-
write
Writes the data to the buffer directly.- Parameters:
buffer- The buffer to write data to.toWrite- The value to write to the buffer.
-
readArray
Reads an array of values from the buffer.- Parameters:
buffer- The buffer to read from.- Returns:
- An array of values read from the buffer.
-
writeArray
Writes an array of values to the buffer.- Parameters:
buffer- The buffer to read from.array- The array of values to write.
-
readCollection
public <C extends Collection<T>> C readCollection(net.minecraft.network.FriendlyByteBuf buffer, Supplier<C> collectionSupplier) Reads a collection of values from the buffer.- Type Parameters:
C- The type of collection to produce.- Parameters:
buffer- The buffer to read from.collectionSupplier- A supplier that provides the collection to populate with values. For example ArrayList::new.- Returns:
- A collection of values read from the buffer.
-
writeCollection
Writes a collection of values to the buffer.- Parameters:
buffer- The buffer to write data to.collection- The collection of values to write.
-
readList
Reads a list of values from the buffer.- Parameters:
buffer- The buffer to read from.- Returns:
- A list of values read from the buffer.
-
writeList
Writes a list of values to the buffer.- Parameters:
buffer- The buffer to write data to.toWrite- The list of values to write.
-
readSet
Reads a set of values from the buffer.- Parameters:
buffer- The buffer to read data from.- Returns:
- A set of values read from the buffer.
-
writeSet
Writes a set of values to the buffer.- Parameters:
buffer- The buffer to write data to.toWrite- The set of values to write.
-
readOptional
Reads an optional value from the buffer.- Parameters:
buffer- The buffer to read data from.- Returns:
- The optional value that was read from the buffer.
-
writeOptional
Writes an optional value to the buffer.- Parameters:
buffer- The buffer to write data to.optional- The optional value to write.
-
readNullable
Read a nullable value from the buffer.- Parameters:
buffer- The buffer to read data from.- Returns:
- The nullable value read from the buffer.
-
writeNullable
Writes a nullable value to the buffer.- Parameters:
buffer- The buffer to write data to.value- The nullable value to write.
-
readWeighted
public net.minecraft.util.random.WeightedEntry.Wrapper<T> readWeighted(net.minecraft.network.FriendlyByteBuf buffer) Read a weighted value from the buffer.- Parameters:
buffer- The buffer to read data from.- Returns:
- The weighted value read from the buffer.
-
writeWeighted
public void writeWeighted(net.minecraft.network.FriendlyByteBuf buffer, net.minecraft.util.random.WeightedEntry.Wrapper<T> toWrite) Write a weighted value to the buffer.- Parameters:
buffer- The buffer to write data to.toWrite- The weighted value to write to the buffer.
-
readWeightedList
public net.minecraft.util.random.SimpleWeightedRandomList<T> readWeightedList(net.minecraft.network.FriendlyByteBuf buffer) Read a weighted random list from the buffer.- Parameters:
buffer- The buffer to read data from.- Returns:
- The weighted random list that was read from the buffer.
-
writeWeightedList
public void writeWeightedList(net.minecraft.network.FriendlyByteBuf buffer, net.minecraft.util.random.SimpleWeightedRandomList<T> list) Write a weighted random list to the buffer.- Parameters:
buffer- The buffer to write data to.list- The weighted random list to write to the buffer.
-