easyvend/API.md

38 lines
1.2 KiB
Markdown
Raw Permalink Normal View History

2018-05-13 16:29:32 -07:00
# Easyvend API
Use this API if you want to make an container compatible with vending and
2018-05-13 16:29:32 -07:00
depositing machines.
## How it works
* Add `easyvend` as optional dependency
2018-05-14 16:37:53 -07:00
* Check for existence of `easyvend` mod in code
* Call `easyvend.register_chest` for all containers you want to be compatible
2018-05-13 16:29:32 -07:00
## `easyvend.register_chest = function(node_name, inv_list, meta_owner)`
Registers a node (called “chest”) for use with Easyvend. After calling this function,
the node will be recognized as storage for vending and depositing machines.
Easyvend makes the following assumptions about the chest:
* It has an inventory
* The inventory does not restrict the types of items you can put and take
* The chest is owned by a player
* The owner is specified in metadata
### Parameters
* `node_name`: Name of the chest node
* `inv_list`: Name of the inventory list for exchanging items
* `meta_owner`: Identifier of the metadata variable storing the owner name
### Example
Register the node `example:superchest` as container:
2018-05-13 16:29:32 -07:00
```
if minetest.get_modpath("easyvend") then
easyvend.register_chest("example:superchest", "main", "owner")
end
2018-05-13 16:29:32 -07:00
```
2018-05-14 16:37:53 -07:00
The `if` check is a common trick to check for the existence of the `easyvend`
and allows you to make the dependency optional.