From c2bbdc7745712bd5bd53f33c03ac929e688e4529 Mon Sep 17 00:00:00 2001 From: Sires Date: Sun, 5 Apr 2020 16:22:25 -0300 Subject: [PATCH] Added protector mod support --- technic_chests/common.lua | 19 +++++++++++ technic_chests/copper_chest.lua | 41 +++++++++++++++++++--- technic_chests/depends.txt | 1 + technic_chests/gold_chest.lua | 33 ++++++++++++++++++ technic_chests/iron_chest.lua | 31 +++++++++++++++++ technic_chests/mithril_chest.lua | 32 ++++++++++++++++++ technic_chests/mod.conf | 2 +- technic_chests/register.lua | 58 +++++++++++++++++++++++++++++--- technic_chests/silver_chest.lua | 33 ++++++++++++++++++ 9 files changed, 239 insertions(+), 11 deletions(-) diff --git a/technic_chests/common.lua b/technic_chests/common.lua index 6369b7a..5b662f1 100644 --- a/technic_chests/common.lua +++ b/technic_chests/common.lua @@ -36,6 +36,15 @@ local function inv_change(pos, count, player) return count end +local function inv_change_protected(pos, count, player) + -- Skip check for pipeworks (fake player) + if minetest.is_player(player) and + minetest.is_protected(pos, player:get_player_name()) then + return 0 + end + return count +end + function technic.chests.inv_move(pos, from_list, from_index, to_list, to_index, count, player) return inv_change(pos, count, player) end @@ -46,6 +55,16 @@ function technic.chests.inv_take(pos, listname, index, stack, player) return inv_change(pos, stack:get_count(), player) end +function technic.chests.inv_move_protected(pos, from_list, from_index, to_list, to_index, count, player) + return inv_change_protected(pos, count, player) +end +function technic.chests.inv_put_protected(pos, listname, index, stack, player) + return inv_change_protected(pos, stack:get_count(), player) +end +function technic.chests.inv_take_protected(pos, listname, index, stack, player) + return inv_change_protected(pos, stack:get_count(), player) +end + function technic.chests.on_inv_move(pos, from_list, from_index, to_list, to_index, count, player) minetest.log("action", player:get_player_name().. " moves stuff in chest at " diff --git a/technic_chests/copper_chest.lua b/technic_chests/copper_chest.lua index fda1db0..075132a 100644 --- a/technic_chests/copper_chest.lua +++ b/technic_chests/copper_chest.lua @@ -17,11 +17,11 @@ minetest.register_craft({ }) minetest.register_craft({ - output = 'technic:copper_locked_chest 1', - recipe = { - {'basic_materials:padlock'}, - {'technic:copper_chest'}, - } + output = 'technic:copper_locked_chest 1', + recipe = { + {'basic_materials:padlock'}, + {'technic:copper_chest'}, + } }) technic.chests:register("Copper", { @@ -32,6 +32,7 @@ technic.chests:register("Copper", { infotext = false, color = false, locked = false, + protected = false, }) technic.chests:register("Copper", { @@ -42,5 +43,35 @@ technic.chests:register("Copper", { infotext = false, color = false, locked = true, + protected = false, }) +if minetest.get_modpath("protector") then + minetest.register_craft({ + output = 'technic:copper_protected_chest 1', + recipe = { + {'default:copper_ingot','default:copper_ingot','default:copper_ingot'}, + {'default:copper_ingot','technic:iron_protected_chest','default:copper_ingot'}, + {'default:copper_ingot','default:copper_ingot','default:copper_ingot'}, + } + }) + + minetest.register_craft({ + output = 'technic:copper_protected_chest 1', + recipe = { + {'default:copper_ingot'}, + {'technic:copper_chest'}, + } + }) + + technic.chests:register("Copper", { + width = 12, + height = 5, + sort = true, + autosort = true, + infotext = false, + color = false, + locked = false, + protected = true, + }) +end diff --git a/technic_chests/depends.txt b/technic_chests/depends.txt index 3fcc834..03daa60 100644 --- a/technic_chests/depends.txt +++ b/technic_chests/depends.txt @@ -5,3 +5,4 @@ moreores? pipeworks? intllib? tubelib? +protector? diff --git a/technic_chests/gold_chest.lua b/technic_chests/gold_chest.lua index 7a50b70..9c4ac50 100644 --- a/technic_chests/gold_chest.lua +++ b/technic_chests/gold_chest.lua @@ -25,6 +25,17 @@ for _, material in ipairs(material_list) do {'default:gold_ingot','default:gold_ingot','default:gold_ingot'}, } }) + + if minetest.get_modpath("protector") then + minetest.register_craft({ + output = 'technic:gold_protected_chest', + recipe = { + {'default:gold_ingot','default:gold_ingot','default:gold_ingot'}, + {'default:gold_ingot',"technic:"..material.."_protected_chest",'default:gold_ingot'}, + {'default:gold_ingot','default:gold_ingot','default:gold_ingot'}, + } + }) + end end minetest.register_craft({ @@ -43,6 +54,7 @@ technic.chests:register("Gold", { infotext = true, color = true, locked = false, + protected = false, }) technic.chests:register("Gold", { @@ -53,5 +65,26 @@ technic.chests:register("Gold", { infotext = true, color = true, locked = true, + protected = false, }) +if minetest.get_modpath("protector") then + minetest.register_craft({ + output = 'technic:gold_protected_chest', + recipe = { + {'default:copper_ingot'}, + {'technic:gold_chest'}, + } + }) + + technic.chests:register("Gold", { + width = 15, + height = 6, + sort = true, + autosort = true, + infotext = true, + color = true, + locked = false, + protected = true, + }) +end diff --git a/technic_chests/iron_chest.lua b/technic_chests/iron_chest.lua index 237067b..395d612 100644 --- a/technic_chests/iron_chest.lua +++ b/technic_chests/iron_chest.lua @@ -39,6 +39,7 @@ technic.chests:register("Iron", { infotext = false, color = false, locked = false, + protected = false, }) technic.chests:register("Iron", { @@ -49,5 +50,35 @@ technic.chests:register("Iron", { infotext = false, color = false, locked = true, + protected = false, }) +if minetest.get_modpath("protector") then + minetest.register_craft({ + output = 'technic:iron_protected_chest 1', + recipe = { + {cast_iron_ingot,cast_iron_ingot,cast_iron_ingot}, + {cast_iron_ingot,'protector:chest',cast_iron_ingot}, + {cast_iron_ingot,cast_iron_ingot,cast_iron_ingot}, + } + }) + + minetest.register_craft({ + output = 'technic:iron_protected_chest 1', + recipe = { + {'default:copper_ingot'}, + {'technic:iron_chest'}, + } + }) + + technic.chests:register("Iron", { + width = 9, + height = 5, + sort = true, + autosort = false, + infotext = false, + color = false, + locked = false, + protected = true, + }) +end diff --git a/technic_chests/mithril_chest.lua b/technic_chests/mithril_chest.lua index 05cbc40..bfa8e66 100644 --- a/technic_chests/mithril_chest.lua +++ b/technic_chests/mithril_chest.lua @@ -16,6 +16,16 @@ if minetest.get_modpath("moreores") then {'moreores:mithril_ingot','moreores:mithril_ingot','moreores:mithril_ingot'}, } }) + if minetest.get_modpath("protector") then + minetest.register_craft({ + output = 'technic:mithril_protected_chest 1', + recipe = { + {'moreores:mithril_ingot','moreores:mithril_ingot','moreores:mithril_ingot'}, + {'moreores:mithril_ingot','technic:gold_protected_chest','moreores:mithril_ingot'}, + {'moreores:mithril_ingot','moreores:mithril_ingot','moreores:mithril_ingot'}, + } + }) + end end minetest.register_craft({ @@ -34,6 +44,7 @@ technic.chests:register("Mithril", { infotext = false, color = false, locked = false, + protected = false, }) technic.chests:register("Mithril", { @@ -44,5 +55,26 @@ technic.chests:register("Mithril", { infotext = false, color = false, locked = true, + protected = false, }) +if minetest.get_modpath("protector") then + minetest.register_craft({ + output = 'technic:mithril_protected_chest 1', + recipe = { + {'default:copper_ingot'}, + {'technic:mithril_chest'}, + } + }) + + technic.chests:register("Mithril", { + width = 15, + height = 6, + sort = true, + autosort = true, + infotext = false, + color = false, + locked = false, + protected = true, + }) +end diff --git a/technic_chests/mod.conf b/technic_chests/mod.conf index 99048c3..c78dc68 100644 --- a/technic_chests/mod.conf +++ b/technic_chests/mod.conf @@ -1,3 +1,3 @@ name = technic_chests depends = default, basic_materials -optional_depends = moreblocks, moreores, pipeworks, intllib, tubelib +optional_depends = moreblocks, moreores, pipeworks, intllib, tubelib, protector diff --git a/technic_chests/register.lua b/technic_chests/register.lua index 0d5150e..dd3c3d3 100644 --- a/technic_chests/register.lua +++ b/technic_chests/register.lua @@ -172,7 +172,10 @@ local function get_receive_fields(name, data) end if data.color then -- This sets the node - local nn = "technic:"..lname..(data.locked and "_locked" or "").."_chest" + -- local nn = "technic:"..lname..(data.locked and "_locked" or "").."_chest" + local nn = "technic:"..name:lower().. + (data.locked and "_locked" or "").. + (data.protected and "_protected" or "").."_chest" check_color_buttons(pos, meta, nn, fields) end if fields["fs_helpers_cycling:0:splitstacks"] @@ -240,14 +243,23 @@ function technic.chests:definition(name, data) pipeworks.after_place(pos) end table.insert(front, "technic_"..lname.."_chest_lock_overlay.png") - else + elseif data.protected then + locked_after_place = function(pos, _) + local meta = minetest.get_meta(pos) + meta:set_string("infotext", + S("%s Protected Chest"):format(name)) + pipeworks.after_place(pos) + end + else locked_after_place = pipeworks.after_place end local desc if data.locked then desc = S("%s Locked Chest"):format(name) - else + elseif data.protected then + desc = S("%s Protected Chest"):format(name) + else desc = S("%s Chest"):format(name) end @@ -292,7 +304,10 @@ function technic.chests:definition(name, data) on_blast = function(pos) local drops = {} default.get_inventory_drops(pos, "main", drops) - drops[#drops+1] = "technic:"..name:lower()..(data.locked and "_locked" or "").."_chest" + -- drops[#drops+1] = "technic:"..name:lower()..(data.locked and "_locked" or "").."_chest" + drops[#drops+1] = "technic:"..name:lower().. + (data.locked and "_locked" or "").. + (data.protected and "_protected" or "").."_chest" minetest.remove_node(pos) return drops end, @@ -328,6 +343,37 @@ function technic.chests:definition(name, data) return secret, "a locked chest", owner end end + if data.protected then + def.allow_metadata_inventory_move = self.inv_move_protected + def.allow_metadata_inventory_put = self.inv_put_protected + def.allow_metadata_inventory_take = self.inv_take_protected + def.on_blast = function() end + def.can_dig = function(pos,player) + local meta = minetest.get_meta(pos); + local inv = meta:get_inventory() + return inv:is_empty("main") and default.can_interact_with_node(player, pos) + end + def.on_skeleton_key_use = function(pos, player, newsecret) + local meta = minetest.get_meta(pos) + local owner = meta:get_string("owner") + local name = player:get_player_name() + + -- verify placer is owner of lockable chest + if owner ~= name then + minetest.record_protection_violation(pos, name) + minetest.chat_send_player(name, "You do not own this chest.") + return nil + end + + local secret = meta:get_string("key_lock_secret") + if secret == "" then + secret = newsecret + meta:set_string("key_lock_secret", secret) + end + + return secret, "a locked chest", owner + end + end return def end @@ -364,7 +410,9 @@ local _TUBELIB_CALLBACKS = { function technic.chests:register(name, data) local def = technic.chests:definition(name, data) - local nn = "technic:"..name:lower()..(data.locked and "_locked" or "").."_chest" + local nn = "technic:"..name:lower().. + (data.locked and "_locked" or "").. + (data.protected and "_protected" or "").."_chest" minetest.register_node(":"..nn, def) if tubelib_exists then diff --git a/technic_chests/silver_chest.lua b/technic_chests/silver_chest.lua index 4de196d..0466dd4 100644 --- a/technic_chests/silver_chest.lua +++ b/technic_chests/silver_chest.lua @@ -16,6 +16,17 @@ if minetest.get_modpath("moreores") then {'moreores:silver_ingot','moreores:silver_ingot','moreores:silver_ingot'}, } }) + + if minetest.get_modpath("protector") then + minetest.register_craft({ + output = 'technic:silver_protected_chest', + recipe = { + {'moreores:silver_ingot','moreores:silver_ingot','moreores:silver_ingot'}, + {'moreores:silver_ingot','technic:copper_protected_chest','moreores:silver_ingot'}, + {'moreores:silver_ingot','moreores:silver_ingot','moreores:silver_ingot'}, + } + }) + end end minetest.register_craft({ @@ -34,6 +45,7 @@ technic.chests:register("Silver", { infotext = true, color = false, locked = false, + protected = false, }) technic.chests:register("Silver", { @@ -44,5 +56,26 @@ technic.chests:register("Silver", { infotext = true, color = false, locked = true, + protected = false, }) +if minetest.get_modpath("protector") then + minetest.register_craft({ + output = 'technic:silver_protected_chest', + recipe = { + {'default:copper_ingot'}, + {'technic:silver_chest'}, + } + }) + + technic.chests:register("Silver", { + width = 12, + height = 6, + sort = true, + autosort = true, + infotext = true, + color = false, + locked = false, + protected = true, + }) +end