Inherits: Node
Basic stack-based inventory class.
Supports basic inventory operations (adding, removing, transferring items etc.). Can contain an unlimited amount of item stacks.
protoset: JSON- A JSON resource containing prototype information.
get_prototree() -> ProtoTree- Returns the inventory prototree parsed from the protoset JSON resource.move_item(from: int, to: int) -> void- Moves the item at the given index in the inventory to a new index.get_item_index(item: InventoryItem) -> int- Returns the index of the given item in the inventory.get_item_count() -> int- Returns the number of items in the inventory.get_items() -> InventoryItem[]- Returns an array containing all the items in the inventory.has_item(item: InventoryItem) -> bool- Checks if the inventory contains the given item.add_item(item: InventoryItem) -> bool- Adds the given item to the inventory.can_add_item(item: InventoryItem) -> bool- Checks if the given item can be added to the inventory.create_item(prototype_id: String) -> InventoryItem- Creates anInventoryItembased on the prototype ID.create_and_add_item(prototype_id: String) -> InventoryItem- Creates anInventoryItembased on the given prototype ID and adds it to the inventory. Returnsnullif the item cannot be added.remove_item(item: InventoryItem) -> bool- Removes the given item from the inventory. Returnsfalseif the item is not inside the inventory.get_item_with_prototype_id(prototype_id: String) -> InventoryItem- Returns the first found item with the given prototype ID.get_items_with_prototype_id(prototype_id: String) -> InventoryItem[]- Returns an array of all the items with the given prototype ID.has_item_with_prototype_id(prototype_id: String) -> bool- Checks if the inventory has an item with the given prototype ID.get_constraint(script: Script) -> InventoryConstraint- Returns the inventory constraint of the given type (script). Returnsnullif the inventory has no constraints of that type.reset() -> void- Removes all items from the inventory and sets its protoset tonull.clear() -> void- Removes all the items from the inventory.serialize() -> Dictionary- Serializes the inventory into aDictionary.deserialize(source: Dictionary) -> bool- Loads the inventory data from the givenDictionary.split_stack(item: InventoryItem, new_stack_size: int) -> InventoryItem- Splits the given item stack into two within the inventory.new_stack_sizedefines the size of the new stack, which is added to the inventory. Returnsnullif the split cannot be performed or if the new stack cannot be added to the inventory.merge_stacks(item_dst: InventoryItem, item_src: InventoryItem, split_source: bool) -> bool- Merges theitem_srcitem stack into theitem_dststack which is inside the inventory. Ifitem_dstdoesn't have enough stack space andsplit_sourceis set totrue,item_srcwill be split and only partially merged. Returnsfalseif the merge cannot be performed.add_item_automerge(item: InventoryItem) -> bool- Adds the given item to the inventory and merges it with all compatible items. Returnsfalseif the item cannot be added.add_item_autosplit(item: InventoryItem) -> bool- Adds the given item to the inventory, splitting it if there is not enough space for the whole stack.add_item_autosplitmerge(item: InventoryItem) -> bool- A combination ofadd_item_autosplitandadd_item_automerge. Adds the given item stack into the inventory, splitting it up and joining it with available item stacks, as needed.pack_item(item: InventoryItem) -> void- Merges the given item with all compatible items in the same inventory.
item_added(item)- Emitted when an item has been added to the inventory.item_removed(item)- Emitted when an item has been removed from the inventory.item_property_changed(item, property)- Emitted when a property of an item inside the inventory has been changed.item_moved(item)- Emitted when an item has moved to a new index.protoset_changed()- Emitted when the protoset property has changed.constraint_added(constraint)- Emitted when a new constraint has been added to the inventory.constraint_removed(constraint)- Emitted when a constraint has been removed from the inventory.constraint_changed(constraint)- Emitted when an inventory constraint has changed.