[SPIGOT-6480] Players cannot take the book from lecterns that were opened by a plugin Created: 29/May/21  Updated: 29/May/21  Resolved: 29/May/21

Status: Resolved
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: blablubbabc Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: inventory, lectern

Version: This server is running CraftBukkit version dev-Spigot-9fb885e-fd905ab (MC: 1.16.5) (Implementing API version 1.16.5-R0.1-SNAPSHOT)
Guidelines Read: Yes

 Description   

When a plugin opens the inventory of a lectern for a player via

 

Player#openInventory(lecternBlockState.getInventory())

clicking the button for taking the book has no effect.

The cause of this issue is as follows:
CraftInventoryLectern (the inventory returned by the lectern BlockState) wraps the LecternInventory of TileEntityLectern#inventory. This inventory is only an IInventory, not an ITileInventory. When calling Player#openInventory, CraftBukkit checks whether this inventory is a tile inventory and then forwards it to EntityPlayer#openContainer. Otherwise, as it is the case here for the lectern inventory, the inventory is opened via CraftHumanEntity#openCustomInventory.
This latter method uses CraftContainer to open the inventory view, which is more limited and behaves differently compared to when vanilla Minecraft opens the lectern inventory via EntityPlayer#openContainer(lecternTileEntity). For instance, CraftContainer doesn't handle the callback

public boolean a(EntityHuman entityhuman, int i)

The regular ContainerLectern reacts to this callback by switching the book pages or taking the book item from the lectern.

I will prepare a PR to open the lectern inventory via EntityPlayer#openContainer instead, similar to how vanilla Minecraft does it.

 


Generated at Fri Mar 14 09:35:29 UTC 2025 using Jira 10.3.3#10030003-sha1:d220e3fefc8dfc6d47f522d3b9a20c1455e12b7b.