Skip to content

Commit

Permalink
Merge pull request #6 from mt-mods/upstream
Browse files Browse the repository at this point in the history
Upstream pull
  • Loading branch information
BuckarooBanzay authored Jul 7, 2020
2 parents e618c6d + 969a6dd commit c5c7a9b
Show file tree
Hide file tree
Showing 8 changed files with 357 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ read_globals = {
"intllib",
"mesecon",
"screwdriver",
"lucky_block"
"lucky_block",
"factions"
}
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ Change log:
- 2.7 - Remove protection field entity when protector has been dug
- 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 , italian local added (thanks Hamlet)

Lucky Blocks: 10

Expand Down Expand Up @@ -95,6 +97,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


Expand Down
104 changes: 100 additions & 4 deletions admin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 = {},
Expand All @@ -125,7 +125,7 @@ minetest.register_chatcommand("protector_show", {
local pos = minetest.find_nodes_in_area(
{x = ppos.x - r, y = ppos.y - r, z = ppos.z - r},
{x = ppos.x + r, y = ppos.y + r, z = ppos.z + r},
{"protector:protect", "protector:protect2"})
{"protector:protect", "protector:protect2", "protector:protect_hidden"})

local meta, owner

Expand All @@ -135,9 +135,105 @@ minetest.register_chatcommand("protector_show", {
meta = minetest.get_meta(pos[n])
owner = meta:get_string("owner") or ""

if owner == name then
if owner == name
or minetest.check_player_privs(name, {protection_bypass = true}) then
minetest.add_entity(pos[n], "protector:display")
end
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 = S("Show your nearby 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
or minetest.check_player_privs(name, {protection_bypass = true}) then
minetest.swap_node(row, {name = "protector:protect"})
end
end
end
})

minetest.register_chatcommand("protector_hide", {
params = "",
description = S("Hide your nearby 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
or minetest.check_player_privs(name, {protection_bypass = true}) then
minetest.swap_node(row, {name = "protector:protect_hidden"})
end
end
end
})
1 change: 1 addition & 0 deletions depends.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ default?
intllib?
lucky_block?
mesecons_mvps?
playerfactions?
8 changes: 6 additions & 2 deletions hud.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ local S = protector.intllib
local radius = (tonumber(minetest.setting_get("protector_radius")) or 5)
local hud = {}
local hud_timer = 0
local hud_interval = (tonumber(minetest.setting_get("protector_hud_interval")) or 5)

if hud_interval > 0 then
minetest.register_globalstep(function(dtime)

-- every 5 seconds
hud_timer = hud_timer + dtime
if hud_timer < 5 then
if hud_timer < hud_interval then
return
end
hud_timer = 0
Expand All @@ -22,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]
Expand Down Expand Up @@ -57,3 +59,5 @@ end)
minetest.register_on_leaveplayer(function(player)
hud[player:get_player_name()] = nil
end)

end
37 changes: 35 additions & 2 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ local MP = minetest.get_modpath(minetest.get_current_modname())
local S = dofile(MP .. "/intllib.lua")
local F = minetest.formspec_escape

-- Load support for factions
local factions_available = minetest.global_exists("factions")

protector = {
mod = "redo",
Expand Down Expand Up @@ -58,6 +60,15 @@ end
-- check for member name
local is_member = function (meta, name)

if factions_available
and meta:get_int("faction_members") == 1
and factions.get_player_faction(name) ~= nil
and factions.get_player_faction(meta:get_string("owner")) ==
factions.get_player_faction(name) then

return true
end

for _, n in pairs(get_member_list(meta)) do

if n == name then
Expand Down Expand Up @@ -129,6 +140,19 @@ local protector_formspec = function(meta)
local npp = protector_max_share_count -- max users added to protector list
local i = 0

if factions_available
and factions.get_player_faction(meta:get_string("owner")) then

formspec = formspec .. "checkbox[0,5;faction_members;"
.. F(S("Allow faction access"))
.. ";" .. (meta:get_int("faction_members") == 1 and
"true" or "false") .. "]"

if npp > 8 then
npp = 8
end
end

for n = 1, #members do

if i < npp then
Expand Down Expand Up @@ -220,7 +244,7 @@ protector.can_dig = function(r, pos, digger, onlyowner, infolevel)
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

Expand Down Expand Up @@ -293,7 +317,11 @@ function minetest.is_protected(pos, digger)

-- hurt player if protection violated
if protector_hurt > 0 and player:get_hp() > 0 then
player:set_hp(player:get_hp() - protector_hurt)

-- This delay fixes item duplication bug (thanks luk3yx)
minetest.after(0.1, function()
player:set_hp(player:get_hp() - protector_hurt)
end)
end

-- flip player when protection violated
Expand Down Expand Up @@ -609,6 +637,11 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
return
end

-- add faction members
if factions_available then
meta:set_int("faction_members", fields.faction_members == "true" and 1 or 0)
end

-- add member [+]
if add_member_input then

Expand Down
Loading

0 comments on commit c5c7a9b

Please sign in to comment.