2016-06-05 13:06:59 +02:00
|
|
|
|
2016-11-02 17:54:19 +01:00
|
|
|
-- get minetest.conf settings
|
2014-11-09 20:43:01 +01:00
|
|
|
protector = {}
|
2015-08-04 21:41:34 +02:00
|
|
|
protector.mod = "redo"
|
2017-10-09 14:58:19 +02:00
|
|
|
protector.radius = tonumber(minetest.settings:get("protector_radius")) or 5
|
|
|
|
protector.flip = minetest.settings:get_bool("protector_flip") or false
|
|
|
|
protector.hurt = tonumber(minetest.settings:get("protector_hurt")) or 0
|
|
|
|
protector.spawn = tonumber(minetest.settings:get("protector_spawn")
|
|
|
|
or minetest.settings:get("protector_pvp_spawn")) or 0
|
2016-11-02 17:54:19 +01:00
|
|
|
|
2017-02-23 11:05:21 +01:00
|
|
|
|
2016-11-02 17:54:19 +01:00
|
|
|
-- get static spawn position
|
2017-10-09 14:58:19 +02:00
|
|
|
local statspawn = minetest.string_to_pos(minetest.settings:get("static_spawnpoint"))
|
|
|
|
or {x = 0, y = 2, z = 0}
|
2014-11-09 20:43:01 +01:00
|
|
|
|
2017-02-23 11:05:21 +01:00
|
|
|
|
2016-06-07 21:29:06 +02:00
|
|
|
-- Intllib
|
|
|
|
local S
|
|
|
|
if minetest.get_modpath("intllib") then
|
|
|
|
S = intllib.Getter()
|
|
|
|
else
|
2017-03-17 11:05:42 +01:00
|
|
|
S = function(s, a, ...) a = {a, ...}
|
|
|
|
return s:gsub("@(%d+)", function(n)
|
|
|
|
return a[tonumber(n)]
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
2016-06-07 21:29:06 +02:00
|
|
|
end
|
|
|
|
protector.intllib = S
|
|
|
|
|
2017-02-23 11:05:21 +01:00
|
|
|
|
2016-11-02 17:54:19 +01:00
|
|
|
-- return list of members as a table
|
2017-09-03 11:53:49 +02:00
|
|
|
local get_member_list = function(meta)
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2015-04-11 14:09:00 +02:00
|
|
|
return meta:get_string("members"):split(" ")
|
2014-11-09 20:43:01 +01:00
|
|
|
end
|
|
|
|
|
2017-02-23 11:05:21 +01:00
|
|
|
|
2016-11-02 17:54:19 +01:00
|
|
|
-- write member list table in protector meta as string
|
2017-09-03 11:53:49 +02:00
|
|
|
local set_member_list = function(meta, list)
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2014-11-09 20:43:01 +01:00
|
|
|
meta:set_string("members", table.concat(list, " "))
|
|
|
|
end
|
|
|
|
|
2017-02-23 11:05:21 +01:00
|
|
|
|
2017-09-03 11:53:49 +02:00
|
|
|
-- check for owner name
|
|
|
|
local is_owner = function(meta, name)
|
2017-08-22 16:54:53 +02:00
|
|
|
|
|
|
|
return name == meta:get_string("owner")
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2017-09-03 11:53:49 +02:00
|
|
|
-- check for member name
|
|
|
|
local is_member = function (meta, name)
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2017-09-03 11:53:49 +02:00
|
|
|
for _, n in pairs(get_member_list(meta)) do
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2014-11-09 20:43:01 +01:00
|
|
|
if n == name then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2014-11-09 20:43:01 +01:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2017-02-23 11:05:21 +01:00
|
|
|
|
2016-11-02 17:54:19 +01:00
|
|
|
-- add player name to table as member
|
2017-09-03 11:53:49 +02:00
|
|
|
local add_member = function(meta, name)
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2017-08-22 16:54:53 +02:00
|
|
|
-- does name already exist?
|
2017-09-03 11:53:49 +02:00
|
|
|
if is_owner(meta, name)
|
|
|
|
or is_member(meta, name) then
|
2015-11-13 12:23:30 +01:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2017-09-03 11:53:49 +02:00
|
|
|
local list = get_member_list(meta)
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2015-07-24 17:21:53 +02:00
|
|
|
table.insert(list, name)
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2017-09-03 11:53:49 +02:00
|
|
|
set_member_list(meta, list)
|
2014-11-09 20:43:01 +01:00
|
|
|
end
|
|
|
|
|
2017-02-23 11:05:21 +01:00
|
|
|
|
2016-11-02 17:54:19 +01:00
|
|
|
-- remove player name from table
|
2017-09-03 11:53:49 +02:00
|
|
|
local del_member = function(meta, name)
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2017-09-03 11:53:49 +02:00
|
|
|
local list = get_member_list(meta)
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2016-01-09 10:55:33 +01:00
|
|
|
for i, n in pairs(list) do
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2014-11-09 20:43:01 +01:00
|
|
|
if n == name then
|
|
|
|
table.remove(list, i)
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2017-09-03 11:53:49 +02:00
|
|
|
set_member_list(meta, list)
|
2014-11-09 20:43:01 +01:00
|
|
|
end
|
|
|
|
|
2017-02-23 11:05:21 +01:00
|
|
|
|
2016-11-02 17:54:19 +01:00
|
|
|
-- protector interface
|
2017-09-03 11:53:49 +02:00
|
|
|
local protector_formspec = function(meta)
|
2015-02-13 20:10:29 +01:00
|
|
|
|
2015-07-24 17:21:53 +02:00
|
|
|
local formspec = "size[8,7]"
|
2016-02-21 22:11:36 +01:00
|
|
|
.. default.gui_bg
|
|
|
|
.. default.gui_bg_img
|
|
|
|
.. default.gui_slots
|
2016-06-07 21:29:06 +02:00
|
|
|
.. "label[2.5,0;" .. S("-- Protector interface --") .. "]"
|
2017-08-22 16:54:53 +02:00
|
|
|
.. "label[0,1;" .. S("PUNCH node to show protected area") .. "]"
|
2016-06-07 21:29:06 +02:00
|
|
|
.. "label[0,2;" .. S("Members:") .. "]"
|
|
|
|
.. "button_exit[2.5,6.2;3,0.5;close_me;" .. S("Close") .. "]"
|
2015-02-13 20:10:29 +01:00
|
|
|
|
2017-09-03 11:53:49 +02:00
|
|
|
local members = get_member_list(meta)
|
2016-11-02 17:54:19 +01:00
|
|
|
local npp = 12 -- max users added to protector list
|
2014-11-09 20:43:01 +01:00
|
|
|
local i = 0
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2016-06-05 13:06:59 +02:00
|
|
|
for n = 1, #members do
|
2015-11-13 12:23:30 +01:00
|
|
|
|
|
|
|
if i < npp then
|
|
|
|
|
|
|
|
-- show username
|
|
|
|
formspec = formspec .. "button[" .. (i % 4 * 2)
|
|
|
|
.. "," .. math.floor(i / 4 + 3)
|
2016-06-05 13:06:59 +02:00
|
|
|
.. ";1.5,.5;protector_member;" .. members[n] .. "]"
|
2015-11-13 12:23:30 +01:00
|
|
|
|
|
|
|
-- username remove button
|
|
|
|
.. "button[" .. (i % 4 * 2 + 1.25) .. ","
|
|
|
|
.. math.floor(i / 4 + 3)
|
2016-06-05 13:06:59 +02:00
|
|
|
.. ";.75,.5;protector_del_member_" .. members[n] .. ";X]"
|
2015-11-13 12:23:30 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
i = i + 1
|
2014-11-09 20:43:01 +01:00
|
|
|
end
|
2015-02-13 20:10:29 +01:00
|
|
|
|
|
|
|
if i < npp then
|
2015-11-13 12:23:30 +01:00
|
|
|
|
|
|
|
-- user name entry field
|
2015-07-24 17:21:53 +02:00
|
|
|
formspec = formspec .. "field[" .. (i % 4 * 2 + 1 / 3) .. ","
|
2015-11-13 12:23:30 +01:00
|
|
|
.. (math.floor(i / 4 + 3) + 1 / 3)
|
|
|
|
.. ";1.433,.5;protector_add_member;;]"
|
|
|
|
|
|
|
|
-- username add button
|
|
|
|
.."button[" .. (i % 4 * 2 + 1.25) .. ","
|
|
|
|
.. math.floor(i / 4 + 3) .. ";.75,.5;protector_submit;+]"
|
2015-02-13 20:10:29 +01:00
|
|
|
|
2015-11-13 12:23:30 +01:00
|
|
|
end
|
2015-02-13 20:10:29 +01:00
|
|
|
|
2014-11-09 20:43:01 +01:00
|
|
|
return formspec
|
|
|
|
end
|
|
|
|
|
2017-02-23 11:05:21 +01:00
|
|
|
|
2016-11-02 17:54:19 +01:00
|
|
|
-- check if pos is inside a protected spawn area
|
2017-09-03 11:53:49 +02:00
|
|
|
local inside_spawn = function(pos, radius)
|
2016-11-02 17:54:19 +01:00
|
|
|
|
|
|
|
if protector.spawn <= 0 then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
if pos.x < statspawn.x + radius
|
|
|
|
and pos.x > statspawn.x - radius
|
|
|
|
and pos.y < statspawn.y + radius
|
|
|
|
and pos.y > statspawn.y - radius
|
|
|
|
and pos.z < statspawn.z + radius
|
|
|
|
and pos.z > statspawn.z - radius then
|
|
|
|
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2017-02-23 11:05:21 +01:00
|
|
|
|
2014-11-09 20:43:01 +01:00
|
|
|
-- Infolevel:
|
|
|
|
-- 0 for no info
|
|
|
|
-- 1 for "This area is owned by <owner> !" if you can't dig
|
|
|
|
-- 2 for "This area is owned by <owner>.
|
|
|
|
-- 3 for checking protector overlaps
|
|
|
|
|
2015-07-24 17:21:53 +02:00
|
|
|
protector.can_dig = function(r, pos, digger, onlyowner, infolevel)
|
2014-11-09 20:43:01 +01:00
|
|
|
|
2017-05-06 19:23:18 +02:00
|
|
|
if not digger or not pos then
|
2014-11-09 20:43:01 +01:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2017-05-06 19:23:18 +02:00
|
|
|
-- protector_bypass privileged users can override protection
|
|
|
|
if infolevel == 1
|
|
|
|
and minetest.check_player_privs(digger, {protection_bypass = true}) then
|
2014-11-09 20:43:01 +01:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2016-11-02 17:54:19 +01:00
|
|
|
-- infolevel 3 is only used to bypass priv check, change to 1 now
|
2014-11-09 20:43:01 +01:00
|
|
|
if infolevel == 3 then infolevel = 1 end
|
|
|
|
|
2016-11-02 17:54:19 +01:00
|
|
|
-- is spawn area protected ?
|
|
|
|
if inside_spawn(pos, protector.spawn) then
|
|
|
|
|
|
|
|
minetest.chat_send_player(digger,
|
|
|
|
S("Spawn @1 has been protected up to a @2 block radius.",
|
2017-09-03 11:53:49 +02:00
|
|
|
minetest.pos_to_string(statspawn), protector.spawn))
|
2016-11-02 17:54:19 +01:00
|
|
|
|
|
|
|
return false
|
|
|
|
end
|
2014-11-09 20:43:01 +01:00
|
|
|
|
2016-11-02 17:54:19 +01:00
|
|
|
-- find the protector nodes
|
2016-06-05 13:06:59 +02:00
|
|
|
local pos = minetest.find_nodes_in_area(
|
2015-07-24 17:21:53 +02:00
|
|
|
{x = pos.x - r, y = pos.y - r, z = pos.z - r},
|
|
|
|
{x = pos.x + r, y = pos.y + r, z = pos.z + r},
|
2014-11-09 20:43:01 +01:00
|
|
|
{"protector:protect", "protector:protect2"})
|
|
|
|
|
2015-05-12 18:56:16 +02:00
|
|
|
local meta, owner, members
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2016-06-05 13:06:59 +02:00
|
|
|
for n = 1, #pos do
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2016-06-05 13:06:59 +02:00
|
|
|
meta = minetest.get_meta(pos[n])
|
2016-06-01 14:38:58 +02:00
|
|
|
owner = meta:get_string("owner") or ""
|
|
|
|
members = meta:get_string("members") or ""
|
2014-11-09 20:43:01 +01:00
|
|
|
|
2016-11-02 17:54:19 +01:00
|
|
|
-- node change and digger isn't owner
|
2017-05-06 19:23:18 +02:00
|
|
|
if infolevel == 1 and owner ~= digger then
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2016-11-02 17:54:19 +01:00
|
|
|
-- and you aren't on the member list
|
2017-09-03 11:53:49 +02:00
|
|
|
if onlyowner or not is_member(meta, digger) then
|
2015-10-09 16:13:24 +02:00
|
|
|
|
2016-11-02 17:54:19 +01:00
|
|
|
minetest.chat_send_player(digger,
|
2016-06-07 21:29:06 +02:00
|
|
|
S("This area is owned by @1!", owner))
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2016-11-02 17:54:19 +01:00
|
|
|
return false
|
2014-11-09 20:43:01 +01:00
|
|
|
end
|
|
|
|
end
|
2015-04-11 14:09:00 +02:00
|
|
|
|
2016-11-02 17:54:19 +01:00
|
|
|
-- when using protector as tool, show protector information
|
2015-04-11 14:09:00 +02:00
|
|
|
if infolevel == 2 then
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2017-09-03 11:53:49 +02:00
|
|
|
minetest.chat_send_player(digger, S("This area is owned by @1.", owner))
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2015-07-24 17:21:53 +02:00
|
|
|
minetest.chat_send_player(digger,
|
2017-09-03 11:53:49 +02:00
|
|
|
S("Protection located at: @1", minetest.pos_to_string(pos[n])))
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2015-04-11 14:09:00 +02:00
|
|
|
if members ~= "" then
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2017-09-03 11:53:49 +02:00
|
|
|
minetest.chat_send_player(digger, S("Members: @1.", members))
|
2015-04-11 14:09:00 +02:00
|
|
|
end
|
2015-10-09 16:13:24 +02:00
|
|
|
|
|
|
|
return false
|
2015-04-11 14:09:00 +02:00
|
|
|
end
|
|
|
|
|
2014-11-09 20:43:01 +01:00
|
|
|
end
|
|
|
|
|
2016-11-02 17:54:19 +01:00
|
|
|
-- show when you can build on unprotected area
|
2014-11-09 20:43:01 +01:00
|
|
|
if infolevel == 2 then
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2016-06-05 13:06:59 +02:00
|
|
|
if #pos < 1 then
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2017-09-03 11:53:49 +02:00
|
|
|
minetest.chat_send_player(digger, S("This area is not protected."))
|
2014-11-09 20:43:01 +01:00
|
|
|
end
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2016-06-07 21:29:06 +02:00
|
|
|
minetest.chat_send_player(digger, S("You can build here."))
|
2014-11-09 20:43:01 +01:00
|
|
|
end
|
2015-04-11 14:09:00 +02:00
|
|
|
|
2014-11-09 20:43:01 +01:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2017-09-03 11:53:49 +02:00
|
|
|
local old_is_protected = minetest.is_protected
|
2014-11-09 20:43:01 +01:00
|
|
|
|
2016-11-02 17:54:19 +01:00
|
|
|
-- check for protected area, return true if protected and digger isn't on list
|
2015-07-24 17:21:53 +02:00
|
|
|
function minetest.is_protected(pos, digger)
|
|
|
|
|
2017-05-27 20:27:40 +02:00
|
|
|
digger = digger or "" -- nil check
|
|
|
|
|
2016-11-02 17:54:19 +01:00
|
|
|
-- is area protected against digger?
|
2015-07-24 17:21:53 +02:00
|
|
|
if not protector.can_dig(protector.radius, pos, digger, false, 1) then
|
2015-10-09 16:13:24 +02:00
|
|
|
|
2015-12-23 17:24:20 +01:00
|
|
|
local player = minetest.get_player_by_name(digger)
|
|
|
|
|
2017-02-23 11:05:21 +01:00
|
|
|
if player and player:is_player() then
|
2015-12-23 17:24:20 +01:00
|
|
|
|
2017-02-23 11:05:21 +01:00
|
|
|
-- hurt player if protection violated
|
|
|
|
if protector.hurt > 0 and player:get_hp() > 0 then
|
|
|
|
player:set_hp(player:get_hp() - protector.hurt)
|
|
|
|
end
|
2016-07-20 17:23:12 +02:00
|
|
|
|
2017-02-23 11:05:21 +01:00
|
|
|
-- flip player when protection violated
|
|
|
|
if protector.flip then
|
|
|
|
-- yaw + 180°
|
2017-10-09 16:29:04 +02:00
|
|
|
local yaw = player:get_look_horizontal() + math.pi
|
|
|
|
--local yaw = player:get_look_yaw() + math.pi
|
2016-07-21 10:01:48 +02:00
|
|
|
|
2017-02-23 11:05:21 +01:00
|
|
|
if yaw > 2 * math.pi then
|
|
|
|
yaw = yaw - 2 * math.pi
|
|
|
|
end
|
2016-07-21 10:01:48 +02:00
|
|
|
|
2017-02-23 11:05:21 +01:00
|
|
|
--player:set_look_horizontal(yaw)
|
|
|
|
player:set_look_yaw(yaw)
|
2016-07-21 10:01:48 +02:00
|
|
|
|
2017-02-23 11:05:21 +01:00
|
|
|
-- invert pitch
|
2017-10-09 16:29:04 +02:00
|
|
|
player:set_look_vertical(-player:get_look_vertical())
|
|
|
|
--player:set_look_pitch(-player:get_look_pitch())
|
2016-07-21 10:01:48 +02:00
|
|
|
|
2017-02-23 11:05:21 +01:00
|
|
|
-- if digging below player, move up to avoid falling through hole
|
2017-10-09 16:29:04 +02:00
|
|
|
local pla_pos = player:get_pos()
|
2016-07-20 17:23:12 +02:00
|
|
|
|
2017-02-23 11:05:21 +01:00
|
|
|
if pos.y < pla_pos.y then
|
2016-07-21 10:01:48 +02:00
|
|
|
|
2017-02-23 11:05:21 +01:00
|
|
|
player:setpos({
|
|
|
|
x = pla_pos.x,
|
|
|
|
y = pla_pos.y + 0.8,
|
|
|
|
z = pla_pos.z
|
|
|
|
})
|
|
|
|
end
|
2016-07-20 17:23:12 +02:00
|
|
|
end
|
2015-12-23 17:24:20 +01:00
|
|
|
end
|
2017-06-04 21:24:32 +02:00
|
|
|
|
2014-11-09 20:43:01 +01:00
|
|
|
return true
|
|
|
|
end
|
2015-10-09 16:13:24 +02:00
|
|
|
|
2016-11-02 17:54:19 +01:00
|
|
|
-- otherwise can dig or place
|
2017-09-03 11:53:49 +02:00
|
|
|
return old_is_protected(pos, digger)
|
2014-11-09 20:43:01 +01:00
|
|
|
end
|
|
|
|
|
2017-02-23 11:05:21 +01:00
|
|
|
|
2016-11-02 17:54:19 +01:00
|
|
|
-- make sure protection block doesn't overlap another protector's area
|
2017-09-03 11:53:49 +02:00
|
|
|
local check_overlap = function(itemstack, placer, pointed_thing)
|
2015-07-24 17:21:53 +02:00
|
|
|
|
2015-10-09 16:13:24 +02:00
|
|
|
if pointed_thing.type ~= "node" then
|
|
|
|
return itemstack
|
|
|
|
end
|
2014-11-09 20:43:01 +01:00
|
|
|
|
2016-11-02 17:54:19 +01:00
|
|
|
local pos = pointed_thing.above
|
2017-08-22 19:36:22 +02:00
|
|
|
local name = placer:get_player_name()
|
2016-11-02 17:54:19 +01:00
|
|
|
|
|
|
|
-- make sure protector doesn't overlap onto protected spawn area
|
|
|
|
if inside_spawn(pos, protector.spawn + protector.radius) then
|
|
|
|
|
2017-08-22 19:36:22 +02:00
|
|
|
minetest.chat_send_player(name,
|
2016-11-02 17:54:19 +01:00
|
|
|
S("Spawn @1 has been protected up to a @2 block radius.",
|
|
|
|
minetest.pos_to_string(statspawn), protector.spawn))
|
|
|
|
|
|
|
|
return itemstack
|
|
|
|
end
|
|
|
|
|
|
|
|
-- make sure protector doesn't overlap any other player's area
|
2017-08-22 19:36:22 +02:00
|
|
|
if not protector.can_dig(protector.radius * 2, pos, name, true, 3) then
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2017-08-22 19:36:22 +02:00
|
|
|
minetest.chat_send_player(name,
|
2016-06-07 21:29:06 +02:00
|
|
|
S("Overlaps into above players protected area"))
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2016-11-02 17:54:19 +01:00
|
|
|
return itemstack
|
2014-11-09 20:43:01 +01:00
|
|
|
end
|
|
|
|
|
2015-10-22 11:34:50 +02:00
|
|
|
return minetest.item_place(itemstack, placer, pointed_thing)
|
2014-11-09 20:43:01 +01:00
|
|
|
|
2015-10-09 16:13:24 +02:00
|
|
|
end
|
2014-11-09 20:43:01 +01:00
|
|
|
|
2017-02-23 11:05:21 +01:00
|
|
|
|
2016-11-02 17:54:19 +01:00
|
|
|
-- protection node
|
2014-11-09 20:43:01 +01:00
|
|
|
minetest.register_node("protector:protect", {
|
2017-08-22 16:54:53 +02:00
|
|
|
description = S("Protection Block") .. " (" .. S("USE for area check") .. ")",
|
2015-10-08 11:18:25 +02:00
|
|
|
drawtype = "nodebox",
|
2015-07-24 17:21:53 +02:00
|
|
|
tiles = {
|
|
|
|
"moreblocks_circle_stone_bricks.png",
|
|
|
|
"moreblocks_circle_stone_bricks.png",
|
|
|
|
"moreblocks_circle_stone_bricks.png^protector_logo.png"
|
2014-11-09 20:43:01 +01:00
|
|
|
},
|
2015-07-24 17:21:53 +02:00
|
|
|
sounds = default.node_sound_stone_defaults(),
|
|
|
|
groups = {dig_immediate = 2, unbreakable = 1},
|
2015-10-08 11:18:25 +02:00
|
|
|
is_ground_content = false,
|
2014-11-09 20:43:01 +01:00
|
|
|
paramtype = "light",
|
2015-10-08 11:18:25 +02:00
|
|
|
light_source = 4,
|
|
|
|
|
|
|
|
node_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = {
|
|
|
|
{-0.5 ,-0.5, -0.5, 0.5, 0.5, 0.5},
|
|
|
|
}
|
|
|
|
},
|
2014-11-09 20:43:01 +01:00
|
|
|
|
2017-09-03 11:53:49 +02:00
|
|
|
on_place = check_overlap,
|
2015-10-09 16:13:24 +02:00
|
|
|
|
2014-11-09 20:43:01 +01:00
|
|
|
after_place_node = function(pos, placer)
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2015-03-02 10:03:35 +01:00
|
|
|
local meta = minetest.get_meta(pos)
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2014-11-09 20:43:01 +01:00
|
|
|
meta:set_string("owner", placer:get_player_name() or "")
|
2016-06-07 21:29:06 +02:00
|
|
|
meta:set_string("infotext", S("Protection (owned by @1)", meta:get_string("owner")))
|
2014-11-09 20:43:01 +01:00
|
|
|
meta:set_string("members", "")
|
|
|
|
end,
|
|
|
|
|
|
|
|
on_use = function(itemstack, user, pointed_thing)
|
2015-11-13 12:23:30 +01:00
|
|
|
|
|
|
|
if pointed_thing.type ~= "node" then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2015-07-24 17:21:53 +02:00
|
|
|
protector.can_dig(protector.radius, pointed_thing.under, user:get_player_name(), false, 2)
|
2014-11-09 20:43:01 +01:00
|
|
|
end,
|
|
|
|
|
|
|
|
on_rightclick = function(pos, node, clicker, itemstack)
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2015-03-02 10:03:35 +01:00
|
|
|
local meta = minetest.get_meta(pos)
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2016-02-21 22:11:36 +01:00
|
|
|
if meta
|
2017-08-22 19:36:22 +02:00
|
|
|
and protector.can_dig(1, pos, clicker:get_player_name(), true, 1) then
|
|
|
|
|
|
|
|
minetest.show_formspec(clicker:get_player_name(),
|
|
|
|
"protector:node_" .. minetest.pos_to_string(pos),
|
2017-09-03 11:53:49 +02:00
|
|
|
protector_formspec(meta))
|
2014-11-09 20:43:01 +01:00
|
|
|
end
|
|
|
|
end,
|
|
|
|
|
|
|
|
on_punch = function(pos, node, puncher)
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2016-04-26 16:23:44 +02:00
|
|
|
if minetest.is_protected(pos, puncher:get_player_name()) then
|
2014-11-09 20:43:01 +01:00
|
|
|
return
|
|
|
|
end
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2015-03-02 10:03:35 +01:00
|
|
|
minetest.add_entity(pos, "protector:display")
|
2014-11-09 20:43:01 +01:00
|
|
|
end,
|
2015-05-27 16:57:19 +02:00
|
|
|
|
|
|
|
can_dig = function(pos, player)
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2017-02-22 22:11:48 +01:00
|
|
|
return player and protector.can_dig(1, pos, player:get_player_name(), true, 1)
|
2015-05-27 16:57:19 +02:00
|
|
|
end,
|
2016-01-25 21:41:35 +01:00
|
|
|
|
|
|
|
on_blast = function() end,
|
2014-11-09 20:43:01 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craft({
|
2015-11-13 12:23:30 +01:00
|
|
|
output = "protector:protect",
|
2014-11-09 20:43:01 +01:00
|
|
|
recipe = {
|
2015-07-24 17:21:53 +02:00
|
|
|
{"default:stone", "default:stone", "default:stone"},
|
2017-07-03 14:33:52 +02:00
|
|
|
{"default:stone", "default:gold_ingot", "default:stone"},
|
2015-07-24 17:21:53 +02:00
|
|
|
{"default:stone", "default:stone", "default:stone"},
|
2014-11-09 20:43:01 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2017-02-23 11:05:21 +01:00
|
|
|
|
2016-11-02 17:54:19 +01:00
|
|
|
-- protection logo
|
2014-11-09 20:43:01 +01:00
|
|
|
minetest.register_node("protector:protect2", {
|
2017-08-22 16:54:53 +02:00
|
|
|
description = S("Protection Logo") .. " (" .. S("USE for area check") .. ")",
|
2014-11-09 20:43:01 +01:00
|
|
|
tiles = {"protector_logo.png"},
|
|
|
|
wield_image = "protector_logo.png",
|
|
|
|
inventory_image = "protector_logo.png",
|
|
|
|
sounds = default.node_sound_stone_defaults(),
|
2015-07-24 17:21:53 +02:00
|
|
|
groups = {dig_immediate = 2, unbreakable = 1},
|
2017-08-22 16:54:53 +02:00
|
|
|
paramtype = "light",
|
2014-11-09 20:43:01 +01:00
|
|
|
paramtype2 = "wallmounted",
|
2015-11-23 11:27:17 +01:00
|
|
|
legacy_wallmounted = true,
|
2015-10-08 11:18:25 +02:00
|
|
|
light_source = 4,
|
2014-11-09 20:43:01 +01:00
|
|
|
drawtype = "nodebox",
|
|
|
|
sunlight_propagates = true,
|
|
|
|
walkable = true,
|
|
|
|
node_box = {
|
|
|
|
type = "wallmounted",
|
|
|
|
wall_top = {-0.375, 0.4375, -0.5, 0.375, 0.5, 0.5},
|
|
|
|
wall_bottom = {-0.375, -0.5, -0.5, 0.375, -0.4375, 0.5},
|
|
|
|
wall_side = {-0.5, -0.5, -0.375, -0.4375, 0.5, 0.375},
|
|
|
|
},
|
|
|
|
selection_box = {type = "wallmounted"},
|
|
|
|
|
2017-09-03 11:53:49 +02:00
|
|
|
on_place = check_overlap,
|
2015-10-09 16:13:24 +02:00
|
|
|
|
2014-11-09 20:43:01 +01:00
|
|
|
after_place_node = function(pos, placer)
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2015-03-02 10:03:35 +01:00
|
|
|
local meta = minetest.get_meta(pos)
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2014-11-09 20:43:01 +01:00
|
|
|
meta:set_string("owner", placer:get_player_name() or "")
|
2016-06-07 21:29:06 +02:00
|
|
|
meta:set_string("infotext", S("Protection (owned by @1)", meta:get_string("owner")))
|
2014-11-09 20:43:01 +01:00
|
|
|
meta:set_string("members", "")
|
|
|
|
end,
|
|
|
|
|
|
|
|
on_use = function(itemstack, user, pointed_thing)
|
2015-11-13 12:23:30 +01:00
|
|
|
|
|
|
|
if pointed_thing.type ~= "node" then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2015-07-24 17:21:53 +02:00
|
|
|
protector.can_dig(protector.radius, pointed_thing.under, user:get_player_name(), false, 2)
|
2014-11-09 20:43:01 +01:00
|
|
|
end,
|
|
|
|
|
|
|
|
on_rightclick = function(pos, node, clicker, itemstack)
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2015-03-02 10:03:35 +01:00
|
|
|
local meta = minetest.get_meta(pos)
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2015-07-24 17:21:53 +02:00
|
|
|
if protector.can_dig(1, pos, clicker:get_player_name(), true, 1) then
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2014-11-09 20:43:01 +01:00
|
|
|
minetest.show_formspec(clicker:get_player_name(),
|
2017-09-03 11:53:49 +02:00
|
|
|
"protector:node_" .. minetest.pos_to_string(pos), protector_formspec(meta))
|
2014-11-09 20:43:01 +01:00
|
|
|
end
|
|
|
|
end,
|
|
|
|
|
|
|
|
on_punch = function(pos, node, puncher)
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2016-04-26 16:23:44 +02:00
|
|
|
if minetest.is_protected(pos, puncher:get_player_name()) then
|
2014-11-09 20:43:01 +01:00
|
|
|
return
|
|
|
|
end
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2015-03-02 10:03:35 +01:00
|
|
|
minetest.add_entity(pos, "protector:display")
|
2014-11-09 20:43:01 +01:00
|
|
|
end,
|
2015-05-27 16:57:19 +02:00
|
|
|
|
|
|
|
can_dig = function(pos, player)
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2017-02-22 22:11:48 +01:00
|
|
|
return player and protector.can_dig(1, pos, player:get_player_name(), true, 1)
|
2015-05-27 16:57:19 +02:00
|
|
|
end,
|
2016-01-25 21:41:35 +01:00
|
|
|
|
|
|
|
on_blast = function() end,
|
2014-11-09 20:43:01 +01:00
|
|
|
})
|
2017-08-22 16:54:53 +02:00
|
|
|
|
|
|
|
-- recipes to switch between protectors
|
2014-11-09 20:43:01 +01:00
|
|
|
minetest.register_craft({
|
2017-08-22 16:54:53 +02:00
|
|
|
type = "shapeless",
|
|
|
|
output = "protector:protect",
|
|
|
|
recipe = {"protector:protect2"}
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
type = "shapeless",
|
2015-11-13 12:23:30 +01:00
|
|
|
output = "protector:protect2",
|
2017-08-22 16:54:53 +02:00
|
|
|
recipe = {"protector:protect"}
|
2014-11-09 20:43:01 +01:00
|
|
|
})
|
2017-08-22 16:54:53 +02:00
|
|
|
|
2017-02-23 11:05:21 +01:00
|
|
|
|
2016-11-02 17:54:19 +01:00
|
|
|
-- check formspec buttons or when name entered
|
2015-10-09 16:13:24 +02:00
|
|
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
2015-02-13 20:10:29 +01:00
|
|
|
|
2016-11-02 17:54:19 +01:00
|
|
|
-- protector formspec found
|
2015-07-24 17:21:53 +02:00
|
|
|
if string.sub(formname, 0, string.len("protector:node_")) == "protector:node_" then
|
2015-02-13 20:10:29 +01:00
|
|
|
|
2015-07-24 17:21:53 +02:00
|
|
|
local pos_s = string.sub(formname, string.len("protector:node_") + 1)
|
2014-11-09 20:43:01 +01:00
|
|
|
local pos = minetest.string_to_pos(pos_s)
|
2015-03-02 10:03:35 +01:00
|
|
|
local meta = minetest.get_meta(pos)
|
2014-11-09 20:43:01 +01:00
|
|
|
|
2016-11-02 17:54:19 +01:00
|
|
|
-- only owner can add names
|
2015-07-24 17:21:53 +02:00
|
|
|
if not protector.can_dig(1, pos, player:get_player_name(), true, 1) then
|
2014-11-09 20:43:01 +01:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2016-11-02 17:54:19 +01:00
|
|
|
-- add member [+]
|
2014-11-09 20:43:01 +01:00
|
|
|
if fields.protector_add_member then
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2016-01-09 17:19:08 +01:00
|
|
|
for _, i in pairs(fields.protector_add_member:split(" ")) do
|
2017-09-03 11:53:49 +02:00
|
|
|
add_member(meta, i)
|
2014-11-09 20:43:01 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-02 17:54:19 +01:00
|
|
|
-- remove member [x]
|
2014-11-09 20:43:01 +01:00
|
|
|
for field, value in pairs(fields) do
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2016-11-02 17:54:19 +01:00
|
|
|
if string.sub(field, 0,
|
|
|
|
string.len("protector_del_member_")) == "protector_del_member_" then
|
|
|
|
|
2017-09-03 11:53:49 +02:00
|
|
|
del_member(meta,
|
2016-11-02 17:54:19 +01:00
|
|
|
string.sub(field,string.len("protector_del_member_") + 1))
|
2014-11-09 20:43:01 +01:00
|
|
|
end
|
|
|
|
end
|
2016-11-02 17:54:19 +01:00
|
|
|
|
|
|
|
-- reset formspec until close button pressed
|
2015-02-13 20:10:29 +01:00
|
|
|
if not fields.close_me then
|
2017-09-03 11:53:49 +02:00
|
|
|
minetest.show_formspec(player:get_player_name(), formname, protector_formspec(meta))
|
2014-11-09 20:43:01 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2017-02-23 11:05:21 +01:00
|
|
|
|
2016-11-02 17:54:19 +01:00
|
|
|
-- display entity shown when protector node is punched
|
2014-11-09 20:43:01 +01:00
|
|
|
minetest.register_entity("protector:display", {
|
|
|
|
physical = false,
|
2015-07-24 17:21:53 +02:00
|
|
|
collisionbox = {0, 0, 0, 0, 0, 0},
|
2014-11-09 20:43:01 +01:00
|
|
|
visual = "wielditem",
|
2015-07-24 17:21:53 +02:00
|
|
|
-- wielditem seems to be scaled to 1.5 times original node size
|
|
|
|
visual_size = {x = 1.0 / 1.5, y = 1.0 / 1.5},
|
2014-11-09 20:43:01 +01:00
|
|
|
textures = {"protector:display_node"},
|
2015-10-08 11:18:25 +02:00
|
|
|
timer = 0,
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2014-11-09 20:43:01 +01:00
|
|
|
on_step = function(self, dtime)
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2015-10-08 11:18:25 +02:00
|
|
|
self.timer = self.timer + dtime
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2016-11-02 17:54:19 +01:00
|
|
|
-- remove after 5 seconds
|
2015-10-08 11:18:25 +02:00
|
|
|
if self.timer > 5 then
|
2014-11-09 20:43:01 +01:00
|
|
|
self.object:remove()
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2017-02-23 11:05:21 +01:00
|
|
|
|
2015-07-24 17:21:53 +02:00
|
|
|
-- Display-zone node, Do NOT place the display as a node,
|
|
|
|
-- it is made to be used as an entity (see above)
|
2015-10-09 16:13:24 +02:00
|
|
|
|
2014-11-09 20:43:01 +01:00
|
|
|
local x = protector.radius
|
|
|
|
minetest.register_node("protector:display_node", {
|
|
|
|
tiles = {"protector_display.png"},
|
|
|
|
use_texture_alpha = true,
|
|
|
|
walkable = false,
|
|
|
|
drawtype = "nodebox",
|
|
|
|
node_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = {
|
|
|
|
-- sides
|
|
|
|
{-(x+.55), -(x+.55), -(x+.55), -(x+.45), (x+.55), (x+.55)},
|
|
|
|
{-(x+.55), -(x+.55), (x+.45), (x+.55), (x+.55), (x+.55)},
|
|
|
|
{(x+.45), -(x+.55), -(x+.55), (x+.55), (x+.55), (x+.55)},
|
|
|
|
{-(x+.55), -(x+.55), -(x+.55), (x+.55), (x+.55), -(x+.45)},
|
|
|
|
-- top
|
|
|
|
{-(x+.55), (x+.45), -(x+.55), (x+.55), (x+.55), (x+.55)},
|
|
|
|
-- bottom
|
|
|
|
{-(x+.55), -(x+.55), -(x+.55), (x+.55), -(x+.45), (x+.55)},
|
|
|
|
-- middle (surround protector)
|
|
|
|
{-.55,-.55,-.55, .55,.55,.55},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
selection_box = {
|
|
|
|
type = "regular",
|
|
|
|
},
|
|
|
|
paramtype = "light",
|
2015-07-24 17:21:53 +02:00
|
|
|
groups = {dig_immediate = 3, not_in_creative_inventory = 1},
|
2014-11-09 20:43:01 +01:00
|
|
|
drop = "",
|
|
|
|
})
|
|
|
|
|
2017-02-23 11:05:21 +01:00
|
|
|
|
2016-11-12 11:52:47 +01:00
|
|
|
local path = minetest.get_modpath("protector")
|
|
|
|
|
|
|
|
dofile(path .. "/doors_chest.lua")
|
|
|
|
dofile(path .. "/pvp.lua")
|
|
|
|
dofile(path .. "/admin.lua")
|
2016-11-22 12:12:11 +01:00
|
|
|
dofile(path .. "/tool.lua")
|
2017-11-11 13:50:50 +01:00
|
|
|
dofile(path .. "/hud.lua")
|
2016-11-12 11:52:47 +01:00
|
|
|
dofile(path .. "/lucky_block.lua")
|
2015-08-31 12:23:34 +02:00
|
|
|
|
2017-02-23 11:05:21 +01:00
|
|
|
|
2017-02-01 15:13:20 +01:00
|
|
|
-- stop mesecon pistons from pushing protectors
|
|
|
|
if minetest.get_modpath("mesecons_mvps") then
|
|
|
|
mesecon.register_mvps_stopper("protector:protect")
|
|
|
|
mesecon.register_mvps_stopper("protector:protect2")
|
2017-02-01 15:29:27 +01:00
|
|
|
mesecon.register_mvps_stopper("protector:chest")
|
2017-02-01 15:13:20 +01:00
|
|
|
end
|
|
|
|
|
2017-02-23 11:05:21 +01:00
|
|
|
|
2016-06-07 21:29:06 +02:00
|
|
|
print (S("[MOD] Protector Redo loaded"))
|