CraftStation

Inherits: NodeInventories < Node

Station where new Crafting processes are generated.

Description

This node has a list of recipes that are generated based on the recipes in NodeInventories.database filtered by the type of this station (If there is no type defined, the recipes will be those that also have no type defined. See more in Recipe)

The node also maintains a list of crafting processes currently being performed, which are created by craft() and finished by finish_craft().

Properties

bool

auto_craft

false

bool

can_finish_craftings

true

bool

can_processing_craftings

true

Array[Crafting]

craftings

[]

bool

has_limit_crafts

false

Array[NodePath]

input_inventories

[]

int

limit_number_crafts

4

bool

only_remove_ingredients_after_craft

false

Array[NodePath]

output_inventories

[]

int

processing_mode

0

int

tick_update_method

0

CraftStationType

type

String

type_id

""

Array[int]

valid_recipes

[]

Methods

void

add_crafting(recipe_index: int, recipe: Recipe)

void

add_input_inventory(input_inventory: Inventory)

bool

can_craft(recipe: Recipe) const

void

cancel_craft(crafting_index: int)

bool

contains_ingredients(recipe: Recipe) const

void

craft(recipe_index: int)

void

deserialize(data: Dictionary)

void

finish_crafting(crafting_index: int)

Inventory

get_input_inventory(index: int = 0) const

bool

is_crafting() const

void

load_valid_recipes()

void

remove_crafting(crafting_index: int)

void

remove_input_inventory(input_inventory: Inventory)

Dictionary

serialize() const

void

tick(delta: float)


Signals

crafting_added(crafting_index: int) 🔗

Emitted when a new crafting is added to the craftings list. This signal is emitted after add_crafting() method occurs.


crafting_removed(crafting_index: int) 🔗

Emitted when a crafting is removed from the list of craftings. This signal is emitted after remove_crafting() method occurs.


input_inventory_added(input_inventory_path: NodePath) 🔗

Emitted when a new Inventory is added to the input_inventories list. This signal is emitted after the add_input_inventory() method occurs.


input_inventory_removed(input_inventory_path: NodePath) 🔗

Emitted when a new Inventory is removed from the input_inventories list. This signal is emitted after the remove_input_inventory() method occurs.


on_crafted(recipe_index: int) 🔗

Emitted when a Crafting is successfully completed. This signal is emitted after the finish_craft() method successfully completes.


on_request_craft(recipe_index: int) 🔗

Emitted when a Crafting is requested, unlike crafting_added, this signal can happen even when the crafting cannot be done. This signal is emitted at the start of the craft() method.


Property Descriptions

bool auto_craft = false 🔗

  • void set_auto_craft(value: bool)

  • bool get_auto_craft()

When activating the station upon identifying a change in the input inventories, it can call the craft() method when possible. This is used in the demo with the campfire, it activates this option when it is turned on with fuel.


bool can_finish_craftings = true 🔗

  • void set_can_finish_craftings(value: bool)

  • bool get_can_finish_craftings()

If true calls finish_craft() after Crafting finish.


bool can_processing_craftings = true 🔗

  • void set_can_processing_craftings(value: bool)

  • bool get_can_processing_craftings()

If true the station processes crafts based on the method tick() called (This method is called differently depending on the option chosen in tick_update_method).

In the demo the is_burning of campfire is used to turn this option on/off.


Array[Crafting] craftings = [] 🔗

List of current craftings being processed, if the processing_mode option is processing_mode.Parallel the processings will be happening together, otherwise only one will be processing and the others will be waiting for the first one to finish.

An example of using this list is in the demo in crafting_ui.gd:


bool has_limit_crafts = false 🔗

  • void set_has_limit_crafts(value: bool)

  • bool get_has_limit_crafts()

If true the craftstation may have a limit of limit_number_crafts to process in the craftings list.


Array[NodePath] input_inventories = [] 🔗

  • void set_input_inventories(value: Array[NodePath])

  • Array[NodePath] get_input_inventories()

List of Inventory items that will be used for crafting Recipe.ingredients items.


int limit_number_crafts = 4 🔗

  • void set_limit_number_crafts(value: int)

  • int get_limit_number_crafts()

Limit the number of craftings in the craftings list. This value is only set if has_limit_crafts is true.


