mirror of
https://git.minetest.land/MineClone2/MineClone2.git
synced 2024-11-28 05:43:43 +01:00
Move LBMs out of init.lua and fix API.md
This commit is contained in:
parent
ac05f8bad6
commit
209b24a2fb
@ -18,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
|
||||
{
|
||||
@ -151,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
|
||||
@ -176,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
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
})
|
||||
|
@ -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,
|
||||
})
|
||||
|
@ -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,
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user