--- a/net/minecraft/network/FriendlyByteBuf.java +++ b/net/minecraft/network/FriendlyByteBuf.java @@ -81,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; @@ -584,7 +586,7 @@ try { NbtIo.writeAnyTag((Tag) tag, new ByteBufOutputStream(this)); return this; - } catch (IOException ioexception) { + } catch (Exception ioexception) { // CraftBukkit - IOException -> Exception throw new EncoderException(ioexception); } } @@ -611,8 +613,8 @@ } } - public FriendlyByteBuf writeItem(ItemStack itemstack) { - if (itemstack.isEmpty()) { + public FriendlyByteBuf writeItem(ItemStack stack) { + if (stack.isEmpty() || stack.getItem() == null) { // CraftBukkit - NPE fix itemstack.getItem() this.writeBoolean(false); } else { this.writeBoolean(true); @@ -641,6 +643,11 @@ 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; } }