Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-6480

Players cannot take the book from lecterns that were opened by a plugin

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • None
    • None
    • This server is running CraftBukkit version dev-Spigot-9fb885e-fd905ab (MC: 1.16.5) (Implementing API version 1.16.5-R0.1-SNAPSHOT)
    • Yes

      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.

       

            Unassigned Unassigned
            blablubbabc blablubbabc
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: