mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Fix: Send a container close packet to Java for containers that could not be opened (#4861)
* Close containers if we did not manage to open it * Mark session inventory translator as nonnull
This commit is contained in:
parent
49f66c2a02
commit
9cdda707a3
3 changed files with 8 additions and 2 deletions
|
@ -222,7 +222,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
|
||||||
private boolean closingInventory;
|
private boolean closingInventory;
|
||||||
|
|
||||||
@Setter
|
@Setter
|
||||||
private InventoryTranslator inventoryTranslator = InventoryTranslator.PLAYER_INVENTORY_TRANSLATOR;
|
private @NonNull InventoryTranslator inventoryTranslator = InventoryTranslator.PLAYER_INVENTORY_TRANSLATOR;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use {@link #getNextItemNetId()} instead for consistency
|
* Use {@link #getNextItemNetId()} instead for consistency
|
||||||
|
|
|
@ -70,6 +70,7 @@ public class JavaOpenBookTranslator extends PacketTranslator<ClientboundOpenBook
|
||||||
}
|
}
|
||||||
|
|
||||||
InventoryTranslator translator = InventoryTranslator.inventoryTranslator(ContainerType.LECTERN);
|
InventoryTranslator translator = InventoryTranslator.inventoryTranslator(ContainerType.LECTERN);
|
||||||
|
Objects.requireNonNull(translator, "could not find lectern inventory translator!");
|
||||||
session.setInventoryTranslator(translator);
|
session.setInventoryTranslator(translator);
|
||||||
|
|
||||||
// Should never be null
|
// Should never be null
|
||||||
|
|
|
@ -57,6 +57,7 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.player.GameMode;
|
||||||
import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack;
|
import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack;
|
||||||
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponents;
|
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponents;
|
||||||
import org.geysermc.mcprotocollib.protocol.data.game.recipe.Ingredient;
|
import org.geysermc.mcprotocollib.protocol.data.game.recipe.Ingredient;
|
||||||
|
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.inventory.ServerboundContainerClosePacket;
|
||||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.inventory.ServerboundPickItemPacket;
|
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.inventory.ServerboundPickItemPacket;
|
||||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.inventory.ServerboundSetCreativeModeSlotPacket;
|
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.inventory.ServerboundSetCreativeModeSlotPacket;
|
||||||
import org.jetbrains.annotations.Contract;
|
import org.jetbrains.annotations.Contract;
|
||||||
|
@ -91,7 +92,7 @@ public class InventoryUtils {
|
||||||
|
|
||||||
public static void displayInventory(GeyserSession session, Inventory inventory) {
|
public static void displayInventory(GeyserSession session, Inventory inventory) {
|
||||||
InventoryTranslator translator = session.getInventoryTranslator();
|
InventoryTranslator translator = session.getInventoryTranslator();
|
||||||
if (translator != null && translator.prepareInventory(session, inventory)) {
|
if (translator.prepareInventory(session, inventory)) {
|
||||||
if (translator instanceof DoubleChestInventoryTranslator && !((Container) inventory).isUsingRealBlock()) {
|
if (translator instanceof DoubleChestInventoryTranslator && !((Container) inventory).isUsingRealBlock()) {
|
||||||
session.scheduleInEventLoop(() -> {
|
session.scheduleInEventLoop(() -> {
|
||||||
Inventory openInv = session.getOpenInventory();
|
Inventory openInv = session.getOpenInventory();
|
||||||
|
@ -110,7 +111,11 @@ public class InventoryUtils {
|
||||||
inventory.setDisplayed(true);
|
inventory.setDisplayed(true);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// Can occur if we e.g. did not find a spot to put a fake container in
|
||||||
|
ServerboundContainerClosePacket closePacket = new ServerboundContainerClosePacket(inventory.getJavaId());
|
||||||
|
session.sendDownstreamGamePacket(closePacket);
|
||||||
session.setOpenInventory(null);
|
session.setOpenInventory(null);
|
||||||
|
session.setInventoryTranslator(InventoryTranslator.PLAYER_INVENTORY_TRANSLATOR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue