2013-02-25 18:02:42 +01:00
|
|
|
-- Locked Stuff for Home Decor mod, by Kaeza
|
|
|
|
--
|
|
|
|
-- The code is mostly copypasta from default:chest_locked, with a few
|
|
|
|
-- tidbits to ease creation of new items, should need arise.
|
|
|
|
|
2013-10-22 02:31:54 +02:00
|
|
|
local S = homedecor.gettext
|
2013-03-05 08:18:56 +01:00
|
|
|
|
2013-02-25 18:02:42 +01:00
|
|
|
--[[
|
|
|
|
| create_locked ( name, infotext )
|
|
|
|
|
|
|
|
|
| Description:
|
|
|
|
| This function takes a base node name such as "homedecor:refrigerator",
|
|
|
|
| copies the definition from the original item into a new table, modifies
|
|
|
|
| it a bit, and registers a new node with a "_locked" suffix such as
|
|
|
|
| "homedecor:refrigerator_locked". The new node behaves identically to
|
|
|
|
| the base node, except that moving items to/from the node's inventory
|
|
|
|
| is only allowed for the original placer. In addition, it register a new
|
|
|
|
| shapeless recipe for the node, using the base node plus a steel ingot.
|
|
|
|
|
|
|
|
|
| Arguments:
|
|
|
|
| name The base node name
|
|
|
|
| infotext The infotext description (in case the name is too long).
|
|
|
|
|
|
|
|
|
| Example Usage:
|
|
|
|
| create_locked("homedecor:refrigerator", "Locked Fridge")
|
|
|
|
| ^ This generates a new "Locked Refrigerator" node, whose infotext is
|
|
|
|
| "Locked Fridge (owned by <placer>)".
|
|
|
|
|
|
|
|
|
| Notes:
|
|
|
|
| If <infotext> is not specified (or is nil), the infotext will be the
|
|
|
|
| base node's description prefixed by "Locked ".
|
|
|
|
|
|
2013-03-09 05:22:10 +01:00
|
|
|
| The ABM for the locked oven is defined in oven.lua.
|
2013-02-25 18:02:42 +01:00
|
|
|
]]
|
|
|
|
local function create_locked ( name, infotext )
|
|
|
|
local def = { }
|
|
|
|
for k, v in pairs(minetest.registered_nodes[name]) do
|
|
|
|
def[k] = v
|
|
|
|
end
|
|
|
|
def.type = nil
|
|
|
|
def.name = nil
|
2013-03-05 08:18:56 +01:00
|
|
|
def.description = S("%s (Locked)"):format(def.description)
|
2013-02-25 18:02:42 +01:00
|
|
|
local after_place_node = def.after_place_node
|
|
|
|
def.after_place_node = function(pos, placer)
|
2013-07-01 05:55:07 +02:00
|
|
|
local meta = minetest.get_meta(pos)
|
2013-02-25 18:02:42 +01:00
|
|
|
meta:set_string("owner", placer:get_player_name() or "")
|
2013-03-05 08:18:56 +01:00
|
|
|
meta:set_string("infotext", S("%s (owned by %s)"):format(infotext,meta:get_string("owner")))
|
2013-02-25 18:02:42 +01:00
|
|
|
if (after_place_node) then
|
|
|
|
return after_place_node(pos, placer)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local allow_metadata_inventory_move = def.allow_metadata_inventory_move;
|
|
|
|
def.allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
2013-07-01 05:55:07 +02:00
|
|
|
local meta = minetest.get_meta(pos)
|
2013-02-25 18:02:42 +01:00
|
|
|
if (player:get_player_name() ~= meta:get_string("owner")) then
|
2013-03-05 08:18:56 +01:00
|
|
|
minetest.log("action", S("%s tried to access a %s belonging to %s at %s"):format(
|
|
|
|
player:get_player_name(),
|
|
|
|
infotext,
|
|
|
|
meta:get_string("owner"),
|
|
|
|
minetest.pos_to_string(pos)
|
|
|
|
))
|
2013-02-25 18:02:42 +01:00
|
|
|
return 0
|
|
|
|
end
|
|
|
|
if (allow_metadata_inventory_move) then
|
|
|
|
return allow_metadata_inventory_move(pos, from_list, from_index, to_list, to_index, count, player)
|
|
|
|
else
|
|
|
|
return count
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local allow_metadata_inventory_put = def.allow_metadata_inventory_put;
|
|
|
|
def.allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
2013-07-01 05:55:07 +02:00
|
|
|
local meta = minetest.get_meta(pos)
|
2013-02-25 18:02:42 +01:00
|
|
|
if (player:get_player_name() ~= meta:get_string("owner")) then
|
2013-03-05 08:18:56 +01:00
|
|
|
minetest.log("action", S("%s tried to access a %s belonging to %s at %s"):format(
|
|
|
|
player:get_player_name(),
|
|
|
|
infotext,
|
|
|
|
meta:get_string("owner"),
|
|
|
|
minetest.pos_to_string(pos)
|
|
|
|
))
|
2013-02-25 18:02:42 +01:00
|
|
|
return 0
|
|
|
|
end
|
|
|
|
if (allow_metadata_inventory_put) then
|
|
|
|
return allow_metadata_inventory_put(pos, listname, index, stack, player)
|
|
|
|
else
|
|
|
|
return stack:get_count()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local allow_metadata_inventory_take = def.allow_metadata_inventory_take;
|
|
|
|
def.allow_metadata_inventory_take = function(pos, listname, index, stack, player)
|
2013-07-01 05:55:07 +02:00
|
|
|
local meta = minetest.get_meta(pos)
|
2013-02-25 18:02:42 +01:00
|
|
|
if (player:get_player_name() ~= meta:get_string("owner")) then
|
2013-03-05 08:18:56 +01:00
|
|
|
minetest.log("action", S("%s tried to access a %s belonging to %s at %s"):format(
|
|
|
|
player:get_player_name(),
|
|
|
|
infotext,
|
|
|
|
meta:get_string("owner"),
|
|
|
|
minetest.pos_to_string(pos)
|
|
|
|
))
|
2013-02-25 18:02:42 +01:00
|
|
|
return 0
|
|
|
|
end
|
|
|
|
if (allow_metadata_inventory_take) then
|
|
|
|
return allow_metadata_inventory_take(pos, listname, index, stack, player)
|
|
|
|
else
|
|
|
|
return stack:get_count()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
minetest.register_node(name.."_locked", def)
|
|
|
|
minetest.register_craft({
|
|
|
|
output = name.."_locked",
|
|
|
|
type = "shapeless",
|
|
|
|
recipe = {
|
|
|
|
name,
|
|
|
|
"default:steel_ingot",
|
|
|
|
}
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
local items = {
|
2013-03-05 08:18:56 +01:00
|
|
|
{ "refrigerator",
|
2014-03-25 14:16:47 +01:00
|
|
|
"Fridge" },
|
2014-06-25 06:24:03 +02:00
|
|
|
{ "refrigerator_steel",
|
|
|
|
"Fridge (stainless steel)" },
|
2013-03-05 08:18:56 +01:00
|
|
|
{ "kitchen_cabinet",
|
|
|
|
"Cabinet" },
|
2014-06-25 09:33:11 +02:00
|
|
|
{ "kitchen_cabinet_steel",
|
|
|
|
"Cabinet (stainless steel top)" },
|
|
|
|
{ "kitchen_cabinet_granite",
|
|
|
|
"Cabinet (granite top)" },
|
|
|
|
{ "kitchen_cabinet_marble",
|
|
|
|
"Cabinet (marble top)" },
|
2013-03-05 08:18:56 +01:00
|
|
|
{ "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" },
|
2014-06-26 14:10:10 +02:00
|
|
|
{ "filing_cabinet",
|
|
|
|
"Filing cabinet" },
|
2013-03-05 08:18:56 +01:00
|
|
|
{ "oven",
|
|
|
|
"Oven" },
|
2013-03-09 05:22:10 +01:00
|
|
|
{ "oven_active",
|
2013-07-12 22:41:11 +02:00
|
|
|
"Oven (active)" },
|
2014-06-25 06:24:03 +02:00
|
|
|
{ "oven_steel",
|
|
|
|
"Oven (stainless steel)" },
|
|
|
|
{ "oven_steel_active",
|
|
|
|
"Oven (stainless steel, active)" },
|
2013-07-12 22:41:11 +02:00
|
|
|
{ "microwave_oven",
|
|
|
|
"Microwave Oven" },
|
|
|
|
{ "microwave_oven_active",
|
|
|
|
"Microwave Oven (active)" },
|
2013-02-25 18:02:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for _,item in ipairs(items) do
|
2013-03-05 08:18:56 +01:00
|
|
|
local name, info = item[1], item[2];
|
|
|
|
create_locked("homedecor:"..name, S("Locked "..info));
|
2013-02-25 18:02:42 +01:00
|
|
|
end
|