spawn lockable nodes for "inventory = { lockable = true }", and migrate all lockable nodes to this mechanism, but the furnaces

This commit is contained in:
Tim 2015-08-19 19:30:03 +02:00
parent cc79b5fc03
commit 29f61bb899
6 changed files with 33 additions and 38 deletions

View File

@ -171,6 +171,7 @@ for _, w in pairs({"mahogany", "oak"}) do
infotext=S("One-drawer Nightstand"),
inventory = {
size=8,
lockable=true,
},
})
@ -196,6 +197,7 @@ for _, w in pairs({"mahogany", "oak"}) do
infotext=S("Two-drawer Nightstand"),
inventory = {
size=16,
lockable=true,
},
})
end

View File

@ -54,7 +54,8 @@ end
-- inventory = {
-- size = 16,
-- formspec = …,
-- locked = true,
-- locked = false,
-- lockable = true,
-- }
--
function homedecor.handle_inventory(name, def, original_def)
@ -88,20 +89,15 @@ function homedecor.handle_inventory(name, def, original_def)
))
end
local locked = def.locked
def.locked = nil
local locked = inventory.locked
if locked then
local description = def.description
-- def.description = S("%s (Locked)"):format(description)
local after_place_node = def.after_place_node
def.after_place_node = function(pos, placer)
local meta = minetest.get_meta(pos)
local owner = placer:get_player_name() or ""
meta:set_string("owner", owner)
meta:set_string("infotext", S("%s (owned by %s)"):format(def.infotext or description, owner))
meta:set_string("infotext", S("%s (owned by %s)"):format(def.infotext or def.description, owner))
return after_place_node and after_place_node(pos, placer)
end
@ -113,7 +109,7 @@ function homedecor.handle_inventory(name, def, original_def)
if (playername ~= owner) then
minetest.log("action", string.format("%s tried to access a %s belonging to %s at %s",
playername, infotext, owner, minetest.pos_to_string(pos)
playername, name, owner, minetest.pos_to_string(pos)
))
return 0
end
@ -130,7 +126,7 @@ function homedecor.handle_inventory(name, def, original_def)
if (playername ~= owner) then
minetest.log("action", string.format("%s tried to access a %s belonging to %s at %s",
playername, infotext, owner, minetest.pos_to_string(pos)
playername, name, owner, minetest.pos_to_string(pos)
))
return 0
end
@ -146,7 +142,7 @@ function homedecor.handle_inventory(name, def, original_def)
if (playername ~= owner) then
minetest.log("action", string.format("%s tried to access a %s belonging to %s at %s",
playername, infotext, owner, minetest.pos_to_string(pos)
playername, name, owner, minetest.pos_to_string(pos)
))
return 0
end
@ -154,4 +150,23 @@ function homedecor.handle_inventory(name, def, original_def)
or stack:get_count()
end
end
local lockable = inventory.lockable
if lockable then
local locked_def = table.copy(original_def)
locked_def.description = S("%s (Locked)"):format(def.infotext or def.description)
local locked_inventory = locked_def.inventory
locked_inventory.locked = true
locked_inventory.lockable = nil -- avoid loops of locked locked stuff
local locked_name = name .. "_locked"
homedecor.register(locked_name, locked_def)
minetest.register_craft({
type = "shapeless",
output = "homedecor:" .. locked_name,
recipe = { "homedecor:" .. name, "default:steel_ingot" }
})
end
end

View File

@ -115,32 +115,6 @@ local function create_locked ( name, infotext )
end
local items = {
{ "refrigerator_white",
"Refrigerator" },
{ "refrigerator_steel",
"Refrigerator (stainless steel)" },
{ "kitchen_cabinet",
"Cabinet" },
{ "kitchen_cabinet_steel",
"Cabinet (stainless steel top)" },
{ "kitchen_cabinet_granite",
"Cabinet (granite top)" },
{ "kitchen_cabinet_marble",
"Cabinet (marble top)" },
{ "kitchen_cabinet_half",
"Cabinet" },
{ "kitchen_cabinet_with_sink",
"Cabinet" },
{ "nightstand_oak_one_drawer",
"Nightstand" },
{ "nightstand_oak_two_drawers",
"Nightstand" },
{ "nightstand_mahogany_one_drawer",
"Nightstand" },
{ "nightstand_mahogany_two_drawers",
"Nightstand" },
{ "filing_cabinet",
"Filing cabinet" },
{ "oven",
"Oven" },
{ "oven_active",

View File

@ -35,7 +35,7 @@ homedecor.register("refrigerator_white", {
infotext=S("Refrigerator"),
inventory = {
size=50,
lockable=true
lockable=true,
},
on_rotate = screwdriver.rotate_simple
})

View File

@ -29,6 +29,7 @@ for _, mat in ipairs(counter_materials) do
infotext=S("Kitchen Cabinet"),
inventory = {
size=24,
lockable=true,
},
})
end
@ -51,6 +52,7 @@ homedecor.register("kitchen_cabinet_half", {
infotext=S("Kitchen Cabinet"),
inventory = {
size=12,
lockable=true,
},
})
@ -68,6 +70,7 @@ homedecor.register("kitchen_cabinet_with_sink", {
infotext=S("Under-sink cabinet"),
inventory = {
size=16,
lockable=true,
},
node_box = {
type = "fixed",

View File

@ -13,6 +13,7 @@ homedecor.register("filing_cabinet", {
infotext=S("Filing cabinet"),
inventory = {
size=16,
lockable=true,
},
})