added /protector_show /protector_hide feature

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

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