don't place eg. chests without data

This commit is contained in:
DS-Minetest 2017-06-23 22:09:03 +02:00 committed by Vanessa Ezekowitz
parent d4162be9a7
commit 16146231b8

View File

@ -24,10 +24,7 @@ local S = rawget(_G, "intllib") and intllib.Getter() or function(s) return s end
local function get_meta_type(name, metaname) local function get_meta_type(name, metaname)
local def = wrench.registered_nodes[name] local def = wrench.registered_nodes[name]
if not def or not def.metas or not def.metas[metaname] then return def and def.metas and def.metas[metaname] or nil
return nil
end
return def.metas[metaname]
end end
local function get_pickup_name(name) local function get_pickup_name(name)
@ -42,6 +39,14 @@ local function restore(pos, placer, itemstack)
local data = itemstack:get_meta():get_string("data") local data = itemstack:get_meta():get_string("data")
data = (data ~= "" and data) or itemstack:get_metadata() data = (data ~= "" and data) or itemstack:get_metadata()
data = minetest.deserialize(data) data = minetest.deserialize(data)
if not data then
minetest.remove_node(pos)
minetest.log("error", placer:get_player_name().." wanted to place "..
name.." at "..minetest.pos_to_string(pos)..
", but it had no data.")
minetest.log("verbose", "itemstack: "..itemstack:to_string())
return true
end
minetest.set_node(pos, {name = data.name, param2 = node.param2}) minetest.set_node(pos, {name = data.name, param2 = node.param2})
for name, value in pairs(data.metas) do for name, value in pairs(data.metas) do
local meta_type = get_meta_type(data.name, name) local meta_type = get_meta_type(data.name, name)