Check if item amount <= 0 when writing ItemStack

This commit is contained in:
AJ Ferguson 2024-04-21 06:13:10 -04:00
parent 897eb241b6
commit 36d9415992

View file

@ -248,8 +248,9 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
}
public void writeOptionalItemStack(ByteBuf buf, ItemStack item) throws IOException {
buf.writeByte(item != null ? item.getAmount() : 0);
if (item != null) {
boolean empty = item == null || item.getAmount() <= 0;
buf.writeByte(!empty ? item.getAmount() : 0);
if (!empty) {
this.writeVarInt(buf, item.getId());
this.writeDataComponentPatch(buf, item.getDataComponents());
}