Compare commits

...

3 Commits

Author SHA1 Message Date
Mikita Wiśniewski 489d3b13d9 Move LBMs out of init.lua and fix API.md 2024-06-24 20:19:43 +07:00
cora 71c8d93a12 Remove unused variables in chests example.lua 2024-06-24 13:46:31 +07:00
Mikita Wiśniewski 720cc5440d Add an introduction text to API.md 2024-06-24 12:56:34 +07:00
6 changed files with 62 additions and 43 deletions

View File

@ -1,5 +1,16 @@
# `mcl_chests` API
When reading through this documentation, please keep in mind that the chest
animations are achieved by giving each chest node an entity, as Minetest (as of
5.8.1) doesn't support giving nodes animated meshes, only static ones.
Because of that, a lot of parameters passed through the exposed functions are
be related to nodes and entities.
Please refer to [Minetest documentation](http://api.minetest.net/) and the code
comments in `api.lua`.
## `mcl_chests.register_chest(basename, definition)`
This function allows for simple chest registration, used by both regular and
@ -7,7 +18,7 @@ trapped chests.
* `basename` is a string that will be concatenated to form full nodenames for
chests, for example `"mcl_chests:basename_small"`.
* `definition` is a key-value table, with following fields:
* `definition` is a key-value table, with the following fields:
```lua
{
@ -140,6 +151,18 @@ Returned value is either a luaentity, or `nil` if failed (in which case a
warning message gets written into the console).
## `mcl_chests.select_and_spawn_entity(pos, node)`
This function is a simple wrapper for `mcl_chests.find_or_create_entity`,
getting most of the fields from node definition.
* `pos` is the position vector.
* `node` is a NodeRef.
Returned value is either a luaentity, or `nil` if failed (in which case a
warning message gets written into the console).
## `mcl_chests.no_rotate`
This function is equivalent to `screwdriver.disallow` and is used when a chest
@ -165,6 +188,7 @@ otherwise (where position is a vector value).
This function is called in `allow_metadata_inventory_move` field of Node
definition.
## `mcl_chests.protection_check_put_take(pos, listname, index, stack, player)`
This function is called in `allow_metadata_inventory_put` and

View File

@ -181,6 +181,15 @@ local function find_or_create_entity(pos, node_name, textures, param2, double, s
end
mcl_chests.find_or_create_entity = find_or_create_entity
local function select_and_spawn_entity(pos, node)
local node_name = node.name
local node_def = minetest.registered_nodes[node_name]
local double_chest = minetest.get_item_group(node_name, "double_chest") > 0
find_or_create_entity(pos, node_name, node_def._chest_entity_textures, node.param2, double_chest,
node_def._chest_entity_sound, node_def._chest_entity_mesh, node_def._chest_entity_animation_type)
end
mcl_chests.select_and_spawn_entity = select_and_spawn_entity
local no_rotate, simple_rotate
if screwdriver then
no_rotate = screwdriver.disallow

View File

@ -155,3 +155,20 @@ minetest.register_craft({
recipe = "mcl_chests:trapped_chest",
burntime = 15,
})
-- Disable active/open trapped chests when loaded because nobody could have them open at loading time.
-- Fixes redstone weirdness.
minetest.register_lbm({
label = "Disable active trapped chests",
name = "mcl_chests:reset_trapped_chests",
nodenames = {
"mcl_chests:trapped_chest_on_small",
"mcl_chests:trapped_chest_on_left",
"mcl_chests:trapped_chest_on_right"
},
run_at_every_load = true,
action = function(pos, node)
minetest.log("action", "[mcl_chests] Disabled active trapped chest on load: " .. minetest.pos_to_string(pos))
mcl_chests.chest_update_after_close(pos)
end,
})

View File

@ -126,3 +126,13 @@ minetest.register_craft({
{ "mcl_core:obsidian", "mcl_core:obsidian", "mcl_core:obsidian" },
},
})
minetest.register_lbm({
label = "Upgrade old ender chest formspec",
name = "mcl_chests:replace_old_ender_form",
nodenames = { "mcl_chests:ender_chest_small" },
run_at_every_load = false,
action = function(pos, node)
minetest.get_meta(pos):set_string("formspec", "")
end,
})

View File

@ -1,8 +1,4 @@
local S = minetest.get_translator(minetest.get_current_modname())
local F = minetest.formspec_escape
local C = minetest.colorize
local get_double_container_neighbor_pos = mcl_util.get_double_container_neighbor_pos
local trapped_chest_mesecons_rules = mesecon.rules.pplate
mcl_chests.register_chest("stone_chest", {
desc = S("Stone Chest"),

View File

@ -58,22 +58,12 @@ minetest.register_on_leaveplayer(function(player)
mcl_chests.player_chest_close(player)
end)
local function select_and_spawn_entity(pos, node)
local node_name = node.name
local node_def = minetest.registered_nodes[node_name]
local double_chest = minetest.get_item_group(node_name, "double_chest") > 0
mcl_chests.find_or_create_entity(pos, node_name, node_def._chest_entity_textures, node.param2, double_chest,
node_def._chest_entity_sound, node_def._chest_entity_mesh, node_def._chest_entity_animation_type)
end
minetest.register_lbm({
label = "Spawn Chest entities",
name = "mcl_chests:spawn_chest_entities",
nodenames = { "group:chest_entity" },
run_at_every_load = true,
action = select_and_spawn_entity,
action = mcl_chests.select_and_spawn_entity,
})
minetest.register_lbm({
@ -101,30 +91,3 @@ minetest.register_lbm({
end
end
})
-- Disable active/open trapped chests when loaded because nobody could have them open at loading time.
-- Fixes redstone weirdness.
minetest.register_lbm({
label = "Disable active trapped chests",
name = "mcl_chests:reset_trapped_chests",
nodenames = {
"mcl_chests:trapped_chest_on_small",
"mcl_chests:trapped_chest_on_left",
"mcl_chests:trapped_chest_on_right"
},
run_at_every_load = true,
action = function(pos, node)
minetest.log("action", "[mcl_chests] Disabled active trapped chest on load: " .. minetest.pos_to_string(pos))
mcl_chests.chest_update_after_close(pos)
end,
})
minetest.register_lbm({
label = "Upgrade old ender chest formspec",
name = "mcl_chests:replace_old_ender_form",
nodenames = { "mcl_chests:ender_chest_small" },
run_at_every_load = false,
action = function(pos, node)
minetest.get_meta(pos):set_string("formspec", "")
end,
})