From c147242c7de7a95e55b36526fc18d5c10431914d Mon Sep 17 00:00:00 2001 From: TenPlus1 Date: Fri, 12 Jun 2020 11:41:33 +0100 Subject: [PATCH] added /protector_show /protector_hide feature --- README.md | 6 ++++ admin.lua | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- hud.lua | 2 +- init.lua | 2 +- tool.lua | 4 +-- 5 files changed, 106 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 009779e..d40465a 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,7 @@ Change log: - 2.8 - Added 'protector_show_interval' setting to minetest.conf [default is 5], make protection field glow in dark. - 2.9 - Added MineClone2 recipes for protection block but no official support as yet - 3.0 - Added PlayerFactions support, 'protector_hud_interval' setting and listing in advanced settings for mod values. +- 3.1 - Ability to hide protection blocks using /protector_hide and /protector_show Lucky Blocks: 10 @@ -94,6 +95,11 @@ reset name list show protected areas of your nearby protectors (max of 5) + /protector_show_area + + +A players own protection blocks can be hidden and shown using the following: + /protector_hide /protector_show diff --git a/admin.lua b/admin.lua index a6a4964..52d287d 100644 --- a/admin.lua +++ b/admin.lua @@ -68,7 +68,7 @@ minetest.register_chatcommand("protector_replace", { minetest.register_abm({ - nodenames = {"protector:protect", "protector:protect2"}, + nodenames = {"protector:protect", "protector:protect2", "protector:protect_hidden"}, interval = 8, chance = 1, catch_up = false, @@ -112,7 +112,7 @@ minetest.register_abm({ local r = tonumber(minetest.settings:get("protector_radius")) or 5 -- show protection areas of nearby protectors owned by you (thanks agaran) -minetest.register_chatcommand("protector_show", { +minetest.register_chatcommand("protector_show_area", { params = "", description = S("Show protected areas of your nearby protectors"), privs = {}, @@ -125,7 +125,7 @@ minetest.register_chatcommand("protector_show", { local pos = minetest.find_nodes_in_area( {x = pos.x - r, y = pos.y - r, z = pos.z - r}, {x = pos.x + r, y = pos.y + r, z = pos.z + r}, - {"protector:protect", "protector:protect2"}) + {"protector:protect", "protector:protect2", "protector:protect_hidden"}) local meta, owner @@ -141,3 +141,96 @@ minetest.register_chatcommand("protector_show", { end end }) + + +-- ability to hide protection blocks (borrowed from doors mod :) +minetest.register_node("protector:protect_hidden", { + description = "Hidden Protector", + drawtype = "airlike", + paramtype = "light", + paramtype2 = "facedir", + sunlight_propagates = true, + -- has to be walkable for falling nodes to stop falling + walkable = true, + pointable = false, + diggable = false, + buildable_to = false, + floodable = false, + drop = "", + groups = {not_in_creative_inventory = 1, unbreakable = 1}, + on_blast = function() end, + -- 1px block inside door hinge near node top + collision_box = { + type = "fixed", + fixed = {-15/32, 13/32, -15/32, -13/32, 1/2, -13/32}, + }, +}) + + +minetest.register_chatcommand("protector_show", { + params = "", + description = "Hide protection blocks", + privs = {interact = true}, + + func = function(name, param) + + local player = minetest.get_player_by_name(name) + + if not player then + return false, "Player not found" + end + + local pos = player:get_pos() + + local a = minetest.find_nodes_in_area( + {x = pos.x - r, y = pos.y - r, z = pos.z - r}, + {x = pos.x + r, y = pos.y + r, z = pos.z + r}, + {"protector:protect_hidden"}) + + local meta, owner + + for _, row in pairs(a) do + + meta = minetest.get_meta(row) + owner = meta:get_string("owner") or "" + + if owner == name then + minetest.swap_node(row, {name = "protector:protect"}) + end + end + end +}) + +minetest.register_chatcommand("protector_hide", { + params = "", + description = "Hide protection blocks", + privs = {interact = true}, + + func = function(name, param) + + local player = minetest.get_player_by_name(name) + + if not player then + return false, "Player not found" + end + + local pos = player:get_pos() + + local a = minetest.find_nodes_in_area( + {x = pos.x - r, y = pos.y - r, z = pos.z - r}, + {x = pos.x + r, y = pos.y + r, z = pos.z + r}, + {"protector:protect", "protector:protect2"}) + + local meta, owner + + for _, row in pairs(a) do + + meta = minetest.get_meta(row) + owner = meta:get_string("owner") or "" + + if owner == name then + minetest.swap_node(row, {name = "protector:protect_hidden"}) + end + end + end +}) diff --git a/hud.lua b/hud.lua index 6b70e71..9b78afa 100644 --- a/hud.lua +++ b/hud.lua @@ -24,7 +24,7 @@ minetest.register_globalstep(function(dtime) local protectors = minetest.find_nodes_in_area( {x = pos.x - radius , y = pos.y - radius , z = pos.z - radius}, {x = pos.x + radius , y = pos.y + radius , z = pos.z + radius}, - {"protector:protect","protector:protect2"}) + {"protector:protect","protector:protect2", "protector:protect_hidden"}) if #protectors > 0 then local npos = protectors[1] diff --git a/init.lua b/init.lua index 22bff1f..93ec483 100644 --- a/init.lua +++ b/init.lua @@ -244,7 +244,7 @@ protector.can_dig = function(r, pos, digger, onlyowner, infolevel) local pos = minetest.find_nodes_in_area( {x = pos.x - r, y = pos.y - r, z = pos.z - r}, {x = pos.x + r, y = pos.y + r, z = pos.z + r}, - {"protector:protect", "protector:protect2"}) + {"protector:protect", "protector:protect2", "protector:protect_hidden"}) local meta, owner, members diff --git a/tool.lua b/tool.lua index 575d1d0..41b385d 100644 --- a/tool.lua +++ b/tool.lua @@ -19,7 +19,7 @@ minetest.register_craftitem("protector:tool", { local pos = user:get_pos() local pp = minetest.find_nodes_in_area( vector.subtract(pos, 2), vector.add(pos, 2), - {"protector:protect", "protector:protect2"}) + {"protector:protect", "protector:protect2", "protector:protect_hidden"}) if #pp == 0 then return end -- none found @@ -67,7 +67,7 @@ minetest.register_craftitem("protector:tool", { -- does a protector already exist ? if #minetest.find_nodes_in_area( vector.subtract(pos, 1), vector.add(pos, 1), - {"protector:protect", "protector:protect2"}) > 0 then + {"protector:protect", "protector:protect2", "protector:protect_hidden"}) > 0 then minetest.chat_send_player(name, S("Protector already in place!"))