Skip to content

Commit

Permalink
Remove reliance on CB conversions
Browse files Browse the repository at this point in the history
Closes #238
  • Loading branch information
Jikoo committed Aug 10, 2024
1 parent d50b743 commit 336aee8
Showing 1 changed file with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.lishid.openinv.internal.v1_21_R1.container.menu;

import com.google.common.base.Preconditions;
import com.lishid.openinv.internal.v1_21_R1.container.OpenInventory;
import com.lishid.openinv.internal.v1_21_R1.container.bukkit.OpenDummyInventory;
import com.lishid.openinv.internal.v1_21_R1.container.bukkit.OpenPlayerInventorySelf;
Expand Down Expand Up @@ -129,11 +130,13 @@ public boolean isInTop(int rawSlot) {
if (viewOnly) {
return null;
}
if (rawSlot < 0) {
return super.getInventory(rawSlot);
if (rawSlot == InventoryView.OUTSIDE || rawSlot == -1) {
return null;
}
Preconditions.checkArgument(rawSlot >= 0 && rawSlot < topSize + offset + BOTTOM_INVENTORY_SIZE,
"Slot %s outside of inventory", rawSlot);
if (rawSlot > topSize) {
return super.getInventory(offset + rawSlot);
return getBottomInventory();
}
Slot slot = slots.get(rawSlot);
if (slot.isFake()) {
Expand All @@ -157,7 +160,16 @@ public int convertSlot(int rawSlot) {
}
return rawSlot;
}
return super.convertSlot(offset + rawSlot);

int slot = rawSlot - topSize;

if (slot >= 27) {
slot -= 27;
} else {
slot += 9;
}

return slot;
}

@Override
Expand All @@ -166,14 +178,18 @@ public int convertSlot(int rawSlot) {
return InventoryType.SlotType.OUTSIDE;
}
if (slot >= topSize) {
return super.getSlotType(offset + slot);
slot -= topSize;
if (slot >= 27) {
return InventoryType.SlotType.QUICKBAR;
}
return InventoryType.SlotType.CONTAINER;
}
return OpenInventoryMenu.this.container.getSlotType(offset + slot);
}

@Override
public int countSlots() {
return topSize + getBottomInventory().getSize();
return topSize + BOTTOM_INVENTORY_SIZE;
}
};
}
Expand Down

0 comments on commit 336aee8

Please sign in to comment.