Update the API documentation
This commit is contained in:
parent
3736c9dad8
commit
c396c88277
52
api.md
52
api.md
@ -1,17 +1,13 @@
|
|||||||
|
|
||||||
Hopper API
|
# Hopper API
|
||||||
----------
|
|
||||||
|
|
||||||
This API is kept simple by adding a single command which allows mods to add
|
This API provides two functions for adding containers such as chests and furnaces that will interact with hoppers.
|
||||||
containers like chests and furnaces to the hopper check list.
|
|
||||||
|
|
||||||
|
## hopper:add_container
|
||||||
|
|
||||||
Command Usage
|
```lua
|
||||||
-------------
|
hopper:add_container({ {"where_from", "node_name", "inventory_name"}, })
|
||||||
|
```
|
||||||
Make sure any mods using this function has 'hopper' in the depends.txt file.
|
|
||||||
|
|
||||||
hopper:add_container({ {"where_from", "node_name", "inventory_name"} })
|
|
||||||
|
|
||||||
'where_from' is a string telling the api that items are coming from either
|
'where_from' is a string telling the api that items are coming from either
|
||||||
the 'top' node into a hopper below, going into the 'bottom' node
|
the 'top' node into a hopper below, going into the 'bottom' node
|
||||||
@ -24,29 +20,35 @@ hopper:add_container({ {"where_from", "node_name", "inventory_name"} })
|
|||||||
|
|
||||||
e.g.
|
e.g.
|
||||||
|
|
||||||
|
```lua
|
||||||
hopper:add_container({
|
hopper:add_container({
|
||||||
{"top", "default:furnace", "dst"}, -- take cooked items from above into hopper below
|
{"top", "default:furnace", "dst"}, -- take cooked items from above into hopper below
|
||||||
{"bottom", "default:furnace", "src"}, -- insert items below to be cooked from hopper above
|
{"bottom", "default:furnace", "src"}, -- insert items below to be cooked from hopper above
|
||||||
{"side", "default:furnace", "fuel"}, -- replenish furnace fuel from hopper at side
|
{"side", "default:furnace", "fuel"}, -- replenish furnace fuel from hopper at side
|
||||||
})
|
})
|
||||||
|
```
|
||||||
|
|
||||||
You can also register hopper interaction targets by group, or by a group and a specific group
|
You can also register hopper interaction targets by group, or by a group and a specific group
|
||||||
value. For example:
|
value. For example:
|
||||||
|
|
||||||
|
```lua
|
||||||
hopper:add_container({
|
hopper:add_container({
|
||||||
{"top", "group:loot_chest", "loot"},
|
{"top", "group:loot_chest", "loot"},
|
||||||
{"bottom", "group:loot_chest", "loot"},
|
{"bottom", "group:loot_chest", "loot"},
|
||||||
{"side", "group:loot_chest", "loot"},
|
{"side", "group:loot_chest", "loot"},
|
||||||
})
|
})
|
||||||
|
```
|
||||||
|
|
||||||
Would cause hoppers to interact with the "loot" inventory of all nodes belonging to the group
|
Would cause hoppers to interact with the "loot" inventory of all nodes belonging to the group
|
||||||
"loot_chest", and
|
"loot_chest", and
|
||||||
|
|
||||||
|
```lua
|
||||||
hopper:add_container({
|
hopper:add_container({
|
||||||
{"top", "group:protected_container=1", "main"},
|
{"top", "group:protected_container=1", "main"},
|
||||||
{"bottom", "group:protected_container=1", "main"},
|
{"bottom", "group:protected_container=1", "main"},
|
||||||
{"side", "group:protected_container=1", "main"},
|
{"side", "group:protected_container=1", "main"},
|
||||||
})
|
})
|
||||||
|
```
|
||||||
|
|
||||||
Would cause hoppers to interact with the "main" inventory of nodes belonging to the group
|
Would cause hoppers to interact with the "main" inventory of nodes belonging to the group
|
||||||
"protected_container" provided they had a value of 1 in that group. Hoppers prioritize the most
|
"protected_container" provided they had a value of 1 in that group. Hoppers prioritize the most
|
||||||
@ -59,6 +61,36 @@ will take priority. Using the above examples, if there were a node that belonged
|
|||||||
the groups "loot_chest" and "protected_container=1" there's no way of knowing ahead of time
|
the groups "loot_chest" and "protected_container=1" there's no way of knowing ahead of time
|
||||||
whether hoppers would interact with the "loot" or "main" inventories. Try to avoid this situation.
|
whether hoppers would interact with the "loot" or "main" inventories. Try to avoid this situation.
|
||||||
|
|
||||||
|
### Optional parameter: get_inventory function
|
||||||
|
|
||||||
|
```lua
|
||||||
|
hopper:add_container({ {"where_from", "node_name", "inventory_name", get_inventory = function get_inventory(node_pos)}, })
|
||||||
|
```
|
||||||
|
|
||||||
|
This option allows you to use a different inventory instead of the inventory of this node. Unlike others, this parameter does not have to be set.
|
||||||
|
|
||||||
|
## hopper:set_extra_container_info
|
||||||
|
|
||||||
|
```lua
|
||||||
|
hopper:set_extra_container_info({ {"node_name", EXTRA PARAMETERS}, })
|
||||||
|
```
|
||||||
|
|
||||||
|
The function adds additional information about the container, which does not depend on where the items arrive. Before using it, you need to add a container.
|
||||||
|
Of course, it is not necessary to use it.
|
||||||
|
|
||||||
|
### EXTRA PARAMETER: set_hopper_param2 function
|
||||||
|
|
||||||
|
```lua
|
||||||
|
hopper:set_extra_container_info({ {"node_name", set_hopper_param2 = function set_hopper_param2(hopper_pos, node_pos)}, })
|
||||||
|
```
|
||||||
|
|
||||||
|
When we place the hopper, we have the position of the node we are looking at and the position of the funnel.
|
||||||
|
When other nodes get into the nodebox of one node, the information becomes insufficient, see [minetest 9147 issue](https://github.com/minetest/minetest/issues/9147). In particular, this feature was useful for adding [connected chests](https://github.com/HybridDog/connected_chests/pull/14) support.
|
||||||
|
|
||||||
|
This function takes priority over the usual installation of the hopper.
|
||||||
|
|
||||||
|
## Already supported containers
|
||||||
|
|
||||||
The hopper mod already have support for the wine barrel inside of the Wine mod and protected
|
The hopper mod already have support for the wine barrel inside of the Wine mod and protected
|
||||||
chests inside of Protector Redo, as well as default chests, furnaces and hoppers
|
chests inside of Protector Redo, as well as default chests, furnaces and hoppers
|
||||||
themselves.
|
themselves.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user