From 336aee88e266f3e0c306701695e757f8ae4da9da Mon Sep 17 00:00:00 2001 From: Jikoo Date: Sat, 10 Aug 2024 12:50:46 -0400 Subject: [PATCH] Remove reliance on CB conversions Closes #238 --- .../container/menu/OpenInventoryMenu.java | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/internal/v1_21_R1/src/main/java/com/lishid/openinv/internal/v1_21_R1/container/menu/OpenInventoryMenu.java b/internal/v1_21_R1/src/main/java/com/lishid/openinv/internal/v1_21_R1/container/menu/OpenInventoryMenu.java index ffbea9d0..d5567f62 100644 --- a/internal/v1_21_R1/src/main/java/com/lishid/openinv/internal/v1_21_R1/container/menu/OpenInventoryMenu.java +++ b/internal/v1_21_R1/src/main/java/com/lishid/openinv/internal/v1_21_R1/container/menu/OpenInventoryMenu.java @@ -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; @@ -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()) { @@ -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 @@ -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; } }; }