diff --git a/core/src/main/java/org/geysermc/geyser/inventory/holder/BlockInventoryHolder.java b/core/src/main/java/org/geysermc/geyser/inventory/holder/BlockInventoryHolder.java index 135e1057f..c11505ffb 100644 --- a/core/src/main/java/org/geysermc/geyser/inventory/holder/BlockInventoryHolder.java +++ b/core/src/main/java/org/geysermc/geyser/inventory/holder/BlockInventoryHolder.java @@ -32,8 +32,10 @@ import org.cloudburstmc.protocol.bedrock.packet.BlockEntityDataPacket; import org.cloudburstmc.protocol.bedrock.packet.ContainerClosePacket; import org.cloudburstmc.protocol.bedrock.packet.ContainerOpenPacket; import org.cloudburstmc.protocol.bedrock.packet.UpdateBlockPacket; +import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.inventory.Container; import org.geysermc.geyser.inventory.Inventory; +import org.geysermc.geyser.inventory.LecternContainer; import org.geysermc.geyser.registry.BlockRegistries; import org.geysermc.geyser.registry.type.BlockMapping; import org.geysermc.geyser.session.GeyserSession; @@ -151,13 +153,27 @@ public class BlockInventoryHolder extends InventoryHolder { @Override public void closeInventory(InventoryTranslator translator, GeyserSession session, Inventory inventory) { - if (((Container) inventory).isUsingRealBlock()) { - // No need to reset a block since we didn't change any blocks - // But send a container close packet because we aren't destroying the original. - ContainerClosePacket packet = new ContainerClosePacket(); - packet.setId((byte) inventory.getBedrockId()); - packet.setServerInitiated(true); - session.sendUpstreamPacket(packet); + if (inventory instanceof Container container) { + if (container.isUsingRealBlock() && !(inventory instanceof LecternContainer)) { + // No need to reset a block since we didn't change any blocks + // But send a container close packet because we aren't destroying the original. + ContainerClosePacket packet = new ContainerClosePacket(); + packet.setId((byte) inventory.getBedrockId()); + packet.setServerInitiated(true); + session.sendUpstreamPacket(packet); + return; + } + } else { + GeyserImpl.getInstance().getLogger().warning("Tried to close a non-container inventory in a block inventory holder! "); + if (GeyserImpl.getInstance().getLogger().isDebug()) { + GeyserImpl.getInstance().getLogger().debug("Current inventory: " + inventory); + GeyserImpl.getInstance().getLogger().debug("Open inventory: " + session.getOpenInventory()); + } + // Try to save ourselves? maybe? + // https://github.com/GeyserMC/Geyser/issues/4141 + // TODO: improve once this issue is pinned down properly + session.setOpenInventory(null); + session.setInventoryTranslator(InventoryTranslator.PLAYER_INVENTORY_TRANSLATOR); return; } diff --git a/core/src/main/java/org/geysermc/geyser/inventory/item/StoredItemMappings.java b/core/src/main/java/org/geysermc/geyser/inventory/item/StoredItemMappings.java index 6bb786896..c15a5d3b4 100644 --- a/core/src/main/java/org/geysermc/geyser/inventory/item/StoredItemMappings.java +++ b/core/src/main/java/org/geysermc/geyser/inventory/item/StoredItemMappings.java @@ -53,6 +53,7 @@ public class StoredItemMappings { private final ItemMapping upgradeTemplate; private final ItemMapping wheat; private final ItemMapping writableBook; + private final ItemMapping writtenBook; public StoredItemMappings(Map itemMappings) { this.bamboo = load(itemMappings, Items.BAMBOO); @@ -68,6 +69,7 @@ public class StoredItemMappings { this.upgradeTemplate = load(itemMappings, Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE); this.wheat = load(itemMappings, Items.WHEAT); this.writableBook = load(itemMappings, Items.WRITABLE_BOOK); + this.writtenBook = load(itemMappings, Items.WRITTEN_BOOK); } @NonNull diff --git a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java index d40b07939..b151f9b09 100644 --- a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java +++ b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java @@ -89,6 +89,7 @@ import org.cloudburstmc.protocol.bedrock.data.command.CommandEnumData; import org.cloudburstmc.protocol.bedrock.data.command.CommandPermission; import org.cloudburstmc.protocol.bedrock.data.command.SoftEnumUpdateType; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.cloudburstmc.protocol.bedrock.data.inventory.ItemData; import org.cloudburstmc.protocol.bedrock.packet.*; import org.cloudburstmc.protocol.common.DefinitionRegistry; import org.cloudburstmc.protocol.common.util.OptionalBoolean; @@ -595,6 +596,12 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource { */ private final Queue keepAliveCache = new ConcurrentLinkedQueue<>(); + /** + * Stores the book that is currently being read. Used in {@link org.geysermc.geyser.translator.protocol.java.inventory.JavaOpenBookTranslator} + */ + @Setter + private @Nullable ItemData currentBook = null; + private final GeyserCameraData cameraData; private final GeyserEntityData entityData; diff --git a/core/src/main/java/org/geysermc/geyser/translator/inventory/LecternInventoryTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/inventory/LecternInventoryTranslator.java index 92cd8a0d4..26721bfcc 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/inventory/LecternInventoryTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/inventory/LecternInventoryTranslator.java @@ -36,36 +36,71 @@ import org.cloudburstmc.nbt.NbtMapBuilder; import org.cloudburstmc.nbt.NbtType; import org.cloudburstmc.protocol.bedrock.data.inventory.ItemData; import org.geysermc.erosion.util.LecternUtils; +import org.geysermc.geyser.GeyserImpl; +import org.geysermc.geyser.inventory.Container; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.inventory.Inventory; import org.geysermc.geyser.inventory.LecternContainer; import org.geysermc.geyser.inventory.PlayerInventory; -import org.geysermc.geyser.inventory.updater.InventoryUpdater; +import org.geysermc.geyser.inventory.updater.ContainerInventoryUpdater; +import org.geysermc.geyser.network.GameProtocol; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.BlockEntityUtils; import org.geysermc.geyser.util.InventoryUtils; import java.util.Collections; -public class LecternInventoryTranslator extends BaseInventoryTranslator { - private final InventoryUpdater updater; +public class LecternInventoryTranslator extends AbstractBlockInventoryTranslator { + + /** + * Hack: Java opens a lectern first, and then follows it up with a ClientboundContainerSetContentPacket + * to actually send the book's contents. We delay opening the inventory until the book was sent. + */ + private boolean initialized = false; public LecternInventoryTranslator() { - super(1); - this.updater = new InventoryUpdater(); + super(1, "minecraft:lectern[facing=north,has_book=true,powered=true]", org.cloudburstmc.protocol.bedrock.data.inventory.ContainerType.LECTERN , ContainerInventoryUpdater.INSTANCE); } @Override public boolean prepareInventory(GeyserSession session, Inventory inventory) { + super.prepareInventory(session, inventory); + if (((Container) inventory).isUsingRealBlock()) { + initialized = false; // We have to wait until we get the book to show to the client + } else { + updateBook(session, inventory, inventory.getItem(0)); // See JavaOpenBookTranslator; placed here manually + initialized = true; + } return true; } @Override public void openInventory(GeyserSession session, Inventory inventory) { + // Hacky, but we're dealing with LECTERNS! It cannot not be hacky. + // "initialized" indicates whether we've received the book from the Java server yet. + // dropping lectern book is the fun workaround when we have to enter the gui to drop the book. + // Since we leave it immediately... don't open it! + if (initialized && !session.isDroppingLecternBook()) { + super.openInventory(session, inventory); + } } @Override public void closeInventory(GeyserSession session, Inventory inventory) { + // Of course, sending a simple ContainerClosePacket, or even breaking the block doesn't work to close a lectern. + // Heck, the latter crashes the client xd + // BDS just sends an empty base lectern tag... that kicks out the client. Fine. Let's do that! + LecternContainer lecternContainer = (LecternContainer) inventory; + Vector3i position = lecternContainer.isUsingRealBlock() ? session.getLastInteractionBlockPosition() : inventory.getHolderPosition(); + var baseLecternTag = LecternUtils.getBaseLecternTag(position.getX(), position.getY(), position.getZ(), 0); + BlockEntityUtils.updateBlockEntity(session, baseLecternTag.build(), position); + + super.closeInventory(session, inventory); // Removes the fake blocks if need be + + // Now: Restore the lectern, if it actually exists + if (lecternContainer.isUsingRealBlock()) { + GeyserImpl.getInstance().getWorldManager().sendLecternData(session, position.getX(), position.getY(), position.getZ()); + } } @Override @@ -82,13 +117,19 @@ public class LecternInventoryTranslator extends BaseInventoryTranslator { public void updateInventory(GeyserSession session, Inventory inventory) { GeyserItemStack itemStack = inventory.getItem(0); if (!itemStack.isEmpty()) { + boolean isDropping = session.isDroppingLecternBook(); updateBook(session, inventory, itemStack); + + if (!initialized && !isDropping) { + initialized = true; + openInventory(session, inventory); + } } } @Override public void updateSlot(GeyserSession session, Inventory inventory, int slot) { - this.updater.updateSlot(this, session, inventory, slot); + super.updateSlot(session, inventory, slot); if (slot == 0) { updateBook(session, inventory, inventory.getItem(0)); } @@ -107,11 +148,14 @@ public class LecternInventoryTranslator extends BaseInventoryTranslator { InventoryUtils.closeInventory(session, inventory.getJavaId(), false); } else if (lecternContainer.getBlockEntityTag() == null) { CompoundTag tag = book.getNbt(); - // Position has to be the last interacted position... right? - Vector3i position = session.getLastInteractionBlockPosition(); + Vector3i position = lecternContainer.isUsingRealBlock() ? session.getLastInteractionBlockPosition() : inventory.getHolderPosition(); + // If shouldExpectLecternHandled returns true, this is already handled for us // shouldRefresh means that we should boot out the client on our side because their lectern GUI isn't updated yet - boolean shouldRefresh = !session.getGeyser().getWorldManager().shouldExpectLecternHandled(session) && !session.getLecternCache().contains(position); + // TODO: yeet after 1.20.60 is minimum supported version + boolean shouldRefresh = !session.getGeyser().getWorldManager().shouldExpectLecternHandled(session) + && !session.getLecternCache().contains(position) + && !GameProtocol.is1_20_60orHigher(session.getUpstream().getProtocolVersion()); NbtMap blockEntityTag; if (tag != null) { @@ -147,10 +191,11 @@ public class LecternInventoryTranslator extends BaseInventoryTranslator { // the block entity tag lecternContainer.setBlockEntityTag(blockEntityTag); lecternContainer.setPosition(position); + + BlockEntityUtils.updateBlockEntity(session, blockEntityTag, position); + session.getLecternCache().add(position); + if (shouldRefresh) { - // Update the lectern because it's not updated client-side - BlockEntityUtils.updateBlockEntity(session, blockEntityTag, position); - session.getLecternCache().add(position); // Close the window - we will reopen it once the client has this data synced ServerboundContainerClosePacket closeWindowPacket = new ServerboundContainerClosePacket(lecternContainer.getJavaId()); session.sendDownstreamGamePacket(closeWindowPacket); @@ -161,6 +206,6 @@ public class LecternInventoryTranslator extends BaseInventoryTranslator { @Override public Inventory createInventory(String name, int windowId, ContainerType containerType, PlayerInventory playerInventory) { - return new LecternContainer(name, windowId, this.size, containerType, playerInventory); + return new LecternContainer(name, windowId, this.size + playerInventory.getSize(), containerType, playerInventory); } } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockInventoryTransactionTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockInventoryTransactionTranslator.java index 29a78daf3..101035cb5 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockInventoryTransactionTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockInventoryTransactionTranslator.java @@ -380,6 +380,8 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator legacySlots = packet.getLegacySlots(); - if (packet.getActions().size() == 1 && legacySlots.size() > 0) { + if (packet.getActions().size() == 1 && !legacySlots.isEmpty()) { InventoryActionData actionData = packet.getActions().get(0); LegacySetItemSlotData slotData = legacySlots.get(0); if (slotData.getContainerId() == 6 && !actionData.getFromItem().isNull()) { diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockLecternUpdateTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockLecternUpdateTranslator.java index b2a34d904..2678128ed 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockLecternUpdateTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockLecternUpdateTranslator.java @@ -31,8 +31,10 @@ import com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.Ser import com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundContainerClosePacket; import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundUseItemOnPacket; import org.cloudburstmc.protocol.bedrock.packet.LecternUpdatePacket; +import org.geysermc.geyser.inventory.Inventory; import org.geysermc.geyser.inventory.LecternContainer; import org.geysermc.geyser.session.GeyserSession; +import org.geysermc.geyser.translator.inventory.LecternInventoryTranslator; import org.geysermc.geyser.translator.protocol.PacketTranslator; import org.geysermc.geyser.translator.protocol.Translator; import org.geysermc.geyser.util.InventoryUtils; @@ -77,6 +79,15 @@ public class BedrockLecternUpdateTranslator extends PacketTranslator containerOpenPacket.setBlockPosition(entity.getPosition().toInt()); session.sendUpstreamPacket(containerOpenPacket); } + } else { + // Case: Player opens a player inventory, while we think it shouldn't have! + // Close all inventories, reset to player inventory. + InventoryUtils.closeInventory(session, session.getOpenInventory().getJavaId(), false); } break; } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/inventory/JavaContainerSetContentTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/inventory/JavaContainerSetContentTranslator.java index cfe1c404e..2f8204871 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/inventory/JavaContainerSetContentTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/inventory/JavaContainerSetContentTranslator.java @@ -27,6 +27,7 @@ package org.geysermc.geyser.translator.protocol.java.inventory; import com.github.steveice10.mc.protocol.packet.ingame.clientbound.inventory.ClientboundContainerSetContentPacket; import org.geysermc.geyser.GeyserImpl; +import org.geysermc.geyser.GeyserLogger; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.inventory.Inventory; import org.geysermc.geyser.session.GeyserSession; @@ -48,12 +49,12 @@ public class JavaContainerSetContentTranslator extends PacketTranslator= inventorySize) { - GeyserImpl geyser = session.getGeyser(); - geyser.getLogger().warning("ClientboundContainerSetContentPacket sent to " + session.bedrockUsername() + GeyserLogger logger = session.getGeyser().getLogger(); + logger.warning("ClientboundContainerSetContentPacket sent to " + session.bedrockUsername() + " that exceeds inventory size!"); - if (geyser.getConfig().isDebugMode()) { - geyser.getLogger().debug(packet); - geyser.getLogger().debug(inventory); + if (logger.isDebug()) { + logger.debug(packet); + logger.debug(inventory); } updateInventory(session, inventory, packet.getContainerId()); // 1.18.1 behavior: the previous items will be correctly set, but the state ID and carried item will not diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/inventory/JavaContainerSetSlotTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/inventory/JavaContainerSetSlotTranslator.java index 734c6945a..4b8eef00d 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/inventory/JavaContainerSetSlotTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/inventory/JavaContainerSetSlotTranslator.java @@ -34,7 +34,7 @@ import org.cloudburstmc.protocol.bedrock.data.inventory.crafting.recipe.ShapedRe import org.cloudburstmc.protocol.bedrock.data.inventory.descriptor.ItemDescriptorWithCount; import org.cloudburstmc.protocol.bedrock.packet.CraftingDataPacket; import org.cloudburstmc.protocol.bedrock.packet.InventorySlotPacket; -import org.geysermc.geyser.GeyserImpl; +import org.geysermc.geyser.GeyserLogger; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.inventory.Inventory; import org.geysermc.geyser.inventory.recipe.GeyserShapedRecipe; @@ -65,8 +65,9 @@ public class JavaContainerSetSlotTranslator extends PacketTranslator= inventory.getSize()) { - GeyserImpl geyser = session.getGeyser(); - geyser.getLogger().warning("ClientboundContainerSetSlotPacket sent to " + session.bedrockUsername() + GeyserLogger logger = session.getGeyser().getLogger(); + logger.warning("ClientboundContainerSetSlotPacket sent to " + session.bedrockUsername() + " that exceeds inventory size!"); - if (geyser.getConfig().isDebugMode()) { - geyser.getLogger().debug(packet); - geyser.getLogger().debug(inventory); + if (logger.isDebug()) { + logger.debug(packet.toString()); + logger.debug(inventory.toString()); } // 1.19.0 behavior: the state ID will not be set due to exception return; diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/inventory/JavaOpenBookTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/inventory/JavaOpenBookTranslator.java new file mode 100644 index 000000000..f9cf4ee28 --- /dev/null +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/inventory/JavaOpenBookTranslator.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2019-2024 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.geyser.translator.protocol.java.inventory; + +import com.github.steveice10.mc.protocol.data.game.inventory.ContainerType; +import com.github.steveice10.mc.protocol.packet.ingame.clientbound.inventory.ClientboundOpenBookPacket; +import com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundContainerClosePacket; +import org.geysermc.geyser.inventory.GeyserItemStack; +import org.geysermc.geyser.inventory.Inventory; +import org.geysermc.geyser.item.Items; +import org.geysermc.geyser.network.GameProtocol; +import org.geysermc.geyser.session.GeyserSession; +import org.geysermc.geyser.translator.inventory.InventoryTranslator; +import org.geysermc.geyser.translator.protocol.PacketTranslator; +import org.geysermc.geyser.translator.protocol.Translator; +import org.geysermc.geyser.util.InventoryUtils; + +import java.util.Objects; + +@Translator(packet = ClientboundOpenBookPacket.class) +public class JavaOpenBookTranslator extends PacketTranslator { + + /** + * Unlike other fake inventories that rely on placing blocks in the world; + * the virtual lectern workaround for books isn't triggered the same way. + * Specifically, we don't get a window id - hence, we just use our own! + */ + private final static int FAKE_LECTERN_WINDOW_ID = -69; + + @Override + public void translate(GeyserSession session, ClientboundOpenBookPacket packet) { + GeyserItemStack stack = session.getPlayerInventory().getItemInHand(); + + // Don't spawn a fake lectern for books already opened "normally" by the client. + if (stack.getItemData(session).equals(session.getCurrentBook())) { + session.setCurrentBook(null); + return; + } + + // Only post 1.20.60 is it possible to tell the client to open a lectern. + if (!GameProtocol.is1_20_60orHigher(session.getUpstream().getProtocolVersion())) { + return; + } + + if (stack.asItem().equals(Items.WRITTEN_BOOK)) { + Inventory openInventory = session.getOpenInventory(); + if (openInventory != null) { + InventoryUtils.closeInventory(session, openInventory.getJavaId(), true); + + ServerboundContainerClosePacket closeWindowPacket = new ServerboundContainerClosePacket(openInventory.getJavaId()); + session.sendDownstreamGamePacket(closeWindowPacket); + } + + InventoryTranslator translator = InventoryTranslator.inventoryTranslator(ContainerType.LECTERN); + session.setInventoryTranslator(translator); + + // Should never be null + Objects.requireNonNull(translator, "lectern translator must exist"); + Inventory inventory = translator.createInventory("", FAKE_LECTERN_WINDOW_ID, ContainerType.LECTERN , session.getPlayerInventory()); + inventory.setItem(0, stack, session); + InventoryUtils.openInventory(session, inventory); + } + } +} diff --git a/core/src/main/java/org/geysermc/geyser/util/InventoryUtils.java b/core/src/main/java/org/geysermc/geyser/util/InventoryUtils.java index 4d91f853c..30b2907cc 100644 --- a/core/src/main/java/org/geysermc/geyser/util/InventoryUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/InventoryUtils.java @@ -45,6 +45,7 @@ import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.inventory.Container; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.inventory.Inventory; +import org.geysermc.geyser.inventory.LecternContainer; import org.geysermc.geyser.inventory.PlayerInventory; import org.geysermc.geyser.inventory.click.Click; import org.geysermc.geyser.inventory.recipe.GeyserRecipe; @@ -123,7 +124,9 @@ public class InventoryUtils { if (inventory != null) { InventoryTranslator translator = session.getInventoryTranslator(); translator.closeInventory(session, inventory); - if (confirm && inventory.isDisplayed() && !inventory.isPending() && !(translator instanceof LecternInventoryTranslator)) { + if (confirm && inventory.isDisplayed() && !inventory.isPending() + && !(translator instanceof LecternInventoryTranslator) // TODO: double-check + ) { session.setClosingInventory(true); } } @@ -133,6 +136,10 @@ public class InventoryUtils { public static @Nullable Inventory getInventory(GeyserSession session, int javaId) { if (javaId == 0) { + // ugly hack: lecterns aren't their own inventory on Java, and can hence be closed with e.g. an id of 0 + if (session.getOpenInventory() instanceof LecternContainer) { + return session.getOpenInventory(); + } return session.getPlayerInventory(); } else { Inventory openInventory = session.getOpenInventory();