mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-10-15 22:17:39 +00:00
Add bounds checks for compartment lookup
This *shouldn't* be needed, as the compartment index is always >= 0, and Inventory.getItem returns an empty stack if the item is not found. However, some mods pass a negative compartment index, which causes getItem to throw an AIOOB instead. Fixes #2267
This commit is contained in:
@@ -54,7 +54,7 @@ public final class InventoryUtil {
|
||||
*/
|
||||
public static int getInventorySlotFromCompartment(Player player, int slot, ItemStack stack) {
|
||||
if (stack.isEmpty()) throw new IllegalArgumentException("Cannot search for empty stack");
|
||||
if (player.getInventory().getItem(slot) == stack) return slot;
|
||||
if (slot >= 0 && slot < Inventory.INVENTORY_SIZE && player.getInventory().getItem(slot) == stack) return slot;
|
||||
if (player.getInventory().getItem(Inventory.SLOT_OFFHAND) == stack) return Inventory.SLOT_OFFHAND;
|
||||
return -1;
|
||||
}
|
||||
|
Reference in New Issue
Block a user