mirror of
https://github.com/minetest/minetest_game.git
synced 2024-12-22 22:22:25 +01:00
Make default.chest.register_chest() usable for other mods (#2127)
This commit is contained in:
parent
ea4ce80f7c
commit
fb18a5b20d
@ -136,12 +136,12 @@ The chests API allows the creation of chests, which have their own inventories f
|
|||||||
* A table indexed by player name to keep track of who opened what chest.
|
* A table indexed by player name to keep track of who opened what chest.
|
||||||
* Key: The name of the player.
|
* Key: The name of the player.
|
||||||
* Value: A table containing information about the chest the player is looking at.
|
* Value: A table containing information about the chest the player is looking at.
|
||||||
e.g `{ pos = {1, 1, 1}, sound = null, swap = "chest" }`
|
e.g `{ pos = {1, 1, 1}, sound = null, swap = "default:chest" }`
|
||||||
|
|
||||||
`default.chest.register_chest(name, def)`
|
`default.chest.register_chest(name, def)`
|
||||||
|
|
||||||
* Registers new chest
|
* Registers new chest
|
||||||
* `name` Name for chest
|
* `name` Name for chest e.g. "default:chest"
|
||||||
* `def` See [#Chest Definition]
|
* `def` See [#Chest Definition]
|
||||||
|
|
||||||
### Chest Definition
|
### Chest Definition
|
||||||
|
@ -44,7 +44,7 @@ function default.chest.chest_lid_close(pn)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
minetest.after(0.2, minetest.swap_node, pos, { name = "default:" .. swap,
|
minetest.after(0.2, minetest.swap_node, pos, { name = swap,
|
||||||
param2 = node.param2 })
|
param2 = node.param2 })
|
||||||
minetest.sound_play(sound, {gain = 0.3, pos = pos,
|
minetest.sound_play(sound, {gain = 0.3, pos = pos,
|
||||||
max_hear_distance = 10}, true)
|
max_hear_distance = 10}, true)
|
||||||
@ -76,7 +76,8 @@ minetest.register_on_leaveplayer(function(player)
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
function default.chest.register_chest(name, d)
|
function default.chest.register_chest(prefixed_name, d)
|
||||||
|
local name = prefixed_name:sub(1,1) == ':' and prefixed_name:sub(2,-1) or prefixed_name
|
||||||
local def = table.copy(d)
|
local def = table.copy(d)
|
||||||
def.drawtype = "mesh"
|
def.drawtype = "mesh"
|
||||||
def.visual = "mesh"
|
def.visual = "mesh"
|
||||||
@ -132,7 +133,7 @@ function default.chest.register_chest(name, d)
|
|||||||
pos = pos, max_hear_distance = 10}, true)
|
pos = pos, max_hear_distance = 10}, true)
|
||||||
if not default.chest.chest_lid_obstructed(pos) then
|
if not default.chest.chest_lid_obstructed(pos) then
|
||||||
minetest.swap_node(pos,
|
minetest.swap_node(pos,
|
||||||
{ name = "default:" .. name .. "_open",
|
{ name = name .. "_open",
|
||||||
param2 = node.param2 })
|
param2 = node.param2 })
|
||||||
end
|
end
|
||||||
minetest.after(0.2, minetest.show_formspec,
|
minetest.after(0.2, minetest.show_formspec,
|
||||||
@ -203,7 +204,7 @@ function default.chest.register_chest(name, d)
|
|||||||
max_hear_distance = 10}, true)
|
max_hear_distance = 10}, true)
|
||||||
if not default.chest.chest_lid_obstructed(pos) then
|
if not default.chest.chest_lid_obstructed(pos) then
|
||||||
minetest.swap_node(pos, {
|
minetest.swap_node(pos, {
|
||||||
name = "default:" .. name .. "_open",
|
name = name .. "_open",
|
||||||
param2 = node.param2 })
|
param2 = node.param2 })
|
||||||
end
|
end
|
||||||
minetest.after(0.2, minetest.show_formspec,
|
minetest.after(0.2, minetest.show_formspec,
|
||||||
@ -215,7 +216,7 @@ function default.chest.register_chest(name, d)
|
|||||||
def.on_blast = function(pos)
|
def.on_blast = function(pos)
|
||||||
local drops = {}
|
local drops = {}
|
||||||
default.get_inventory_drops(pos, "main", drops)
|
default.get_inventory_drops(pos, "main", drops)
|
||||||
drops[#drops+1] = "default:" .. name
|
drops[#drops+1] = name
|
||||||
minetest.remove_node(pos)
|
minetest.remove_node(pos)
|
||||||
return drops
|
return drops
|
||||||
end
|
end
|
||||||
@ -248,7 +249,7 @@ function default.chest.register_chest(name, d)
|
|||||||
def_opened.tiles[i].backface_culling = true
|
def_opened.tiles[i].backface_culling = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
def_opened.drop = "default:" .. name
|
def_opened.drop = name
|
||||||
def_opened.groups.not_in_creative_inventory = 1
|
def_opened.groups.not_in_creative_inventory = 1
|
||||||
def_opened.selection_box = {
|
def_opened.selection_box = {
|
||||||
type = "fixed",
|
type = "fixed",
|
||||||
@ -265,29 +266,31 @@ function default.chest.register_chest(name, d)
|
|||||||
def_closed.tiles[5] = def.tiles[3] -- drawtype to make them match the mesh
|
def_closed.tiles[5] = def.tiles[3] -- drawtype to make them match the mesh
|
||||||
def_closed.tiles[3] = def.tiles[3].."^[transformFX"
|
def_closed.tiles[3] = def.tiles[3].."^[transformFX"
|
||||||
|
|
||||||
minetest.register_node("default:" .. name, def_closed)
|
minetest.register_node(prefixed_name, def_closed)
|
||||||
minetest.register_node("default:" .. name .. "_open", def_opened)
|
minetest.register_node(prefixed_name .. "_open", def_opened)
|
||||||
|
|
||||||
-- convert old chests to this new variant
|
-- convert old chests to this new variant
|
||||||
minetest.register_lbm({
|
if name == "default:chest" or name == "default:chest_locked" then
|
||||||
label = "update chests to opening chests",
|
minetest.register_lbm({
|
||||||
name = "default:upgrade_" .. name .. "_v2",
|
label = "update chests to opening chests",
|
||||||
nodenames = {"default:" .. name},
|
name = "default:upgrade_" .. name:sub(9,-1) .. "_v2",
|
||||||
action = function(pos, node)
|
nodenames = {name},
|
||||||
local meta = minetest.get_meta(pos)
|
action = function(pos, node)
|
||||||
meta:set_string("formspec", nil)
|
local meta = minetest.get_meta(pos)
|
||||||
local inv = meta:get_inventory()
|
meta:set_string("formspec", nil)
|
||||||
local list = inv:get_list("default:chest")
|
local inv = meta:get_inventory()
|
||||||
if list then
|
local list = inv:get_list("default:chest")
|
||||||
inv:set_size("main", 8*4)
|
if list then
|
||||||
inv:set_list("main", list)
|
inv:set_size("main", 8*4)
|
||||||
inv:set_list("default:chest", nil)
|
inv:set_list("main", list)
|
||||||
|
inv:set_list("default:chest", nil)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
})
|
||||||
})
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
default.chest.register_chest("chest", {
|
default.chest.register_chest("default:chest", {
|
||||||
description = S("Chest"),
|
description = S("Chest"),
|
||||||
tiles = {
|
tiles = {
|
||||||
"default_chest_top.png",
|
"default_chest_top.png",
|
||||||
@ -303,7 +306,7 @@ default.chest.register_chest("chest", {
|
|||||||
groups = {choppy = 2, oddly_breakable_by_hand = 2},
|
groups = {choppy = 2, oddly_breakable_by_hand = 2},
|
||||||
})
|
})
|
||||||
|
|
||||||
default.chest.register_chest("chest_locked", {
|
default.chest.register_chest("default:chest_locked", {
|
||||||
description = S("Locked Chest"),
|
description = S("Locked Chest"),
|
||||||
tiles = {
|
tiles = {
|
||||||
"default_chest_top.png",
|
"default_chest_top.png",
|
||||||
|
Loading…
Reference in New Issue
Block a user