Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,23 @@ public Inventory getInventory(final int rawSlot) {
}

public Inventory mapValidSlotToInventory(final int rawSlot) {
if (rawSlot < this.getTopInventory().getSize()) {
if (rawSlot < this.getTopSlots()) {
return this.getTopInventory();
} else {
return this.getBottomInventory();
}
}

// The number of raw slots the top inventory occupies in the open menu. This is
// usually just its size, but a view can override it when the menu renders fewer
// slots than the inventory reports (e.g. a player inventory shown as a chest).
public int getTopSlots() {
return this.getTopInventory().getSize();
}

@Override
public int convertSlot(final int rawSlot) {
int numInTop = this.getTopInventory().getSize();
int numInTop = this.getTopSlots();
// Index from the top inventory as having slots from [0,size]
if (rawSlot < numInTop) {
return rawSlot;
Expand Down Expand Up @@ -132,7 +139,7 @@ public int convertSlot(final int rawSlot) {
@Override
public InventoryType.SlotType getSlotType(final int slot) {
InventoryType.SlotType type = InventoryType.SlotType.CONTAINER;
if (slot >= 0 && slot < this.getTopInventory().getSize()) {
if (slot >= 0 && slot < this.getTopSlots()) {
switch (this.getType()) {
case BLAST_FURNACE:
case FURNACE:
Expand Down Expand Up @@ -229,7 +236,7 @@ public void close() {

@Override
public int countSlots() {
return this.getTopInventory().getSize() + this.getBottomInventory().getSize();
return this.getTopSlots() + this.getBottomInventory().getSize();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ public InventoryType getType() {
return inventory.getType();
}

@Override
public int getTopSlots() {
// A player inventory shown inside a container is laid out as a generic
// chest (whole rows of 9), so the armour and off-hand slots that
// getSize() counts are not rendered. Use the number of slots actually
// laid out so the raw-slot mapping matches the open menu.
if (inventory.getType() == InventoryType.PLAYER) {
return (inventory.getSize() / 9) * 9;
}
return inventory.getSize();
}

// Paper start
@Override
public net.kyori.adventure.text.Component title() {
Expand Down
Loading