added /protector_show /protector_hide feature

This commit is contained in:
TenPlus1 2020-06-12 11:41:33 +01:00
parent db932e676c
commit c147242c7d
5 changed files with 106 additions and 7 deletions

View File

@ -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

View File

@ -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
})

View File

@ -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]

View File

@ -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

View File

@ -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!"))