--- a/net/minecraft/network/FriendlyByteBuf.java +++ b/net/minecraft/network/FriendlyByteBuf.java @@ -80,6 +81,8 @@ import org.joml.Quaternionf; import org.joml.Vector3f; +import org.bukkit.craftbukkit.inventory.CraftItemStack; // CraftBukkit + public class FriendlyByteBuf extends ByteBuf { public static final int DEFAULT_NBT_QUOTA = 2097152; private final ByteBuf source; @@ -536,8 +586,8 @@ try { NbtIo.writeAnyTag(tag, new ByteBufOutputStream(this)); return this; - } catch (IOException var3) { - throw new EncoderException(var3); + } catch (Exception ioexception) { // CraftBukkit - IOException -> Exception + throw new EncoderException(ioexception); } } @@ -562,7 +614,7 @@ } public FriendlyByteBuf writeItem(ItemStack stack) { - if (stack.isEmpty()) { + if (stack.isEmpty() || stack.getItem() == null) { // CraftBukkit - NPE fix itemstack.getItem() this.writeBoolean(false); } else { this.writeBoolean(true); @@ -584,11 +638,17 @@ if (!this.readBoolean()) { return ItemStack.EMPTY; } else { - Item item = this.readById(BuiltInRegistries.ITEM); - int _byte = this.readByte(); - ItemStack itemStack = new ItemStack(item, _byte); - itemStack.setTag(this.readNbt()); - return itemStack; + Item item = (Item) this.readById((IdMap) BuiltInRegistries.ITEM); + byte b0 = this.readByte(); + ItemStack itemstack = new ItemStack(item, b0); + + itemstack.setTag(this.readNbt()); + // CraftBukkit start + if (itemstack.getTag() != null) { + CraftItemStack.setItemMeta(itemstack, CraftItemStack.getItemMeta(itemstack)); + } + // CraftBukkit end + return itemstack; } }