1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-08-28 16:22:18 +00:00

Add inventory.getItemLimit

Closes #781
This commit is contained in:
Jummit 2021-05-22 08:32:55 +02:00
parent 96d46ffd2c
commit e40fb67b50

View File

@ -153,6 +153,33 @@ public class InventoryMethods implements GenericSource
return stack.isEmpty() ? null : ItemData.fill( new HashMap<>(), stack );
}
/**
* Get the maximum number of items which can be stored in this slot.
*
* Typically this will be limited to 64 items. However, some inventories (such as barrels or caches) can store
* hundreds or thousands of items in one slot.
*
* @param inventory Inventory to probe.
* @param slot The slot
* @return The maximum number of items in this slot.
* @throws LuaException If the slot is out of range.
* @cc.usage Count the maximum number of items an adjacent chest can hold.
* <pre>{@code
* local chest = peripheral.find("minecraft:chest")
* local total = 0
* for i = 1, chest.size() do
* total = total + chest.getItemLimit(i)
* end
* print(total)
* }</pre>
*/
@LuaFunction( mainThread = true )
public static int getItemLimit( Inventory inventory, int slot ) throws LuaException
{
assertBetween( slot, 1, inventory.size(), "Slot out of range (%s)" );
return inventory.getMaxCountPerStack();
}
/**
* Push items from one inventory to another connected one.
*