How to reproduce
Give yourself a
written_book
with the following command:/give @p written_book{pages:["{\"selector\":\"@p\"}"],title:"",author:""}
Open it
→ ✔ You will see your name written at the topRemove that book from your inventory and
/give
you this book againPlace it in your offhand
Open it
→ ❌ You will see@p
the first time. Close and reopen it again. This time you will see your name.
This issue concern also @a
, @e
, @r
... and scores display.
Code analysis
Based on 1.11 decompiled using MCP 9.35 rc1
The problem is that the method net.minecraft.item.ItemWrittenBook.resolveContents(ItemStack, EntityPlayer)
tests if the player is holding the item in the mainhand and only if this is the case sends a SPacketSetSlot
packet.
This condition does not really make sense because the item is modified anyways, the client inventory just won't be updated. This can be seen by dropping the book, picking it back up and opening it in the offhand again.
The best way to fix this would probably be to remove this condition.
Confirmed for 1.11. This could be related to MC-84005.