Add BinaryWriter#write(ByteBuf)

This commit is contained in:
TheMode 2021-04-14 01:40:21 +02:00
parent a3f1235df4
commit b68c30423c
2 changed files with 8 additions and 13 deletions

View File

@ -1,5 +1,6 @@
package net.minestom.server.item; package net.minestom.server.item;
import io.netty.buffer.ByteBuf;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.minestom.server.instance.block.Block; import net.minestom.server.instance.block.Block;
import net.minestom.server.item.attribute.ItemAttribute; import net.minestom.server.item.attribute.ItemAttribute;
@ -33,7 +34,7 @@ public class ItemMeta implements Writeable {
private final ItemMetaBuilder emptyBuilder; private final ItemMetaBuilder emptyBuilder;
private String cachedSNBT; private String cachedSNBT;
private BinaryWriter cachedBuffer; private ByteBuf cachedBuffer;
protected ItemMeta(@NotNull ItemMetaBuilder metaBuilder) { protected ItemMeta(@NotNull ItemMetaBuilder metaBuilder) {
this.damage = metaBuilder.damage; this.damage = metaBuilder.damage;
@ -157,9 +158,9 @@ public class ItemMeta implements Writeable {
if (cachedBuffer == null) { if (cachedBuffer == null) {
BinaryWriter w = new BinaryWriter(); BinaryWriter w = new BinaryWriter();
w.writeNBT("", nbt); w.writeNBT("", nbt);
this.cachedBuffer = w; this.cachedBuffer = w.getBuffer();
} }
writer.write(cachedBuffer); writer.write(cachedBuffer);
cachedBuffer.getBuffer().resetReaderIndex(); this.cachedBuffer.resetReaderIndex();
} }
} }

View File

@ -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}. * Writes an {@link UUID}.
* It is done by writing both long, the most and least significant bits. * 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()); 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 * 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. * length of the array.