Chests: Revert inventory name

Revert the new 'default:game' inventory back to the old 'main' and use the
lbm to restore the contents of the chest.
Change the name of the conversion LBM to ensure it is run again on already
converted chests.
This commit is contained in:
tenplus1 2017-05-08 12:47:53 +01:00 committed by paramat
parent 5bd44c21ef
commit 63b3542d00
1 changed files with 13 additions and 11 deletions

View File

@ -1773,10 +1773,10 @@ local function get_chest_formspec(pos)
default.gui_bg .. default.gui_bg ..
default.gui_bg_img .. default.gui_bg_img ..
default.gui_slots .. default.gui_slots ..
"list[nodemeta:" .. spos .. ";default:chest;0,0.3;8,4;]" .. "list[nodemeta:" .. spos .. ";main;0,0.3;8,4;]" ..
"list[current_player;main;0,4.85;8,1;]" .. "list[current_player;main;0,4.85;8,1;]" ..
"list[current_player;main;0,6.08;8,3;8]" .. "list[current_player;main;0,6.08;8,3;8]" ..
"listring[nodemeta:" .. spos .. ";default:chest]" .. "listring[nodemeta:" .. spos .. ";main]" ..
"listring[current_player;main]" .. "listring[current_player;main]" ..
default.get_hotbar_bg(0,4.85) default.get_hotbar_bg(0,4.85)
return formspec return formspec
@ -1842,7 +1842,7 @@ function default.register_chest(name, d)
meta:set_string("infotext", "Locked Chest") meta:set_string("infotext", "Locked Chest")
meta:set_string("owner", "") meta:set_string("owner", "")
local inv = meta:get_inventory() local inv = meta:get_inventory()
inv:set_size("default:chest", 8*4) inv:set_size("main", 8*4)
end end
def.after_place_node = function(pos, placer) def.after_place_node = function(pos, placer)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
@ -1853,7 +1853,7 @@ function default.register_chest(name, d)
def.can_dig = function(pos,player) def.can_dig = function(pos,player)
local meta = minetest.get_meta(pos); local meta = minetest.get_meta(pos);
local inv = meta:get_inventory() local inv = meta:get_inventory()
return inv:is_empty("default:chest") and return inv:is_empty("main") and
default.can_interact_with_node(player, pos) default.can_interact_with_node(player, pos)
end end
def.allow_metadata_inventory_move = function(pos, from_list, from_index, def.allow_metadata_inventory_move = function(pos, from_list, from_index,
@ -1939,12 +1939,12 @@ function default.register_chest(name, d)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_string("infotext", "Chest") meta:set_string("infotext", "Chest")
local inv = meta:get_inventory() local inv = meta:get_inventory()
inv:set_size("default:chest", 8*4) inv:set_size("main", 8*4)
end end
def.can_dig = function(pos,player) def.can_dig = function(pos,player)
local meta = minetest.get_meta(pos); local meta = minetest.get_meta(pos);
local inv = meta:get_inventory() local inv = meta:get_inventory()
return inv:is_empty("default:chest") return inv:is_empty("main")
end end
def.on_rightclick = function(pos, node, clicker) def.on_rightclick = function(pos, node, clicker)
minetest.sound_play(def.sound_open, {gain = 0.3, pos = pos, minetest.sound_play(def.sound_open, {gain = 0.3, pos = pos,
@ -2007,16 +2007,18 @@ function default.register_chest(name, d)
-- convert old chests to this new variant -- convert old chests to this new variant
minetest.register_lbm({ minetest.register_lbm({
label = "update chests to opening chests", label = "update chests to opening chests",
name = "default:upgrade_" .. name, name = "default:upgrade_" .. name .. "_v2",
nodenames = {"default:" .. name}, nodenames = {"default:" .. name},
action = function(pos, node) action = function(pos, node)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_string("formspec", nil) meta:set_string("formspec", nil)
local inv = meta:get_inventory() local inv = meta:get_inventory()
local list = inv:get_list("main") local list = inv:get_list("default:chest")
inv:set_list("main", nil) if list then
inv:set_size("default:chest", 8*4) inv:set_size("main", 8*4)
inv:set_list("default:chest", list) inv:set_list("main", list)
inv:set_list("default:chest", nil)
end
end end
}) })
end end