-
Notifications
You must be signed in to change notification settings - Fork 3
Slotless Item Handler
The ISlotlessItemHandler
was introduced to move more reponsibility to the direction of the capability provider.
This does not require capability consumers to loop over all slots anymore.
Instead, they can ask the handler for any item to be retrieved or inserted in a slot-agnostic manner.
This capability is always meant to exist together with the regular IItemHandler
.
For cases where a complete overview of the inventory is required, the default handler should be used.
One example in which this capability is used is Colossal Chests.
This mod introduces chests that can easily have inventories with half a million of slots.
This does not scale very well for naive item transfer algorithms that use the default IItemHandler
,
because this requires continuous looping over all slots.
When using the ISlotlessItemHandler
, the responsibility for extracting and inserting items lies with the Colossal Chests,
which is able to perform indexing over its items which allows efficient actions through the capability.
DefaultSlotlessItemHandlerWrapper
provides a naive implementation of the capability that wraps around a IItemHandler
.
For inventories with a large amount of slots, this will not scale well because of the non-intelligent implementation.
SlotlessItemHandlerWrapper
is an abstract implementation of the capability.
When extending this class, efficient implementations of getNonFullSlotWithItemStack
, getNonEmptySlotWithItemStack
, getEmptySlot
and getNonEmptySlot
are required.
CyclopsCore provides an example implementation of this in the IndexedSlotlessItemHandlerWrapper
, which requires the presence of a IndexedInventory
.
Example usage of the capability for inserting a list of items:
if (tile.hasCapability(SLOTLESS_ITEMHANDLER, side)) {
ISlotlessItemHandler handler = tile.getCapability(SLOTLESS_ITEMHANDLER, side);
for (ItemStack itemStack : myList) {
if (handler.insertItem(itemStack, true)) {
handler.insertItem(itemStack, false);
}
}
}
Example usage of the capability for extracting stacks of items to a list:
if (tile.hasCapability(SLOTLESS_ITEMHANDLER, side)) {
ISlotlessItemHandler handler = tile.getCapability(SLOTLESS_ITEMHANDLER, side);
while (handler.extractItem(64, true)) {
myList.add(handler.extractItem(64, false));
}
}
Example usage of the capability for extracting items matching an item by damage value and NBT to a list:
if (tile.hasCapability(SLOTLESS_ITEMHANDLER, side)) {
ISlotlessItemHandler handler = tile.getCapability(SLOTLESS_ITEMHANDLER, side);
while (handler.extractItem(myStack, ItemMatch.DAMAGE | ItemMatch.NBT, true)) {
myList.add(handler.extractItem(myStack, false));
}
}