mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-21 07:31:47 +01:00
Add BinaryWriter#write(ByteBuf)
This commit is contained in:
parent
a3f1235df4
commit
b68c30423c
@ -1,5 +1,6 @@
|
||||
package net.minestom.server.item;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
import net.minestom.server.item.attribute.ItemAttribute;
|
||||
@ -33,7 +34,7 @@ public class ItemMeta implements Writeable {
|
||||
private final ItemMetaBuilder emptyBuilder;
|
||||
|
||||
private String cachedSNBT;
|
||||
private BinaryWriter cachedBuffer;
|
||||
private ByteBuf cachedBuffer;
|
||||
|
||||
protected ItemMeta(@NotNull ItemMetaBuilder metaBuilder) {
|
||||
this.damage = metaBuilder.damage;
|
||||
@ -157,9 +158,9 @@ public class ItemMeta implements Writeable {
|
||||
if (cachedBuffer == null) {
|
||||
BinaryWriter w = new BinaryWriter();
|
||||
w.writeNBT("", nbt);
|
||||
this.cachedBuffer = w;
|
||||
this.cachedBuffer = w.getBuffer();
|
||||
}
|
||||
writer.write(cachedBuffer);
|
||||
cachedBuffer.getBuffer().resetReaderIndex();
|
||||
this.cachedBuffer.resetReaderIndex();
|
||||
}
|
||||
}
|
||||
|
@ -233,16 +233,6 @@ public class BinaryWriter extends OutputStream {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Consumer this object to write at a different time
|
||||
*
|
||||
* @param consumer the writer consumer
|
||||
*/
|
||||
public void write(Consumer<BinaryWriter> consumer) {
|
||||
if (consumer != null)
|
||||
consumer.accept(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes an {@link UUID}.
|
||||
* It is done by writing both long, the most and least significant bits.
|
||||
@ -295,6 +285,10 @@ public class BinaryWriter extends OutputStream {
|
||||
this.buffer.writeBytes(writer.getBuffer());
|
||||
}
|
||||
|
||||
public void write(@NotNull ByteBuf buffer) {
|
||||
this.buffer.writeBytes(buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes an array of writeable objects to this writer. Will prepend the binary stream with a var int to denote the
|
||||
* length of the array.
|
||||
|
Loading…
Reference in New Issue
Block a user