Slot Rules¶
Slot Rules allow you to restrict what items can be placed into specific inventory slots. This is essential for equipment systems (e.g., ensuring a helmet can only go in the head slot).
SlotDefinition (Resource)¶
Every slot in an Inventory has a corresponding SlotDefinition.
- display_name: Name of the slot (e.g., "Head", "Weapon").
- icon_placeholder: Texture shown when the slot is empty.
- rules: An Array[SlotRule] that must all pass for an item to be accepted.
- allow_drag_out / allow_right_click: UI interaction restrictions.
Base Class: SlotRule (Resource)¶
All rules extend SlotRule.
# Returns true if the item is allowed in this slot.
func can_accept_item(item: ItemDefinition, slot_index: int, inventory: Inventory) -> bool
# Returns a human-readable string explaining why the item was rejected.
func get_rejection_reason(item: ItemDefinition, slot_index: int) -> String
Built-in Rules¶
EquipmentTypeRule¶
Locks a slot to a specific integer equipment_type.
- Property: equipment_type (int).
- Usage: Set the rule's equipment_type to 1. Set your Helmet item's equipment_type to 1.
ItemTagRule¶
Requires items to have specific string tags.
- Properties: required_tags (Array[String]), match_any (bool).
- Usage: If match_any is true, the item needs at least one of the tags. If false, it must have all of them.
MaxOneRule¶
Prevents items from stacking in a specific slot (e.g., equipment slots). - Usage: Add this to equipment slots so players can't stack 64 Iron Swords in a single weapon slot.
Rule Implementation Details
EquipmentTypeRule.can_accept_item() uses item.get("equipment_type") rather than item.equipment_type due to a potential missing meta check in the code. This works for direct property access but may behave differently if the item lacks the property.