From 908b40824830ef5f6d2fc36929415d0aa402657f Mon Sep 17 00:00:00 2001 From: Tim Date: Wed, 19 Aug 2015 22:30:27 +0200 Subject: [PATCH] register the furnaces internally via homedecor.register as well, getting rid of the last dependency on deprecated lock-code --- homedecor/handlers/furnaces.lua | 19 +++-- homedecor/handlers/locked.lua | 135 ------------------------------- homedecor/init.lua | 2 - homedecor/kitchen_appliances.lua | 10 +-- 4 files changed, 15 insertions(+), 151 deletions(-) delete mode 100644 homedecor/handlers/locked.lua diff --git a/homedecor/handlers/furnaces.lua b/homedecor/handlers/furnaces.lua index 0e9888e2..02212a63 100644 --- a/homedecor/handlers/furnaces.lua +++ b/homedecor/handlers/furnaces.lua @@ -97,9 +97,7 @@ function homedecor.register_furnace(name, furnacedef) local def = { description = furnacedef.description, tiles = tiles, - paramtype2 = furnacedef.paramtype2 or "facedir", groups = furnacedef.groups or {cracky=2}, - legacy_facedir_simple = true, sounds = furnacedef.sounds or default.node_sound_wood_defaults(), on_construct = function(pos) local meta = minetest.get_meta(pos) @@ -159,17 +157,17 @@ function homedecor.register_furnace(name, furnacedef) return 0 end end, + inventory = { + lockable = true + } } local def_active = { description = furnacedef.description.." (active)", tiles = tiles_active, - paramtype = furnacedef.paramtype, - paramtype2 = furnacedef.paramtype2 or "facedir", light_source = 8, - drop = name, + drop = "homedecor:" .. name, groups = furnacedef.groups or {cracky=2, not_in_creative_inventory=1}, - legacy_facedir_simple = true, sounds = furnacedef.sounds or default.node_sound_stone_defaults(), on_construct = function(pos) local meta = minetest.get_meta(pos) @@ -229,6 +227,9 @@ function homedecor.register_furnace(name, furnacedef) return 0 end end, + inventory = { + lockable = true + } } if furnacedef.extra_nodedef_fields then @@ -238,8 +239,10 @@ function homedecor.register_furnace(name, furnacedef) end end - minetest.register_node(name, def) - minetest.register_node(name_active, def_active) + homedecor.register(name, def) + homedecor.register(name_active, def_active) + + local name, name_active = "homedecor:"..name, "homedecor:"..name_active minetest.register_abm({ nodenames = {name, name_active, name.."_locked", name_active.."_locked"}, diff --git a/homedecor/handlers/locked.lua b/homedecor/handlers/locked.lua deleted file mode 100644 index 2737e04e..00000000 --- a/homedecor/handlers/locked.lua +++ /dev/null @@ -1,135 +0,0 @@ --- 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. - -local S = homedecor.gettext - ---[[ - | 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 )". - | - | Notes: - | If is not specified (or is nil), the infotext will be the - | base node's description prefixed by "Locked ". - | - | The ABM for the locked oven is defined in oven.lua. - ]] -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 - def.description = S("%s (Locked)"):format(def.description) - local after_place_node = def.after_place_node - def.after_place_node = function(pos, placer) - local meta = minetest.get_meta(pos) - meta:set_string("owner", placer:get_player_name() or "") - meta:set_string("infotext", S("%s (owned by %s)"):format(infotext,meta:get_string("owner"))) - 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) - local meta = minetest.get_meta(pos) - if (player:get_player_name() ~= meta:get_string("owner")) then - 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) - )) - 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) - local meta = minetest.get_meta(pos) - if (player:get_player_name() ~= meta:get_string("owner")) then - 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) - )) - 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) - local meta = minetest.get_meta(pos) - if (player:get_player_name() ~= meta:get_string("owner")) then - 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) - )) - 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 = { - { "oven", - "Oven" }, - { "oven_active", - "Oven (active)" }, - { "oven_steel", - "Oven (stainless steel)" }, - { "oven_steel_active", - "Oven (stainless steel, active)" }, - { "microwave_oven", - "Microwave Oven" }, - { "microwave_oven_active", - "Microwave Oven (active)" }, -} - -for _,item in ipairs(items) do - local name, info = item[1], item[2]; - create_locked("homedecor:"..name, S("Locked "..info)); -end diff --git a/homedecor/init.lua b/homedecor/init.lua index d0c699a7..d92a8afa 100644 --- a/homedecor/init.lua +++ b/homedecor/init.lua @@ -140,8 +140,6 @@ dofile(modpath.."/exterior.lua") dofile(modpath.."/trash_cans.lua") dofile(modpath.."/wardrobe.lua") -dofile(modpath.."/handlers/locked.lua") - dofile(modpath.."/crafts.lua") print("[HomeDecor] " .. homedecor.gettext("Loaded!")) diff --git a/homedecor/kitchen_appliances.lua b/homedecor/kitchen_appliances.lua index 80804fc8..6ef016cd 100644 --- a/homedecor/kitchen_appliances.lua +++ b/homedecor/kitchen_appliances.lua @@ -53,7 +53,7 @@ minetest.register_alias("homedecor:refrigerator_steel_bottom_locked", "homedecor minetest.register_alias("homedecor:refrigerator_steel_top_locked", "air") -- kitchen "furnaces" -homedecor.register_furnace("homedecor:oven", { +homedecor.register_furnace("oven", { description = S("Oven"), tile_format = "homedecor_oven_%s%s.png", output_slots = 4, @@ -61,7 +61,7 @@ homedecor.register_furnace("homedecor:oven", { cook_speed = 1.25, }) -homedecor.register_furnace("homedecor:oven_steel", { +homedecor.register_furnace("oven_steel", { description = S("Oven (stainless steel)"), tile_format = "homedecor_oven_steel_%s%s.png", output_slots = 4, @@ -69,7 +69,7 @@ homedecor.register_furnace("homedecor:oven_steel", { cook_speed = 1.25, }) -homedecor.register_furnace("homedecor:microwave_oven", { +homedecor.register_furnace("microwave_oven", { description = S("Microwave Oven"), tiles = { "homedecor_microwave_top.png", "homedecor_microwave_top.png^[transformR180", @@ -85,11 +85,9 @@ homedecor.register_furnace("homedecor:microwave_oven", { output_width = 2, cook_speed = 1.5, extra_nodedef_fields = { - drawtype = "nodebox", - paramtype = "light", node_box = { type = "fixed", - fixed = { { -0.5, -0.5, -0.125, 0.5, 0.125, 0.5 } }, + fixed = { -0.5, -0.5, -0.125, 0.5, 0.125, 0.5 }, }, }, })