InventoryConstraint

Inherits: Resource

Script that can be extended to define add rules for Inventory behaviors.

Methods

bool

_can_add_new_stack_on_inventory(inventory: Node, item_id: String, amount: int, properties: Dictionary) virtual

bool

_can_add_on_inventory(inventory: Node, item_id: String, amount: int, properties: Dictionary) virtual

int

_get_amount_to_add(inventory: Node, item_id: String, amount: int, properties: Dictionary) virtual

int

_get_max_stack(inventory: Node, item_id: String, amount: int, properties: Dictionary, actual_max_stack: int) virtual


Method Descriptions

bool _can_add_new_stack_on_inventory(inventory: Node, item_id: String, amount: int, properties: Dictionary) virtual 🔗

This function can be extended to define whether or not the inventory accepts the creation of a stack.

Returns true the inventory can create new stack with item_id.

Returns false the inventory cannot add new stack with item_id.


bool _can_add_on_inventory(inventory: Node, item_id: String, amount: int, properties: Dictionary) virtual 🔗

This function can be extended to limit when an item can be added (regardless of whether it is adding a new stack or not).

Useful when you want the inventory to accept only one item or one category of item.

Returns true the inventory can add item_id.

Returns false the inventory cannot add item_id.


int _get_amount_to_add(inventory: Node, item_id: String, amount: int, properties: Dictionary) virtual 🔗

This function can be implemented to override the quantity that should be added to each inventory add interaction.

Useful when you want to limit the quantity that the inventory receives, for example an inventory linked to a processor and receives one item at a time, or does not receive anything if it is processing something.

Returns int with amount of item_id added in inventory.


int _get_max_stack(inventory: Node, item_id: String, amount: int, properties: Dictionary, actual_max_stack: int) virtual 🔗

This function can be extended to override the max stack behavior of your inventory, very useful for creating inventories that do not respect the max stack number of items,

for example an inventory of only wood where the max stack is higher than the max stack defined for the wood itself.

Returns int with max_stack of item_id added.