3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-26 16:12:46 +01:00

Ensure bedrock inventory id is at most 100 (#3260)

Dieser Commit ist enthalten in:
AJ Ferguson 2022-08-29 12:26:30 -04:00 committet von GitHub
Ursprung 670308edc2
Commit 8e47a9f5e9
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
24 geänderte Dateien mit 56 neuen und 49 gelöschten Zeilen

Datei anzeigen

@ -45,7 +45,7 @@ import java.util.Arrays;
@ToString @ToString
public abstract class Inventory { public abstract class Inventory {
@Getter @Getter
protected final int id; protected final int javaId;
/** /**
* The Java inventory state ID from the server. As of Java Edition 1.18.1 this value has one instance per player. * The Java inventory state ID from the server. As of Java Edition 1.18.1 this value has one instance per player.
@ -94,15 +94,22 @@ public abstract class Inventory {
this("Inventory", id, size, containerType); this("Inventory", id, size, containerType);
} }
protected Inventory(String title, int id, int size, ContainerType containerType) { protected Inventory(String title, int javaId, int size, ContainerType containerType) {
this.title = title; this.title = title;
this.id = id; this.javaId = javaId;
this.size = size; this.size = size;
this.containerType = containerType; this.containerType = containerType;
this.items = new GeyserItemStack[size]; this.items = new GeyserItemStack[size];
Arrays.fill(items, GeyserItemStack.EMPTY); Arrays.fill(items, GeyserItemStack.EMPTY);
} }
// This is to prevent conflicts with special bedrock inventory IDs.
// The vanilla java server only sends an ID between 1 and 100 when opening an inventory,
// so this is rarely needed. (certain plugins)
public int getBedrockId() {
return javaId <= 100 ? javaId : (javaId % 100) + 1;
}
public GeyserItemStack getItem(int slot) { public GeyserItemStack getItem(int slot) {
if (slot > this.size) { if (slot > this.size) {
GeyserImpl.getInstance().getLogger().debug("Tried to get an item out of bounds! " + this); GeyserImpl.getInstance().getLogger().debug("Tried to get an item out of bounds! " + this);

Datei anzeigen

@ -144,7 +144,7 @@ public final class ClickPlan {
} }
ServerboundContainerClickPacket clickPacket = new ServerboundContainerClickPacket( ServerboundContainerClickPacket clickPacket = new ServerboundContainerClickPacket(
inventory.getId(), inventory.getJavaId(),
stateId, stateId,
action.slot, action.slot,
action.click.actionType, action.click.actionType,

Datei anzeigen

@ -133,7 +133,7 @@ public class BlockInventoryHolder extends InventoryHolder {
@Override @Override
public void openInventory(InventoryTranslator translator, GeyserSession session, Inventory inventory) { public void openInventory(InventoryTranslator translator, GeyserSession session, Inventory inventory) {
ContainerOpenPacket containerOpenPacket = new ContainerOpenPacket(); ContainerOpenPacket containerOpenPacket = new ContainerOpenPacket();
containerOpenPacket.setId((byte) inventory.getId()); containerOpenPacket.setId((byte) inventory.getBedrockId());
containerOpenPacket.setType(containerType); containerOpenPacket.setType(containerType);
containerOpenPacket.setBlockPosition(inventory.getHolderPosition()); containerOpenPacket.setBlockPosition(inventory.getHolderPosition());
containerOpenPacket.setUniqueEntityId(inventory.getHolderId()); containerOpenPacket.setUniqueEntityId(inventory.getHolderId());
@ -146,7 +146,7 @@ public class BlockInventoryHolder extends InventoryHolder {
// No need to reset a block since we didn't change any blocks // 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. // But send a container close packet because we aren't destroying the original.
ContainerClosePacket packet = new ContainerClosePacket(); ContainerClosePacket packet = new ContainerClosePacket();
packet.setId((byte) inventory.getId()); packet.setId((byte) inventory.getBedrockId());
packet.setUnknownBool0(true); //TODO needs to be changed in Protocol to "server-side" or something packet.setUnknownBool0(true); //TODO needs to be changed in Protocol to "server-side" or something
session.sendUpstreamPacket(packet); session.sendUpstreamPacket(packet);
return; return;

Datei anzeigen

@ -59,7 +59,7 @@ public class ChestInventoryUpdater extends InventoryUpdater {
} }
InventoryContentPacket contentPacket = new InventoryContentPacket(); InventoryContentPacket contentPacket = new InventoryContentPacket();
contentPacket.setContainerId(inventory.getId()); contentPacket.setContainerId(inventory.getBedrockId());
contentPacket.setContents(bedrockItems); contentPacket.setContents(bedrockItems);
session.sendUpstreamPacket(contentPacket); session.sendUpstreamPacket(contentPacket);
} }
@ -70,7 +70,7 @@ public class ChestInventoryUpdater extends InventoryUpdater {
return true; return true;
InventorySlotPacket slotPacket = new InventorySlotPacket(); InventorySlotPacket slotPacket = new InventorySlotPacket();
slotPacket.setContainerId(inventory.getId()); slotPacket.setContainerId(inventory.getBedrockId());
slotPacket.setSlot(translator.javaSlotToBedrock(javaSlot)); slotPacket.setSlot(translator.javaSlotToBedrock(javaSlot));
slotPacket.setItem(inventory.getItem(javaSlot).getItemData(session)); slotPacket.setItem(inventory.getItem(javaSlot).getItemData(session));
session.sendUpstreamPacket(slotPacket); session.sendUpstreamPacket(slotPacket);

Datei anzeigen

@ -47,7 +47,7 @@ public class ContainerInventoryUpdater extends InventoryUpdater {
} }
InventoryContentPacket contentPacket = new InventoryContentPacket(); InventoryContentPacket contentPacket = new InventoryContentPacket();
contentPacket.setContainerId(inventory.getId()); contentPacket.setContainerId(inventory.getBedrockId());
contentPacket.setContents(Arrays.asList(bedrockItems)); contentPacket.setContents(Arrays.asList(bedrockItems));
session.sendUpstreamPacket(contentPacket); session.sendUpstreamPacket(contentPacket);
} }
@ -58,7 +58,7 @@ public class ContainerInventoryUpdater extends InventoryUpdater {
return true; return true;
InventorySlotPacket slotPacket = new InventorySlotPacket(); InventorySlotPacket slotPacket = new InventorySlotPacket();
slotPacket.setContainerId(inventory.getId()); slotPacket.setContainerId(inventory.getBedrockId());
slotPacket.setSlot(translator.javaSlotToBedrock(javaSlot)); slotPacket.setSlot(translator.javaSlotToBedrock(javaSlot));
slotPacket.setItem(inventory.getItem(javaSlot).getItemData(session)); slotPacket.setItem(inventory.getItem(javaSlot).getItemData(session));
session.sendUpstreamPacket(slotPacket); session.sendUpstreamPacket(slotPacket);

Datei anzeigen

@ -47,7 +47,7 @@ public class HorseInventoryUpdater extends InventoryUpdater {
} }
InventoryContentPacket contentPacket = new InventoryContentPacket(); InventoryContentPacket contentPacket = new InventoryContentPacket();
contentPacket.setContainerId(inventory.getId()); contentPacket.setContainerId(inventory.getBedrockId());
contentPacket.setContents(Arrays.asList(bedrockItems)); contentPacket.setContents(Arrays.asList(bedrockItems));
session.sendUpstreamPacket(contentPacket); session.sendUpstreamPacket(contentPacket);
} }

Datei anzeigen

@ -62,7 +62,7 @@ public class BeaconInventoryTranslator extends AbstractBlockInventoryTranslator
@Override @Override
public void openInventory(InventoryTranslator translator, GeyserSession session, Inventory inventory) { public void openInventory(InventoryTranslator translator, GeyserSession session, Inventory inventory) {
if (!((BeaconContainer) inventory).isUsingRealBlock()) { if (!((BeaconContainer) inventory).isUsingRealBlock()) {
InventoryUtils.closeInventory(session, inventory.getId(), false); InventoryUtils.closeInventory(session, inventory.getJavaId(), false);
return; return;
} }
super.openInventory(translator, session, inventory); super.openInventory(translator, session, inventory);

Datei anzeigen

@ -43,7 +43,7 @@ public class BrewingInventoryTranslator extends AbstractBlockInventoryTranslator
public void openInventory(GeyserSession session, Inventory inventory) { public void openInventory(GeyserSession session, Inventory inventory) {
super.openInventory(session, inventory); super.openInventory(session, inventory);
ContainerSetDataPacket dataPacket = new ContainerSetDataPacket(); ContainerSetDataPacket dataPacket = new ContainerSetDataPacket();
dataPacket.setWindowId((byte) inventory.getId()); dataPacket.setWindowId((byte) inventory.getBedrockId());
dataPacket.setProperty(ContainerSetDataPacket.BREWING_STAND_FUEL_TOTAL); dataPacket.setProperty(ContainerSetDataPacket.BREWING_STAND_FUEL_TOTAL);
dataPacket.setValue(20); dataPacket.setValue(20);
session.sendUpstreamPacket(dataPacket); session.sendUpstreamPacket(dataPacket);
@ -52,7 +52,7 @@ public class BrewingInventoryTranslator extends AbstractBlockInventoryTranslator
@Override @Override
public void updateProperty(GeyserSession session, Inventory inventory, int key, int value) { public void updateProperty(GeyserSession session, Inventory inventory, int key, int value) {
ContainerSetDataPacket dataPacket = new ContainerSetDataPacket(); ContainerSetDataPacket dataPacket = new ContainerSetDataPacket();
dataPacket.setWindowId((byte) inventory.getId()); dataPacket.setWindowId((byte) inventory.getBedrockId());
switch (key) { switch (key) {
case 0: case 0:
dataPacket.setProperty(ContainerSetDataPacket.BREWING_STAND_BREW_TIME); dataPacket.setProperty(ContainerSetDataPacket.BREWING_STAND_BREW_TIME);

Datei anzeigen

@ -127,7 +127,7 @@ public class EnchantingInventoryTranslator extends AbstractBlockInventoryTransla
// Slot should be determined as 0, 1, or 2 // Slot should be determined as 0, 1, or 2
return rejectRequest(request); return rejectRequest(request);
} }
ServerboundContainerButtonClickPacket packet = new ServerboundContainerButtonClickPacket(inventory.getId(), javaSlot); ServerboundContainerButtonClickPacket packet = new ServerboundContainerButtonClickPacket(inventory.getJavaId(), javaSlot);
session.sendDownstreamPacket(packet); session.sendDownstreamPacket(packet);
return acceptRequest(request, makeContainerEntries(session, inventory, IntSets.emptySet())); return acceptRequest(request, makeContainerEntries(session, inventory, IntSets.emptySet()));
} }

Datei anzeigen

@ -52,7 +52,7 @@ public class Generic3X3InventoryTranslator extends AbstractBlockInventoryTransla
@Override @Override
public void openInventory(GeyserSession session, Inventory inventory) { public void openInventory(GeyserSession session, Inventory inventory) {
ContainerOpenPacket containerOpenPacket = new ContainerOpenPacket(); ContainerOpenPacket containerOpenPacket = new ContainerOpenPacket();
containerOpenPacket.setId((byte) inventory.getId()); containerOpenPacket.setId((byte) inventory.getBedrockId());
// Required for opening the real block - otherwise, if the container type is incorrect, it refuses to open // Required for opening the real block - otherwise, if the container type is incorrect, it refuses to open
containerOpenPacket.setType(((Generic3X3Container) inventory).isDropper() ? com.nukkitx.protocol.bedrock.data.inventory.ContainerType.DROPPER : com.nukkitx.protocol.bedrock.data.inventory.ContainerType.DISPENSER); containerOpenPacket.setType(((Generic3X3Container) inventory).isDropper() ? com.nukkitx.protocol.bedrock.data.inventory.ContainerType.DROPPER : com.nukkitx.protocol.bedrock.data.inventory.ContainerType.DISPENSER);
containerOpenPacket.setBlockPosition(inventory.getHolderPosition()); containerOpenPacket.setBlockPosition(inventory.getHolderPosition());

Datei anzeigen

@ -804,7 +804,7 @@ public abstract class InventoryTranslator {
*/ */
//TODO: compatibility for simulated inventory (ClickPlan) //TODO: compatibility for simulated inventory (ClickPlan)
private static int findTempSlot(Inventory inventory, GeyserItemStack item, boolean emptyOnly, int... slotBlacklist) { private static int findTempSlot(Inventory inventory, GeyserItemStack item, boolean emptyOnly, int... slotBlacklist) {
int offset = inventory.getId() == 0 ? 1 : 0; //offhand is not a viable temp slot int offset = inventory.getJavaId() == 0 ? 1 : 0; //offhand is not a viable temp slot
HashSet<GeyserItemStack> itemBlacklist = new HashSet<>(slotBlacklist.length + 1); HashSet<GeyserItemStack> itemBlacklist = new HashSet<>(slotBlacklist.length + 1);
itemBlacklist.add(item); itemBlacklist.add(item);

Datei anzeigen

@ -99,10 +99,10 @@ public class LecternInventoryTranslator extends BaseInventoryTranslator {
LecternContainer lecternContainer = (LecternContainer) inventory; LecternContainer lecternContainer = (LecternContainer) inventory;
if (session.isDroppingLecternBook()) { if (session.isDroppingLecternBook()) {
// We have to enter the inventory GUI to eject the book // We have to enter the inventory GUI to eject the book
ServerboundContainerButtonClickPacket packet = new ServerboundContainerButtonClickPacket(inventory.getId(), 3); ServerboundContainerButtonClickPacket packet = new ServerboundContainerButtonClickPacket(inventory.getJavaId(), 3);
session.sendDownstreamPacket(packet); session.sendDownstreamPacket(packet);
session.setDroppingLecternBook(false); session.setDroppingLecternBook(false);
InventoryUtils.closeInventory(session, inventory.getId(), false); InventoryUtils.closeInventory(session, inventory.getJavaId(), false);
} else if (lecternContainer.getBlockEntityTag() == null) { } else if (lecternContainer.getBlockEntityTag() == null) {
CompoundTag tag = book.getNbt(); CompoundTag tag = book.getNbt();
// Position has to be the last interacted position... right? // Position has to be the last interacted position... right?
@ -150,9 +150,9 @@ public class LecternInventoryTranslator extends BaseInventoryTranslator {
BlockEntityUtils.updateBlockEntity(session, blockEntityTag, position); BlockEntityUtils.updateBlockEntity(session, blockEntityTag, position);
session.getLecternCache().add(position); session.getLecternCache().add(position);
// Close the window - we will reopen it once the client has this data synced // Close the window - we will reopen it once the client has this data synced
ServerboundContainerClosePacket closeWindowPacket = new ServerboundContainerClosePacket(lecternContainer.getId()); ServerboundContainerClosePacket closeWindowPacket = new ServerboundContainerClosePacket(lecternContainer.getJavaId());
session.sendDownstreamPacket(closeWindowPacket); session.sendDownstreamPacket(closeWindowPacket);
InventoryUtils.closeInventory(session, inventory.getId(), false); InventoryUtils.closeInventory(session, inventory.getJavaId(), false);
} }
} }
} }

Datei anzeigen

@ -147,7 +147,7 @@ public class LoomInventoryTranslator extends AbstractBlockInventoryTranslator {
// Java's formula: 4 * row + col // Java's formula: 4 * row + col
// And the Java loom window has a fixed row/width of four // And the Java loom window has a fixed row/width of four
// So... Number / 4 = row (so we don't have to bother there), and number % 4 is our column, which leads us back to our index. :) // So... Number / 4 = row (so we don't have to bother there), and number % 4 is our column, which leads us back to our index. :)
ServerboundContainerButtonClickPacket packet = new ServerboundContainerButtonClickPacket(inventory.getId(), index); ServerboundContainerButtonClickPacket packet = new ServerboundContainerButtonClickPacket(inventory.getJavaId(), index);
session.sendDownstreamPacket(packet); session.sendDownstreamPacket(packet);
GeyserItemStack inputCopy = inventory.getItem(0).copy(1); GeyserItemStack inputCopy = inventory.getItem(0).copy(1);

Datei anzeigen

@ -68,7 +68,7 @@ public class StonecutterInventoryTranslator extends AbstractBlockInventoryTransl
ItemStack javaOutput = craftingData.output(); ItemStack javaOutput = craftingData.output();
// Getting the index of the item in the Java stonecutter list // Getting the index of the item in the Java stonecutter list
ServerboundContainerButtonClickPacket packet = new ServerboundContainerButtonClickPacket(inventory.getId(), button); ServerboundContainerButtonClickPacket packet = new ServerboundContainerButtonClickPacket(inventory.getJavaId(), button);
session.sendDownstreamPacket(packet); session.sendDownstreamPacket(packet);
container.setStonecutterButton(button); container.setStonecutterButton(button);
if (inventory.getItem(1).getJavaId() != javaOutput.getId()) { if (inventory.getItem(1).getJavaId() != javaOutput.getId()) {

Datei anzeigen

@ -130,7 +130,7 @@ public class DoubleChestInventoryTranslator extends ChestInventoryTranslator {
@Override @Override
public void openInventory(GeyserSession session, Inventory inventory) { public void openInventory(GeyserSession session, Inventory inventory) {
ContainerOpenPacket containerOpenPacket = new ContainerOpenPacket(); ContainerOpenPacket containerOpenPacket = new ContainerOpenPacket();
containerOpenPacket.setId((byte) inventory.getId()); containerOpenPacket.setId((byte) inventory.getBedrockId());
containerOpenPacket.setType(ContainerType.CONTAINER); containerOpenPacket.setType(ContainerType.CONTAINER);
containerOpenPacket.setBlockPosition(inventory.getHolderPosition()); containerOpenPacket.setBlockPosition(inventory.getHolderPosition());
containerOpenPacket.setUniqueEntityId(inventory.getHolderId()); containerOpenPacket.setUniqueEntityId(inventory.getHolderId());
@ -143,7 +143,7 @@ public class DoubleChestInventoryTranslator extends ChestInventoryTranslator {
// No need to reset a block since we didn't change any blocks // 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. // But send a container close packet because we aren't destroying the original.
ContainerClosePacket packet = new ContainerClosePacket(); ContainerClosePacket packet = new ContainerClosePacket();
packet.setId((byte) inventory.getId()); packet.setId((byte) inventory.getBedrockId());
packet.setUnknownBool0(true); //TODO needs to be changed in Protocol to "server-side" or something packet.setUnknownBool0(true); //TODO needs to be changed in Protocol to "server-side" or something
session.sendUpstreamPacket(packet); session.sendUpstreamPacket(packet);
return; return;

Datei anzeigen

@ -43,7 +43,7 @@ public abstract class AbstractFurnaceInventoryTranslator extends AbstractBlockIn
@Override @Override
public void updateProperty(GeyserSession session, Inventory inventory, int key, int value) { public void updateProperty(GeyserSession session, Inventory inventory, int key, int value) {
ContainerSetDataPacket dataPacket = new ContainerSetDataPacket(); ContainerSetDataPacket dataPacket = new ContainerSetDataPacket();
dataPacket.setWindowId((byte) inventory.getId()); dataPacket.setWindowId((byte) inventory.getBedrockId());
switch (key) { switch (key) {
case 0: case 0:
dataPacket.setProperty(ContainerSetDataPacket.FURNACE_LIT_TIME); dataPacket.setProperty(ContainerSetDataPacket.FURNACE_LIT_TIME);

Datei anzeigen

@ -105,7 +105,7 @@ public abstract class ChestedHorseInventoryTranslator extends AbstractHorseInven
} }
InventoryContentPacket horseContentsPacket = new InventoryContentPacket(); InventoryContentPacket horseContentsPacket = new InventoryContentPacket();
horseContentsPacket.setContainerId(inventory.getId()); horseContentsPacket.setContainerId(inventory.getBedrockId());
horseContentsPacket.setContents(Arrays.asList(horseItems)); horseContentsPacket.setContents(Arrays.asList(horseItems));
session.sendUpstreamPacket(horseContentsPacket); session.sendUpstreamPacket(horseContentsPacket);
} }

Datei anzeigen

@ -40,23 +40,23 @@ public class BedrockContainerCloseTranslator extends PacketTranslator<ContainerC
@Override @Override
public void translate(GeyserSession session, ContainerClosePacket packet) { public void translate(GeyserSession session, ContainerClosePacket packet) {
byte windowId = packet.getId(); byte bedrockId = packet.getId();
//Client wants close confirmation //Client wants close confirmation
session.sendUpstreamPacket(packet); session.sendUpstreamPacket(packet);
session.setClosingInventory(false); session.setClosingInventory(false);
if (windowId == -1 && session.getOpenInventory() instanceof MerchantContainer) { if (bedrockId == -1 && session.getOpenInventory() instanceof MerchantContainer) {
// 1.16.200 - window ID is always -1 sent from Bedrock // 1.16.200 - window ID is always -1 sent from Bedrock
windowId = (byte) session.getOpenInventory().getId(); bedrockId = (byte) session.getOpenInventory().getBedrockId();
} }
Inventory openInventory = session.getOpenInventory(); Inventory openInventory = session.getOpenInventory();
if (openInventory != null) { if (openInventory != null) {
if (windowId == openInventory.getId()) { if (bedrockId == openInventory.getBedrockId()) {
ServerboundContainerClosePacket closeWindowPacket = new ServerboundContainerClosePacket(windowId); ServerboundContainerClosePacket closeWindowPacket = new ServerboundContainerClosePacket(openInventory.getJavaId());
session.sendDownstreamPacket(closeWindowPacket); session.sendDownstreamPacket(closeWindowPacket);
InventoryUtils.closeInventory(session, windowId, false); InventoryUtils.closeInventory(session, openInventory.getJavaId(), false);
} else if (openInventory.isPending()) { } else if (openInventory.isPending()) {
InventoryUtils.displayInventory(session, openInventory); InventoryUtils.displayInventory(session, openInventory);
openInventory.setPending(false); openInventory.setPending(false);

Datei anzeigen

@ -114,7 +114,7 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
changedItem = Int2ObjectMaps.singleton(hotbarSlot, itemStack.getItemStack()); changedItem = Int2ObjectMaps.singleton(hotbarSlot, itemStack.getItemStack());
} }
ServerboundContainerClickPacket dropPacket = new ServerboundContainerClickPacket( ServerboundContainerClickPacket dropPacket = new ServerboundContainerClickPacket(
inventory.getId(), inventory.getStateId(), hotbarSlot, clickType.actionType, clickType.action, inventory.getJavaId(), inventory.getStateId(), hotbarSlot, clickType.actionType, clickType.action,
inventory.getCursor().getItemStack(), changedItem); inventory.getCursor().getItemStack(), changedItem);
session.sendDownstreamPacket(dropPacket); session.sendDownstreamPacket(dropPacket);
return; return;
@ -371,7 +371,7 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
changedSlots.put(bedrockHotbarSlot, armorSlotItem.getItemStack()); changedSlots.put(bedrockHotbarSlot, armorSlotItem.getItemStack());
ServerboundContainerClickPacket clickPacket = new ServerboundContainerClickPacket( ServerboundContainerClickPacket clickPacket = new ServerboundContainerClickPacket(
playerInventory.getId(), playerInventory.getStateId(), armorSlot, playerInventory.getJavaId(), playerInventory.getStateId(), armorSlot,
click.actionType, click.action, null, changedSlots); click.actionType, click.action, null, changedSlots);
session.sendDownstreamPacket(clickPacket); session.sendDownstreamPacket(clickPacket);
} }

Datei anzeigen

@ -68,9 +68,9 @@ public class BedrockLecternUpdateTranslator extends PacketTranslator<LecternUpda
if (lecternContainer.getCurrentBedrockPage() == packet.getPage()) { if (lecternContainer.getCurrentBedrockPage() == packet.getPage()) {
// The same page means Bedrock is closing the window // The same page means Bedrock is closing the window
ServerboundContainerClosePacket closeWindowPacket = new ServerboundContainerClosePacket(lecternContainer.getId()); ServerboundContainerClosePacket closeWindowPacket = new ServerboundContainerClosePacket(lecternContainer.getJavaId());
session.sendDownstreamPacket(closeWindowPacket); session.sendDownstreamPacket(closeWindowPacket);
InventoryUtils.closeInventory(session, lecternContainer.getId(), false); InventoryUtils.closeInventory(session, lecternContainer.getJavaId(), false);
} else { } else {
// Each "page" Bedrock gives to us actually represents two pages (think opening a book and seeing two pages) // Each "page" Bedrock gives to us actually represents two pages (think opening a book and seeing two pages)
// Each "page" on Java is just one page (think a spiral notebook folded back to only show one page) // Each "page" on Java is just one page (think a spiral notebook folded back to only show one page)
@ -82,12 +82,12 @@ public class BedrockLecternUpdateTranslator extends PacketTranslator<LecternUpda
// is a byte when transmitted over the network and therefore this stops us at 128 // is a byte when transmitted over the network and therefore this stops us at 128
if (newJavaPage > currentJavaPage) { if (newJavaPage > currentJavaPage) {
for (int i = currentJavaPage; i < newJavaPage; i++) { for (int i = currentJavaPage; i < newJavaPage; i++) {
ServerboundContainerButtonClickPacket clickButtonPacket = new ServerboundContainerButtonClickPacket(session.getOpenInventory().getId(), 2); ServerboundContainerButtonClickPacket clickButtonPacket = new ServerboundContainerButtonClickPacket(session.getOpenInventory().getJavaId(), 2);
session.sendDownstreamPacket(clickButtonPacket); session.sendDownstreamPacket(clickButtonPacket);
} }
} else { } else {
for (int i = currentJavaPage; i > newJavaPage; i--) { for (int i = currentJavaPage; i > newJavaPage; i--) {
ServerboundContainerButtonClickPacket clickButtonPacket = new ServerboundContainerButtonClickPacket(session.getOpenInventory().getId(), 1); ServerboundContainerButtonClickPacket clickButtonPacket = new ServerboundContainerButtonClickPacket(session.getOpenInventory().getJavaId(), 1);
session.sendDownstreamPacket(clickButtonPacket); session.sendDownstreamPacket(clickButtonPacket);
} }
} }

Datei anzeigen

@ -38,6 +38,6 @@ public class JavaContainerCloseTranslator extends PacketTranslator<ClientboundCo
public void translate(GeyserSession session, ClientboundContainerClosePacket packet) { public void translate(GeyserSession session, ClientboundContainerClosePacket packet) {
// Sometimes the server can request a window close of ID 0... when the window isn't even open // Sometimes the server can request a window close of ID 0... when the window isn't even open
// Don't confirm in this instance // Don't confirm in this instance
InventoryUtils.closeInventory(session, packet.getContainerId(), (session.getOpenInventory() != null && session.getOpenInventory().getId() == packet.getContainerId())); InventoryUtils.closeInventory(session, packet.getContainerId(), (session.getOpenInventory() != null && session.getOpenInventory().getJavaId() == packet.getContainerId()));
} }
} }

Datei anzeigen

@ -54,7 +54,7 @@ public class JavaMerchantOffersTranslator extends PacketTranslator<ClientboundMe
@Override @Override
public void translate(GeyserSession session, ClientboundMerchantOffersPacket packet) { public void translate(GeyserSession session, ClientboundMerchantOffersPacket packet) {
Inventory openInventory = session.getOpenInventory(); Inventory openInventory = session.getOpenInventory();
if (!(openInventory instanceof MerchantContainer merchantInventory && openInventory.getId() == packet.getContainerId())) { if (!(openInventory instanceof MerchantContainer merchantInventory && openInventory.getJavaId() == packet.getContainerId())) {
return; return;
} }

Datei anzeigen

@ -49,7 +49,7 @@ public class JavaOpenScreenTranslator extends PacketTranslator<ClientboundOpenSc
// No translator exists for this window type. Close all windows and return. // No translator exists for this window type. Close all windows and return.
if (newTranslator == null) { if (newTranslator == null) {
if (openInventory != null) { if (openInventory != null) {
InventoryUtils.closeInventory(session, openInventory.getId(), true); InventoryUtils.closeInventory(session, openInventory.getJavaId(), true);
} }
ServerboundContainerClosePacket closeWindowPacket = new ServerboundContainerClosePacket(packet.getContainerId()); ServerboundContainerClosePacket closeWindowPacket = new ServerboundContainerClosePacket(packet.getContainerId());
session.sendDownstreamPacket(closeWindowPacket); session.sendDownstreamPacket(closeWindowPacket);
@ -64,7 +64,7 @@ public class JavaOpenScreenTranslator extends PacketTranslator<ClientboundOpenSc
// In rare cases, inventories can do funny things where it keeps the same window type up but change the contents. // In rare cases, inventories can do funny things where it keeps the same window type up but change the contents.
if (openInventory.getContainerType() != packet.getType()) { if (openInventory.getContainerType() != packet.getType()) {
// Sometimes the server can double-open an inventory with the same ID - don't confirm in that instance. // Sometimes the server can double-open an inventory with the same ID - don't confirm in that instance.
InventoryUtils.closeInventory(session, openInventory.getId(), openInventory.getId() != packet.getContainerId()); InventoryUtils.closeInventory(session, openInventory.getJavaId(), openInventory.getJavaId() != packet.getContainerId());
} }
} }

Datei anzeigen

@ -90,7 +90,7 @@ public class InventoryUtils {
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();
if (openInv != null && openInv.getId() == inventory.getId()) { if (openInv != null && openInv.getJavaId() == inventory.getJavaId()) {
translator.openInventory(session, inventory); translator.openInventory(session, inventory);
translator.updateInventory(session, inventory); translator.updateInventory(session, inventory);
} else if (openInv != null && openInv.isPending()) { } else if (openInv != null && openInv.isPending()) {
@ -108,11 +108,11 @@ public class InventoryUtils {
} }
} }
public static void closeInventory(GeyserSession session, int windowId, boolean confirm) { public static void closeInventory(GeyserSession session, int javaId, boolean confirm) {
session.getPlayerInventory().setCursor(GeyserItemStack.EMPTY, session); session.getPlayerInventory().setCursor(GeyserItemStack.EMPTY, session);
updateCursor(session); updateCursor(session);
Inventory inventory = getInventory(session, windowId); Inventory inventory = getInventory(session, javaId);
if (inventory != null) { if (inventory != null) {
InventoryTranslator translator = session.getInventoryTranslator(); InventoryTranslator translator = session.getInventoryTranslator();
translator.closeInventory(session, inventory); translator.closeInventory(session, inventory);
@ -124,12 +124,12 @@ public class InventoryUtils {
session.setOpenInventory(null); session.setOpenInventory(null);
} }
public static Inventory getInventory(GeyserSession session, int windowId) { public static Inventory getInventory(GeyserSession session, int javaId) {
if (windowId == 0) { if (javaId == 0) {
return session.getPlayerInventory(); return session.getPlayerInventory();
} else { } else {
Inventory openInventory = session.getOpenInventory(); Inventory openInventory = session.getOpenInventory();
if (openInventory != null && windowId == openInventory.getId()) { if (openInventory != null && javaId == openInventory.getJavaId()) {
return openInventory; return openInventory;
} }
return null; return null;