bool only_remove_ingredients_after_craft = false 🔗

  • void set_only_remove_ingredients_after_craft(value: bool)

  • bool get_only_remove_ingredients_after_craft()

Removes ingredients only when the crafting process finishes in finish_craft(), this is used in the demo campfire to not remove meats while crafting is happening.


Array[NodePath] output_inventories = [] 🔗

  • void set_output_inventories(value: Array[NodePath])

  • Array[NodePath] get_output_inventories()

Craft product output inventory, after finish_craft() happens a list of products from Recipe.produts is added to these inventories. Note: An inventory can be part of both input_inventories and output_inventories at the same time.


int processing_mode = 0 🔗

  • void set_processing_mode(value: int)

  • int get_processing_mode()

Processing mode for craftings. If set to Parallel, all craftings will happen together, if set to Sequential only one craft will be processed at a time.


int tick_update_method = 0 🔗

  • void set_tick_update_method(value: int)

  • int get_tick_update_method()

Method for updating crafting processes. If marked as Process or Physic Process , the tick() call will happen internally in your respective godot calls. If marked as Custom the tick() method will not be called anywhere and you will have to call it in your code, it should be useful for multiplayer systems where the server manages this time.


CraftStationType type 🔗

Defines the station type with resource CraftStationType. This resource must be created in InventoryDatabase with a custom editor. This defines which recipes will be valid for this station in the variable valid_recipes.


String type_id = "" 🔗

  • void set_type_id(value: String)

  • String get_type_id()

There is currently no description for this property. Please help us by contributing one!


Array[int] valid_recipes = [] 🔗

  • void set_valid_recipes(value: Array[int])

  • Array[int] get_valid_recipes()

Valid recipes that are filtered based on the defined station type. See in type.


Method Descriptions

void add_crafting(recipe_index: int, recipe: Recipe) 🔗

Adds a new crafting process with the recipe index recipe_index to the station’s crafting process list. It emits the signal crafting_added.


void add_input_inventory(input_inventory: Inventory) 🔗

Adds a new Inventory used as input for crafting. Items in this inventory will be used as Recipe.ingredients and Recipe.required_items for crafting.


bool can_craft(recipe: Recipe) const 🔗

Returns true if the recipe can be created. It checks whether the ingredients are present in the input_inventories and whether this recipe is of the CraftStationType type of this station.


void cancel_craft(crafting_index: int) 🔗

Cancels Crafting with index crafting_index and returns the items used by crafting to the input inventory. Note: Canceling does not return items to their previous positions, such as Inventory or a specific Slot.


bool contains_ingredients(recipe: Recipe) const 🔗

Returns true if the input inventories have the Recipe.ingredients and Recipe.required_items for this Crafting recipe.


void craft(recipe_index: int) 🔗

Calls a new craft with recipe from index recipe_index of valid_recipes to be processed (added to the member.craftings list). Note: It will only be included if contains_ingredients() is true.


void deserialize(data: Dictionary) 🔗

There is currently no description for this method. Please help us by contributing one!


void finish_crafting(crafting_index: int) 🔗

Finishes a craft from the craftings process list with index crafting_index. This method removes the items from Recipe.ingredients from the input inventories if the only_remove_ingredients_after_craft option is enabled. Adds the Recipe.products to the output inventories. The on_crafted is emitted when successfully removed.


Inventory get_input_inventory(index: int = 0) const 🔗

Returns an input Inventory by the index of index.


bool is_crafting() const 🔗

Returns true if the craftstation is processing a crafting.


void load_valid_recipes() 🔗

There is currently no description for this method. Please help us by contributing one!


void remove_crafting(crafting_index: int) 🔗

Removes a crafting from the list of craftings with index crafting_index. This is called by finish_crafting(). Note: This method does not do the same as finish_crafting(), it does not add crafting after removal. It emits the signal crafting_removed.


void remove_input_inventory(input_inventory: Inventory) 🔗

Remove a Inventory used as input for crafting.


Dictionary serialize() const 🔗

There is currently no description for this method. Please help us by contributing one!


void tick(delta: float) 🔗

Method called to update the list of craftings. This method can be called internally or by your code by setting the tick_update_method.