3030import org .cloudburstmc .nbt .NbtMapBuilder ;
3131import org .cloudburstmc .protocol .bedrock .data .inventory .ItemData ;
3232import org .geysermc .erosion .util .LecternUtils ;
33- import org .geysermc .geyser .GeyserImpl ;
34- import org .geysermc .geyser .inventory .Container ;
3533import org .geysermc .geyser .inventory .GeyserItemStack ;
3634import org .geysermc .geyser .inventory .Inventory ;
3735import org .geysermc .geyser .inventory .LecternContainer ;
@@ -55,7 +53,7 @@ public class LecternInventoryTranslator extends AbstractBlockInventoryTranslator
5553 * Hack: Java opens a lectern first, and then follows it up with a ClientboundContainerSetContentPacket
5654 * to actually send the book's contents. We delay opening the inventory until the book was sent.
5755 */
58- private boolean initialized = false ;
56+ private boolean receivedBook = false ;
5957
6058 public LecternInventoryTranslator () {
6159 super (1 , Blocks .LECTERN , org .cloudburstmc .protocol .bedrock .data .inventory .ContainerType .LECTERN , ContainerInventoryUpdater .INSTANCE );
@@ -64,11 +62,12 @@ public LecternInventoryTranslator() {
6462 @ Override
6563 public boolean prepareInventory (GeyserSession session , Inventory inventory ) {
6664 super .prepareInventory (session , inventory );
67- if (((Container ) inventory ).isUsingRealBlock ()) {
68- initialized = false ; // We have to wait until we get the book to show to the client
65+ if (((LecternContainer ) inventory ).isFakeLectern ()) {
66+ // See JavaOpenBookTranslator; this isn't a lectern but a book in the player inventory
67+ updateBook (session , inventory , inventory .getItem (0 ));
68+ receivedBook = true ;
6969 } else {
70- updateBook (session , inventory , inventory .getItem (0 )); // See JavaOpenBookTranslator; placed here manually
71- initialized = true ;
70+ receivedBook = false ; // We have to wait until we get the book
7271 }
7372 return true ;
7473 }
@@ -79,7 +78,7 @@ public void openInventory(GeyserSession session, Inventory inventory) {
7978 // "initialized" indicates whether we've received the book from the Java server yet.
8079 // dropping lectern book is the fun workaround when we have to enter the gui to drop the book.
8180 // Since we leave it immediately... don't open it!
82- if (initialized && !session .isDroppingLecternBook ()) {
81+ if (receivedBook && !session .isDroppingLecternBook ()) {
8382 super .openInventory (session , inventory );
8483 }
8584 }
@@ -122,8 +121,8 @@ public void updateInventory(GeyserSession session, Inventory inventory) {
122121 boolean isDropping = session .isDroppingLecternBook ();
123122 updateBook (session , inventory , itemStack );
124123
125- if (!initialized && !isDropping ) {
126- initialized = true ;
124+ if (!receivedBook && !isDropping ) {
125+ receivedBook = true ;
127126 openInventory (session , inventory );
128127 }
129128 }
0 commit comments