Compare commits

...

17 commits

Author SHA1 Message Date
39d43f643a Support multiple factions 2025-08-16 10:54:55 +02:00
tenplus1
958686fcd0 protector tool copies faction checkbox status to new when holding sneak 2025-07-20 07:35:57 +01:00
tenplus1
73bbe5fb95 add chest open/close sound 2025-07-02 11:20:39 +01:00
tenplus1
d294ddbda1 change minetest. to core. 2025-05-04 13:17:16 +01:00
tenplus1
c923871739 fix mcl steel trapdoor drops 2025-03-31 13:38:46 +01:00
tenplus1
81b7818a22 add ukrainian translation (thx Fromkaniv) 2025-03-15 16:43:07 +00:00
tenplus1
c85ed64b37 update translations (thx skybuilder1717) 2025-01-27 15:41:50 +00:00
tenplus1
4b133302dc add commands to add/del member names from local protection. 2025-01-27 08:43:19 +00:00
tenplus1
b800cd2e89 show number of members in protected area in hud 2025-01-27 08:14:21 +00:00
tenplus1
624285c714 tweak door sounds 2025-01-26 11:36:23 +00:00
tenplus1
1edfa9bae3 smaller screenshot 2025-01-26 11:17:23 +00:00
tenplus1
1646e6dc0a use template for protection nodes. 2025-01-26 11:09:56 +00:00
tenplus1
8ab8d841f3 name check for protector_replace/remove commands 2025-01-25 15:45:54 +00:00
tenplus1
e4ea32efa3 store radius and max_shares in global 2025-01-25 15:09:20 +00:00
tenplus1
74fac5ff9a separate chest and doors code 2025-01-25 14:45:20 +00:00
tenplus1
d46cba5061 tidy 2025-01-25 14:33:25 +00:00
tenplus1
add28c4114 fix playerfaction check 2025-01-25 14:03:28 +00:00
20 changed files with 1406 additions and 1193 deletions

View file

@ -62,6 +62,7 @@ Change log:
- 3.2 - Defaults to Minetest translation if found, otherwise intllib fallback if loaded, locale files updated for both. Added 'protector_msg' setting for player text. - 3.2 - Defaults to Minetest translation if found, otherwise intllib fallback if loaded, locale files updated for both. Added 'protector_msg' setting for player text.
- 3.3 - Added support for playerfactions new api (thanks louisroyer), added limiter to protection radius of 22. - 3.3 - Added support for playerfactions new api (thanks louisroyer), added limiter to protection radius of 22.
- 3.4 - Player flip and hurt functions moved to minetest.register_protection_violation function (thanks hlqkj), added 'protector_crafts' setting, changed wood doors n chests to immediate_dig for mineclone2 fix. Upped protector radius limit to 30. - 3.4 - Player flip and hurt functions moved to minetest.register_protection_violation function (thanks hlqkj), added 'protector_crafts' setting, changed wood doors n chests to immediate_dig for mineclone2 fix. Upped protector radius limit to 30.
- 3.5 - Store settings in global, reduce screenshot, tweak door sounds, use node template, add name check to commands, add commands to add and remove member names, tweak & tidy code.
Lucky Blocks: 10 Lucky Blocks: 10
@ -76,7 +77,7 @@ remove specific user names
/protector_remove name1 name2 /protector_remove name1 name2
remove all names from list reset names on remove list
/protector_remove - /protector_remove -
@ -92,19 +93,27 @@ replace owner with new name
/protector_replace owner new_owner /protector_replace owner new_owner
reset name list reset names on replace list
/protector_replace - /protector_replace -
show protected areas of your nearby protectors (max of 5) show protected areas of your nearby protectors (max of 5)
/protector_show_area /protector_show_area
A players own protection blocks can be hidden and shown using the following: A players own protection blocks can be hidden and shown using the following:
/protector_hide /protector_hide
/protector_show /protector_show
Adding members to local protection can be done by using
/protector_add_member
Removing members from local protection can be done by using
/protector_del_member
The following lines can be added to your minetest.conf file to configure specific features of the mod: The following lines can be added to your minetest.conf file to configure specific features of the mod:

122
admin.lua
View file

@ -1,43 +1,38 @@
-- translation and default name vars -- translation and default name vars
local S = minetest.get_translator("protector") local S = core.get_translator("protector")
local removal_names = "" local removal_names = ""
local replace_names = "" local replace_names = ""
-- remove protection command -- remove protection command
minetest.register_chatcommand("protector_remove", { core.register_chatcommand("protector_remove", {
params = S("<names list>"), params = S("<names list>"),
description = S("Remove Protectors around players (separate names with spaces)"), description = S("Remove Protectors around players (separate names with spaces)"),
privs = {server = true}, privs = {server = true},
func = function(name, param) func = function(name, param)
if not param or param == "" then
minetest.chat_send_player(name,
S("Protector Names to remove: @1", removal_names))
return
end
if param == "-" then if param == "-" then
minetest.chat_send_player(name, S("Name List Reset")) core.chat_send_player(name, S("Name List Reset"))
removal_names = "" removal_names = "" ; return
return
end end
if param ~= "" then
removal_names = param removal_names = param
end end
core.chat_send_player(name,
S("Protector Names to remove: @1", removal_names))
end
}) })
-- replace protection command -- replace protection command
minetest.register_chatcommand("protector_replace", { core.register_chatcommand("protector_replace", {
params = S("<owner name> <name to replace with>"), params = S("<owner name> <name to replace with>"),
description = S("Replace Protector Owner with name provided"), description = S("Replace Protector Owner with name provided"),
privs = {server = true}, privs = {server = true},
@ -47,33 +42,43 @@ minetest.register_chatcommand("protector_replace", {
-- reset list to empty -- reset list to empty
if param == "-" then if param == "-" then
minetest.chat_send_player(name, S("Name List Reset")) core.chat_send_player(name, S("Name List Reset"))
replace_names = "" replace_names = "" ; return
return
end end
-- show name info -- check and set replacement name
if param == "" and replace_names ~= "" then if param ~= "" then
local names = replace_names:split(" ") local names = param:split(" ") ; if not names[2] then return end
minetest.chat_send_player(name, S("Replacing Protector name @1 with @2", if names[2] ~= string.match(names[2], "[%w_-]+") then
names[1] or "", names[2] or "")) core.chat_send_player(name, S("Invalid player name!")) ; return
end
return if names[2]:len() > 25 then
core.chat_send_player(name, S("Player name too long")) ; return
end end
replace_names = param replace_names = param
end end
-- show name info
if replace_names ~= "" then
local names = replace_names:split(" ")
core.chat_send_player(name, S("Replacing Protector name @1 with @2",
names[1] or "", names[2] or ""))
end
end
}) })
-- Abm to remove or replace protectors within active player area -- Abm to remove or replace protectors within active player area
minetest.register_abm({ core.register_abm({
nodenames = {"protector:protect", "protector:protect2", "protector:protect_hidden"}, nodenames = {"protector:protect", "protector:protect2", "protector:protect_hidden"},
interval = 6, interval = 5,
chance = 1, chance = 1,
catch_up = false, catch_up = false,
@ -81,10 +86,7 @@ minetest.register_abm({
if removal_names == "" and replace_names == "" then return end if removal_names == "" and replace_names == "" then return end
local meta = minetest.get_meta(pos) local meta = core.get_meta(pos) ; if not meta then return end
if not meta then return end
local owner = meta:get_string("owner") local owner = meta:get_string("owner")
if removal_names ~= "" then if removal_names ~= "" then
@ -92,7 +94,10 @@ minetest.register_abm({
local names = removal_names:split(" ") local names = removal_names:split(" ")
for _, n in pairs(names) do for _, n in pairs(names) do
if n == owner then minetest.set_node(pos, {name = "air"}) end
if n == owner then
core.set_node(pos, {name = "air"}) ; return
end
end end
end end
@ -101,6 +106,7 @@ minetest.register_abm({
local names = replace_names:split(" ") local names = replace_names:split(" ")
if names[1] and names[2] and owner == names[1] then if names[1] and names[2] and owner == names[1] then
meta:set_string("owner", names[2]) meta:set_string("owner", names[2])
meta:set_string("infotext", S("Protection (owned by @1)", names[2])) meta:set_string("infotext", S("Protection (owned by @1)", names[2]))
end end
@ -108,26 +114,22 @@ minetest.register_abm({
end end
}) })
-- get protection radius (max 30)
local r = tonumber(minetest.settings:get("protector_radius")) or 5
if r > 30 then r = 30 end
-- show protection areas of nearby protectors owned by you (thanks agaran) -- show protection areas of nearby protectors owned by you (thanks agaran)
minetest.register_chatcommand("protector_show_area", { local r = protector.radius
core.register_chatcommand("protector_show_area", {
params = "", params = "",
description = S("Show protected areas of your nearby protectors"), description = S("Show protected areas of your nearby protectors"),
privs = {}, privs = {},
func = function(name, param) func = function(name, param)
local player = minetest.get_player_by_name(name) local player = core.get_player_by_name(name)
local pos = player:get_pos() local pos = player:get_pos()
-- find the protector nodes -- find the protector nodes
local pos = minetest.find_nodes_in_area( local pos = core.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},
{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_hidden"}) {"protector:protect", "protector:protect2", "protector:protect_hidden"})
@ -137,12 +139,12 @@ minetest.register_chatcommand("protector_show_area", {
-- show a maximum of 5 protected areas only -- show a maximum of 5 protected areas only
for n = 1, math.min(#pos, 5) do for n = 1, math.min(#pos, 5) do
meta = minetest.get_meta(pos[n]) meta = core.get_meta(pos[n])
owner = meta:get_string("owner") or "" owner = meta:get_string("owner") or ""
if owner == name if owner == name
or minetest.check_player_privs(name, {protection_bypass = true}) then or core.check_player_privs(name, {protection_bypass = true}) then
minetest.add_entity(pos[n], "protector:display") core.add_entity(pos[n], "protector:display")
end end
end end
end end
@ -150,7 +152,7 @@ minetest.register_chatcommand("protector_show_area", {
-- ability to hide protection blocks (borrowed from doors mod :) -- ability to hide protection blocks (borrowed from doors mod :)
minetest.register_node("protector:protect_hidden", { core.register_node("protector:protect_hidden", {
description = "Hidden Protector", description = "Hidden Protector",
drawtype = "airlike", drawtype = "airlike",
paramtype = "light", paramtype = "light",
@ -166,7 +168,7 @@ minetest.register_node("protector:protect_hidden", {
groups = {not_in_creative_inventory = 1, unbreakable = 1}, groups = {not_in_creative_inventory = 1, unbreakable = 1},
is_ground_content = false, is_ground_content = false,
on_blast = function() end, on_blast = function() end,
-- 1px block inside door hinge near node top -- 1px block to stop falling nodes replacing protector
collision_box = { collision_box = {
type = "fixed", fixed = {-15/32, 13/32, -15/32, -13/32, 1/2, -13/32} type = "fixed", fixed = {-15/32, 13/32, -15/32, -13/32, 1/2, -13/32}
} }
@ -174,22 +176,22 @@ minetest.register_node("protector:protect_hidden", {
-- make own protectors visible in area -- make own protectors visible in area
minetest.register_chatcommand("protector_show", { core.register_chatcommand("protector_show", {
params = "", params = "",
description = S("Show your nearby protection blocks"), description = S("Show your nearby protection blocks"),
privs = {interact = true}, privs = {interact = true},
func = function(name, param) func = function(name, param)
local player = minetest.get_player_by_name(name) local player = core.get_player_by_name(name)
if not player then if not player then
return false, "Player not found" return false, S("Player not found.")
end end
local pos = player:get_pos() local pos = player:get_pos()
local a = minetest.find_nodes_in_area( local a = core.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},
{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"}) {"protector:protect_hidden"})
@ -198,12 +200,12 @@ minetest.register_chatcommand("protector_show", {
for _, row in pairs(a) do for _, row in pairs(a) do
meta = minetest.get_meta(row) meta = core.get_meta(row)
owner = meta:get_string("owner") or "" owner = meta:get_string("owner") or ""
if owner == name if owner == name
or minetest.check_player_privs(name, {protection_bypass = true}) then or core.check_player_privs(name, {protection_bypass = true}) then
minetest.swap_node(row, {name = "protector:protect"}) core.swap_node(row, {name = "protector:protect"})
end end
end end
end end
@ -211,22 +213,22 @@ minetest.register_chatcommand("protector_show", {
-- make own protectors invisible in area -- make own protectors invisible in area
minetest.register_chatcommand("protector_hide", { core.register_chatcommand("protector_hide", {
params = "", params = "",
description = S("Hide your nearby protection blocks"), description = S("Hide your nearby protection blocks"),
privs = {interact = true}, privs = {interact = true},
func = function(name, param) func = function(name, param)
local player = minetest.get_player_by_name(name) local player = core.get_player_by_name(name)
if not player then if not player then
return false, "Player not found" return false, S("Player not found.")
end end
local pos = player:get_pos() local pos = player:get_pos()
local a = minetest.find_nodes_in_area( local a = core.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},
{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"})
@ -235,12 +237,12 @@ minetest.register_chatcommand("protector_hide", {
for _, row in pairs(a) do for _, row in pairs(a) do
meta = minetest.get_meta(row) meta = core.get_meta(row)
owner = meta:get_string("owner") or "" owner = meta:get_string("owner") or ""
if owner == name if owner == name
or minetest.check_player_privs(name, {protection_bypass = true}) then or core.check_player_privs(name, {protection_bypass = true}) then
minetest.swap_node(row, {name = "protector:protect_hidden"}) core.swap_node(row, {name = "protector:protect_hidden"})
end end
end end
end end

260
chest.lua Normal file
View file

@ -0,0 +1,260 @@
-- translation
local S = core.get_translator("protector")
local F = core.formspec_escape
-- MineClone support
local mcl = core.get_modpath("mcl_core")
local mcf = core.get_modpath("mcl_formspec")
-- Are crafts enabled?
local protector_crafts = core.settings:get_bool("protector_crafts") ~= false
-- Protected Chest
local chest_size = mcl and (9 * 3) or (8 * 4)
core.register_node("protector:chest", {
description = S("Protected Chest"),
tiles = {
"default_chest_top.png", "default_chest_top.png",
"default_chest_side.png", "default_chest_side.png",
"default_chest_side.png", "default_chest_front.png^protector_logo.png"
},
paramtype2 = "facedir",
groups = {dig_immediate = 2, unbreakable = 1},
legacy_facedir_simple = true,
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
on_construct = function(pos)
local meta = core.get_meta(pos)
local inv = meta:get_inventory()
meta:set_string("infotext", S("Protected Chest"))
meta:set_string("name", S("Protected Chest"))
inv:set_size("main", chest_size)
end,
can_dig = function(pos,player)
local meta = core.get_meta(pos)
local inv = meta:get_inventory()
if inv:is_empty("main") then
if not core.is_protected(pos, player:get_player_name()) then
return true
end
end
end,
on_metadata_inventory_put = function(pos, listname, index, stack, player)
core.log("action", player:get_player_name()
.. " moves stuff to protected chest at " .. core.pos_to_string(pos))
end,
on_metadata_inventory_take = function(pos, listname, index, stack, player)
core.log("action", player:get_player_name()
.. " takes stuff from protected chest at " .. core.pos_to_string(pos))
end,
on_metadata_inventory_move = function(
pos, from_list, from_index, to_list, to_index, count, player)
core.log("action", player:get_player_name()
.. " moves stuff inside protected chest at " .. core.pos_to_string(pos))
end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
if core.is_protected(pos, player:get_player_name()) then
return 0
end
return stack:get_count()
end,
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
if core.is_protected(pos, player:get_player_name()) then
return 0
end
return stack:get_count()
end,
allow_metadata_inventory_move = function(
pos, from_list, from_index, to_list, to_index, count, player)
if core.is_protected(pos, player:get_player_name()) then
return 0
end
return count
end,
on_rightclick = function(pos, node, clicker)
if core.is_protected(pos, clicker:get_player_name()) then return end
local meta = core.get_meta(pos) ; if not meta then return end
local spos = pos.x .. "," .. pos.y .. "," ..pos.z
local formspec
-- mineclone support
if mcl and mcf then
formspec = "size[9,8.75]"
.. "label[0,0;" .. core.formspec_escape(
core.colorize("#313131", "Protected Chest")) .. "]"
.. "list[nodemeta:" .. spos .. ";main;0,0.5;9,3;]"
.. mcl_formspec.get_itemslot_bg(0,0.5,9,3)
.. "image_button[3.0,3.5;1.05,0.8;protector_up_icon.png;protect_up;]"
.. "image_button[4.0,3.5;1.05,0.8;protector_down_icon.png;protect_down;]"
.. "label[0,4.0;" .. core.formspec_escape(
core.colorize("#313131", "Inventory")) .. "]"
.. "list[current_player;main;0,4.5;9,3;9]"
.. mcl_formspec.get_itemslot_bg(0,4.5,9,3)
.. "list[current_player;main;0,7.74;9,1;]"
.. mcl_formspec.get_itemslot_bg(0,7.74,9,1)
.. "listring[nodemeta:" .. spos .. ";main]"
.. "listring[current_player;main]"
else -- default formspec
formspec = "size[8,9]"
.. "list[nodemeta:".. spos .. ";main;0,0.3;8,4;]"
.. "image_button[-0.01,4.26;1.05,0.8;protector_up_icon.png;protect_up;]"
.. "image_button[0.98,4.26;1.05,0.8;protector_down_icon.png;protect_down;]"
.. "tooltip[protect_up;" .. S("To Chest") .. "]"
.. "tooltip[protect_down;" .. S("To Inventory") .. "]"
.. "field[2.3,4.8;4,0.25;protect_name;;"
.. meta:get_string("name") .. "]"
.. "button[5.99,4.5;2.05,0.25;protect_rename;" .. S("Rename") .. "]"
.. "list[current_player;main;0,5;8,1;]"
.. "list[current_player;main;0,6.08;8,3;8]"
.. "listring[nodemeta:" .. spos .. ";main]"
.. "listring[current_player;main]"
end
core.sound_play("default_chest_open", {
gain = 0.3, pos = pos, max_hear_distance = 10}, true)
core.show_formspec(clicker:get_player_name(),
"protector:chest_" .. core.pos_to_string(pos), formspec)
end,
on_blast = function() end
})
-- Container transfer helper
local function to_from(src, dst)
local stack, item, leftover
local size = dst:get_size("main")
for i = 1, size do
stack = src:get_stack("main", i)
item = stack:get_name()
if item ~= "" and dst:room_for_item("main", item) then
leftover = dst:add_item("main", stack)
if leftover and not leftover:is_empty() then
src:set_stack("main", i, leftover)
else
src:set_stack("main", i, nil)
end
end
end
end
-- Protected Chest formspec buttons
core.register_on_player_receive_fields(function(player, formname, fields)
if string.sub(formname, 0, 16) ~= "protector:chest_" then return end
local pos_s = string.sub(formname, 17)
local pos = core.string_to_pos(pos_s)
if core.is_protected(pos, player:get_player_name()) then return end
local meta = core.get_meta(pos) ; if not meta then return end
local chest_inv = meta:get_inventory() ; if not chest_inv then return end
local player_inv = player:get_inventory()
-- copy contents of player inventory to chest
if fields.protect_up then
to_from(player_inv, chest_inv)
-- copy contents of chest to player inventory
elseif fields.protect_down then
to_from(chest_inv, player_inv)
elseif fields.protect_name or fields.protect_rename then
-- change chest infotext to display name
if fields.protect_name ~= "" then
if fields.protect_name ~= string.match(fields.protect_name, "[%w%s_-]+")
or fields.protect_name:len() > 35 then
return
end
meta:set_string("name", fields.protect_name)
meta:set_string("infotext", fields.protect_name)
else
meta:set_string("name", S("Protected Chest"))
meta:set_string("infotext", S("Protected Chest"))
end
elseif fields.quit then
core.sound_play("default_chest_close", {
gain = 0.3, pos = pos, max_hear_distance = 10}, true)
end
end)
-- Protected Chest recipes
if protector_crafts then
if mcl then
core.register_craft({
output = "protector:chest",
recipe = { {"mcl_chests:chest", "mcl_core:gold_ingot"} }
})
else
core.register_craft({
output = "protector:chest",
recipe = {
{"group:wood", "group:wood", "group:wood"},
{"group:wood", "default:copper_ingot", "group:wood"},
{"group:wood", "group:wood", "group:wood"}
}
})
core.register_craft({
output = "protector:chest",
recipe = { {"default:chest", "default:copper_ingot"} }
})
end
end

521
doors.lua Normal file
View file

@ -0,0 +1,521 @@
-- doors code from an old client re-used
local S = core.get_translator("protector")
-- MineClone support
local mcl = core.get_modpath("mcl_core")
-- Are crafts enabled?
local protector_crafts = core.settings:get_bool("protector_crafts") ~= false
-- Registers a door
local function register_door(name, def)
def.groups.not_in_creative_inventory = 1
def.groups.handy = 1
def.groups.prot_door = 1
local box = {{-0.5, -0.5, -0.5, 0.5, 0.5, -0.5 + 1.5/16}}
def.node_box_bottom = box
def.node_box_top = box
def.selection_box_bottom = box
def.selection_box_top = box
core.register_craftitem(name, {
description = def.description,
inventory_image = def.inventory_image,
on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.type ~= "node" then return itemstack end
local ptu = pointed_thing.under
local nu = core.get_node(ptu)
if core.registered_nodes[nu.name]
and core.registered_nodes[nu.name].on_rightclick then
return core.registered_nodes[nu.name].on_rightclick(
ptu, nu, placer, itemstack)
end
local pt = pointed_thing.above
local pt2 = {x = pt.x, y = pt.y, z = pt.z}
pt2.y = pt2.y + 1
if not core.registered_nodes[core.get_node(pt).name].buildable_to
or not core.registered_nodes[core.get_node(pt2).name].buildable_to
or not placer or not placer:is_player() then
return itemstack
end
if core.is_protected(pt, placer:get_player_name())
or core.is_protected(pt2, placer:get_player_name()) then
core.record_protection_violation(pt, placer:get_player_name())
return itemstack
end
local p2 = core.dir_to_facedir(placer:get_look_dir())
local pt3 = {x = pt.x, y = pt.y, z = pt.z}
if p2 == 0 then pt3.x = pt3.x - 1
elseif p2 == 1 then pt3.z = pt3.z + 1
elseif p2 == 2 then pt3.x = pt3.x + 1
elseif p2 == 3 then pt3.z = pt3.z - 1
end
if core.get_item_group(core.get_node(pt3).name, "prot_door") == 0 then
core.set_node(pt, {name = name .. "_b_1", param2 = p2})
core.set_node(pt2, {name = name .. "_t_1", param2 = p2})
else
core.set_node(pt, {name = name .. "_b_2", param2 = p2})
core.set_node(pt2, {name = name .. "_t_2", param2 = p2})
core.get_meta(pt):set_int("right", 1)
core.get_meta(pt2):set_int("right", 1)
end
if not core.settings:get_bool("creative_mode") then
itemstack:take_item()
end
core.sound_play(def.sounds.place, {pos = pt2}, true)
return itemstack
end
})
local tt = def.tiles_top
local tb = def.tiles_bottom
local function after_dig_node(pos, name, digger)
local node = core.get_node(pos)
if node.name == name then
core.node_dig(pos, node, digger)
end
end
local function on_rightclick(pos, dir, check_name, replace, replace_dir, params)
pos.y = pos.y + dir
if core.get_node(pos).name ~= check_name then return end
local p2 = core.get_node(pos).param2
p2 = params[p2 + 1]
core.swap_node(pos, {name = replace_dir, param2 = p2})
pos.y = pos.y - dir
core.swap_node(pos, {name = replace, param2=p2})
core.sound_play(def.open_sound,
{pos = pos, gain = 0.3, max_hear_distance = 10}, true)
end
local function on_rotate(pos, node, dir, user, check_name, mode, new_param2)
if mode ~= screwdriver.ROTATE_FACE then return false end
pos.y = pos.y + dir
if core.get_node(pos).name ~= check_name then return false end
if core.is_protected(pos, user:get_player_name()) then
core.record_protection_violation(pos, user:get_player_name())
return false
end
local node2 = core.get_node(pos)
node2.param2 = (node2.param2 + 1) % 4
core.swap_node(pos, node2)
pos.y = pos.y - dir
node.param2 = (node.param2 + 1) % 4
core.swap_node(pos, node)
return true
end
core.register_node(name .. "_b_1", {
tiles = {tb[2], tb[2], tb[2], tb[2], tb[1], tb[1] .. "^[transformfx"},
paramtype = "light",
paramtype2 = "facedir",
use_texture_alpha = "clip",
is_ground_content = false,
node_dig_prediction = "",
drop = name,
drawtype = "nodebox",
node_box = {type = "fixed", fixed = def.node_box_bottom},
selection_box = {type = "fixed", fixed = def.selection_box_bottom},
groups = def.groups,
_mcl_hardness = 0.8,
_mcl_blast_resistance = 1,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
pos.y = pos.y + 1
after_dig_node(pos, name.."_t_1", digger)
end,
on_rightclick = function(pos, node, clicker)
if not core.is_protected(pos, clicker:get_player_name()) then
on_rightclick(pos, 1, name .. "_t_1", name .. "_b_2",
name .. "_t_2", {1,2,3,0})
end
end,
on_rotate = function(pos, node, user, mode, new_param2)
return on_rotate(pos, node, 1, user, name .. "_t_1", mode)
end,
sounds = def.sounds,
sunlight_propagates = def.sunlight,
on_blast = function() end
})
core.register_node(name .. "_t_1", {
tiles = {tt[2], tt[2], tt[2], tt[2], tt[1], tt[1] .. "^[transformfx"},
paramtype = "light",
paramtype2 = "facedir",
use_texture_alpha = "clip",
is_ground_content = false,
node_dig_prediction = "",
drop = "",
drawtype = "nodebox",
node_box = {type = "fixed", fixed = def.node_box_top},
selection_box = {type = "fixed", fixed = def.selection_box_top},
groups = def.groups,
_mcl_hardness = 0.8,
_mcl_blast_resistance = 1,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
pos.y = pos.y - 1
after_dig_node(pos, name .. "_b_1", digger)
end,
on_rightclick = function(pos, node, clicker)
if not core.is_protected(pos, clicker:get_player_name()) then
on_rightclick(pos, -1, name .. "_b_1", name .. "_t_2",
name .. "_b_2", {1,2,3,0})
end
end,
on_rotate = function(pos, node, user, mode, new_param2)
return on_rotate(pos, node, -1, user, name .. "_b_1", mode)
end,
sounds = def.sounds,
sunlight_propagates = def.sunlight,
on_blast = function() end
})
core.register_node(name .. "_b_2", {
tiles = {tb[2], tb[2], tb[2], tb[2], tb[1] .. "^[transformfx", tb[1]},
paramtype = "light",
paramtype2 = "facedir",
use_texture_alpha = "clip",
is_ground_content = false,
node_dig_prediction = "",
drop = name,
drawtype = "nodebox",
node_box = {type = "fixed", fixed = def.node_box_bottom},
selection_box = {type = "fixed", fixed = def.selection_box_bottom},
groups = def.groups,
_mcl_hardness = 0.8,
_mcl_blast_resistance = 1,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
pos.y = pos.y + 1
after_dig_node(pos, name .. "_t_2", digger)
end,
on_rightclick = function(pos, node, clicker)
if not core.is_protected(pos, clicker:get_player_name()) then
on_rightclick(pos, 1, name .. "_t_2", name .. "_b_1",
name .. "_t_1", {3,0,1,2})
end
end,
on_rotate = function(pos, node, user, mode, new_param2)
return on_rotate(pos, node, 1, user, name .. "_t_2", mode)
end,
sounds = def.sounds,
sunlight_propagates = def.sunlight,
on_blast = function() end
})
core.register_node(name .. "_t_2", {
tiles = {tt[2], tt[2], tt[2], tt[2], tt[1] .. "^[transformfx", tt[1]},
paramtype = "light",
paramtype2 = "facedir",
use_texture_alpha = "clip",
is_ground_content = false,
node_dig_prediction = "",
drop = "",
drawtype = "nodebox",
node_box = {type = "fixed", fixed = def.node_box_top},
selection_box = {type = "fixed", fixed = def.selection_box_top},
groups = def.groups,
_mcl_hardness = 0.8,
_mcl_blast_resistance = 1,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
pos.y = pos.y - 1
after_dig_node(pos, name .. "_b_2", digger)
end,
on_rightclick = function(pos, node, clicker)
if not core.is_protected(pos, clicker:get_player_name()) then
on_rightclick(pos, -1, name .. "_b_2", name .. "_t_1",
name .. "_b_1", {3,0,1,2})
end
end,
on_rotate = function(pos, node, user, mode, new_param2)
return on_rotate(pos, node, -1, user, name .. "_b_2", mode)
end,
sounds = def.sounds,
sunlight_propagates = def.sunlight,
on_blast = function() end
})
end
-- Protected Wooden Door
local name = "protector:door_wood"
register_door(name, {
description = S("Protected Wooden Door"),
inventory_image = "doors_wood.png^protector_logo.png",
groups = {
snappy = 1, choppy = 2, dig_immediate = 2, unbreakable = 1, axey = 1, handy = 1
},
tiles_bottom = {"doors_wood_b.png^protector_logo.png", "doors_brown.png"},
tiles_top = {"doors_wood_a.png", "doors_brown.png"},
sounds = default.node_sound_wood_defaults(),
open_sound = "default_dug_node",
sunlight = false
})
if protector_crafts then
if mcl then
core.register_craft({
output = name,
recipe = { {"mcl_doors:wooden_door", "mcl_core:gold_ingot"} }
})
else
core.register_craft({
output = name,
recipe = {
{"group:wood", "group:wood"},
{"group:wood", "default:copper_ingot"},
{"group:wood", "group:wood"}
}
})
core.register_craft({
output = name,
recipe = { {"doors:door_wood", "default:copper_ingot"} }
})
end
end
-- Protected Steel Door
local name = "protector:door_steel"
register_door(name, {
description = S("Protected Steel Door"),
inventory_image = "doors_steel.png^protector_logo.png",
groups = {
snappy = 1, cracky = 1, handy = 1,
level = (mcl and 0 or 2), pickaxey = 2, unbreakable = 1
},
tiles_bottom = {"doors_steel_b.png^protector_logo.png", "doors_grey.png"},
tiles_top = {"doors_steel_a.png", "doors_grey.png"},
sounds = default.node_sound_metal_defaults(),
open_sound = "default_place_node_metal",
sunlight = false,
})
if protector_crafts then
if mcl then
core.register_craft({
output = name,
recipe = { {"mcl_doors:iron_door", "mcl_core:gold_ingot"} }
})
else
core.register_craft({
output = name,
recipe = {
{"default:steel_ingot", "default:steel_ingot"},
{"default:steel_ingot", "default:copper_ingot"},
{"default:steel_ingot", "default:steel_ingot"}
}
})
core.register_craft({
output = name,
recipe = { {"doors:door_steel", "default:copper_ingot"} }
})
end
end
----trapdoor----
local function register_trapdoor(name, def)
local name_closed = name
local name_opened = name .. "_open"
def.on_rightclick = function (pos, node, clicker, itemstack, pointed_thing)
if core.is_protected(pos, clicker:get_player_name()) then return end
local newname = node.name == name_closed and name_opened or name_closed
core.sound_play(def.open_sound,
{pos = pos, gain = 0.3, max_hear_distance = 10}, true)
core.swap_node(pos,
{name = newname, param1 = node.param1, param2 = node.param2})
end
-- Common trapdoor configuration
def.drawtype = "nodebox"
def.paramtype = "light"
def.paramtype2 = "facedir"
def.use_texture_alpha = "clip"
def.is_ground_content = false
def.node_dig_prediction = ""
local def_opened = table.copy(def)
local def_closed = table.copy(def)
def_closed.node_box = {
type = "fixed", fixed = {-0.5, -0.5, -0.5, 0.5, -6/16, 0.5}
}
def_closed.selection_box = {
type = "fixed", fixed = {-0.5, -0.5, -0.5, 0.5, -6/16, 0.5}
}
def_closed.tiles = { def.tile_front, def.tile_front, def.tile_side, def.tile_side,
def.tile_side, def.tile_side }
def_opened.node_box = {
type = "fixed", fixed = {-0.5, -0.5, 6/16, 0.5, 0.5, 0.5}
}
def_opened.selection_box = {
type = "fixed", fixed = {-0.5, -0.5, 6/16, 0.5, 0.5, 0.5}
}
def_opened.tiles = { def.tile_side, def.tile_side,
def.tile_side .. "^[transform3",
def.tile_side .. "^[transform1",
def.tile_front, def.tile_front }
def_opened.drop = name_closed
def_opened.groups.not_in_creative_inventory = 1
core.register_node(name_opened, def_opened)
core.register_node(name_closed, def_closed)
end
-- Protected Wooden Trapdoor
register_trapdoor("protector:trapdoor", {
description = S("Protected Trapdoor"),
inventory_image = "doors_trapdoor.png^protector_logo.png",
wield_image = "doors_trapdoor.png^protector_logo.png",
tile_front = "doors_trapdoor.png^protector_logo.png",
tile_side = "doors_trapdoor_side.png",
groups = {snappy = 1, choppy = 2, dig_immediate = 2, unbreakable = 1, axey = 1},
_mcl_hardness = 0.8,
_mcl_blast_resistance = 1,
sounds = default.node_sound_wood_defaults(),
open_sound = "default_dug_node"
})
if protector_crafts then
if mcl then
core.register_craft({
output = "protector:trapdoor",
recipe = { {"mcl_doors:trapdoor", "mcl_core:gold_ingot"} }
})
else
core.register_craft({
output = "protector:trapdoor 2",
recipe = {
{"group:wood", "default:copper_ingot", "group:wood"},
{"group:wood", "group:wood", "group:wood"}
}
})
core.register_craft({
output = "protector:trapdoor",
recipe = { {"doors:trapdoor", "default:copper_ingot"} }
})
end
end
-- Protected Steel Trapdoor
register_trapdoor("protector:trapdoor_steel", {
description = S("Protected Steel Trapdoor"),
inventory_image = "doors_trapdoor_steel.png^protector_logo.png",
wield_image = "doors_trapdoor_steel.png^protector_logo.png",
tile_front = "doors_trapdoor_steel.png^protector_logo.png",
tile_side = "doors_trapdoor_steel_side.png",
groups = {
snappy = 1, bendy = 2, cracky = 1, level = (mcl and 0 or 2),
unbreakable = 1, pickaxey = 2, handy = 1
},
_mcl_hardness = 1,
_mcl_blast_resistance = 1,
sounds = default.node_sound_metal_defaults(),
open_sound = "default_place_node_metal"
})
if protector_crafts then
if mcl then
core.register_craft({
output = "protector:trapdoor_steel",
recipe = { {"mcl_doors:iron_trapdoor", "mcl_core:gold_ingot"} }
})
else
core.register_craft({
output = "protector:trapdoor_steel",
recipe = {
{"default:copper_ingot", "default:steel_ingot"},
{"default:steel_ingot", "default:steel_ingot"}
}
})
core.register_craft({
output = "protector:trapdoor_steel",
recipe = { {"doors:trapdoor_steel", "default:copper_ingot"} }
})
end
end

View file

@ -1,757 +0,0 @@
-- doors code from an old client re-used
local S = minetest.get_translator("protector")
local F = minetest.formspec_escape
-- MineClone support
local mcl = minetest.get_modpath("mcl_core")
local mcf = minetest.get_modpath("mcl_formspec")
-- Are crafts enabled?
local protector_crafts = minetest.settings:get_bool("protector_crafts") ~= false
-- Registers a door
local function register_door(name, def)
def.groups.not_in_creative_inventory = 1
def.groups.handy = 1
def.groups.prot_door = 1
local box = {{-0.5, -0.5, -0.5, 0.5, 0.5, -0.5 + 1.5/16}}
def.node_box_bottom = box
def.node_box_top = box
def.selection_box_bottom = box
def.selection_box_top = box
minetest.register_craftitem(name, {
description = def.description,
inventory_image = def.inventory_image,
on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.type ~= "node" then
return itemstack
end
local ptu = pointed_thing.under
local nu = minetest.get_node(ptu)
if minetest.registered_nodes[nu.name]
and minetest.registered_nodes[nu.name].on_rightclick then
return minetest.registered_nodes[nu.name].on_rightclick(ptu, nu, placer, itemstack)
end
local pt = pointed_thing.above
local pt2 = {x = pt.x, y = pt.y, z = pt.z}
pt2.y = pt2.y + 1
if not minetest.registered_nodes[minetest.get_node(pt).name].buildable_to
or not minetest.registered_nodes[minetest.get_node(pt2).name].buildable_to
or not placer or not placer:is_player() then
return itemstack
end
if minetest.is_protected(pt, placer:get_player_name())
or minetest.is_protected(pt2, placer:get_player_name()) then
minetest.record_protection_violation(pt, placer:get_player_name())
return itemstack
end
local p2 = minetest.dir_to_facedir(placer:get_look_dir())
local pt3 = {x = pt.x, y = pt.y, z = pt.z}
if p2 == 0 then
pt3.x = pt3.x - 1
elseif p2 == 1 then
pt3.z = pt3.z + 1
elseif p2 == 2 then
pt3.x = pt3.x + 1
elseif p2 == 3 then
pt3.z = pt3.z - 1
end
if minetest.get_item_group(minetest.get_node(pt3).name, "prot_door") == 0 then
minetest.set_node(pt, {name = name .. "_b_1", param2 = p2})
minetest.set_node(pt2, {name = name .. "_t_1", param2 = p2})
else
minetest.set_node(pt, {name = name .. "_b_2", param2 = p2})
minetest.set_node(pt2, {name = name .. "_t_2", param2 = p2})
minetest.get_meta(pt):set_int("right", 1)
minetest.get_meta(pt2):set_int("right", 1)
end
if not minetest.settings:get_bool("creative_mode") then
itemstack:take_item()
end
minetest.sound_play(def.sounds.place, {pos = pt2}, true)
return itemstack
end
})
local tt = def.tiles_top
local tb = def.tiles_bottom
local function after_dig_node(pos, name, digger)
local node = minetest.get_node(pos)
if node.name == name then
minetest.node_dig(pos, node, digger)
end
end
local function on_rightclick(pos, dir, check_name, replace, replace_dir, params)
pos.y = pos.y + dir
if minetest.get_node(pos).name ~= check_name then return end
local p2 = minetest.get_node(pos).param2
p2 = params[p2 + 1]
minetest.swap_node(pos, {name = replace_dir, param2 = p2})
pos.y = pos.y - dir
minetest.swap_node(pos, {name = replace, param2=p2})
minetest.sound_play("default_dug_node",
{pos = pos, gain = 0.3, max_hear_distance = 10}, true)
end
local function on_rotate(pos, node, dir, user, check_name, mode, new_param2)
if mode ~= screwdriver.ROTATE_FACE then return false end
pos.y = pos.y + dir
if minetest.get_node(pos).name ~= check_name then return false end
if minetest.is_protected(pos, user:get_player_name()) then
minetest.record_protection_violation(pos, user:get_player_name())
return false
end
local node2 = minetest.get_node(pos)
node2.param2 = (node2.param2 + 1) % 4
minetest.swap_node(pos, node2)
pos.y = pos.y - dir
node.param2 = (node.param2 + 1) % 4
minetest.swap_node(pos, node)
return true
end
minetest.register_node(name .. "_b_1", {
tiles = {tb[2], tb[2], tb[2], tb[2], tb[1], tb[1] .. "^[transformfx"},
paramtype = "light",
paramtype2 = "facedir",
use_texture_alpha = "clip",
is_ground_content = false,
node_dig_prediction = "",
drop = name,
drawtype = "nodebox",
node_box = { type = "fixed", fixed = def.node_box_bottom },
selection_box = { type = "fixed", fixed = def.selection_box_bottom },
groups = def.groups,
_mcl_hardness = 0.8,
_mcl_blast_resistance = 1,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
pos.y = pos.y + 1
after_dig_node(pos, name.."_t_1", digger)
end,
on_rightclick = function(pos, node, clicker)
if not minetest.is_protected(pos, clicker:get_player_name()) then
on_rightclick(pos, 1, name .. "_t_1", name .. "_b_2", name .. "_t_2", {1,2,3,0})
end
end,
on_rotate = function(pos, node, user, mode, new_param2)
return on_rotate(pos, node, 1, user, name .. "_t_1", mode)
end,
sounds = def.sounds,
sunlight_propagates = def.sunlight,
on_blast = function() end
})
minetest.register_node(name .. "_t_1", {
tiles = {tt[2], tt[2], tt[2], tt[2], tt[1], tt[1] .. "^[transformfx"},
paramtype = "light",
paramtype2 = "facedir",
use_texture_alpha = "clip",
is_ground_content = false,
node_dig_prediction = "",
drop = "",
drawtype = "nodebox",
node_box = { type = "fixed", fixed = def.node_box_top },
selection_box = { type = "fixed", fixed = def.selection_box_top },
groups = def.groups,
_mcl_hardness = 0.8,
_mcl_blast_resistance = 1,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
pos.y = pos.y - 1
after_dig_node(pos, name .. "_b_1", digger)
end,
on_rightclick = function(pos, node, clicker)
if not minetest.is_protected(pos, clicker:get_player_name()) then
on_rightclick(pos, -1, name .. "_b_1", name .. "_t_2", name .. "_b_2", {1,2,3,0})
end
end,
on_rotate = function(pos, node, user, mode, new_param2)
return on_rotate(pos, node, -1, user, name .. "_b_1", mode)
end,
sounds = def.sounds,
sunlight_propagates = def.sunlight,
on_blast = function() end
})
minetest.register_node(name .. "_b_2", {
tiles = {tb[2], tb[2], tb[2], tb[2], tb[1] .. "^[transformfx", tb[1]},
paramtype = "light",
paramtype2 = "facedir",
use_texture_alpha = "clip",
is_ground_content = false,
node_dig_prediction = "",
drop = name,
drawtype = "nodebox",
node_box = { type = "fixed", fixed = def.node_box_bottom },
selection_box = { type = "fixed", fixed = def.selection_box_bottom },
groups = def.groups,
_mcl_hardness = 0.8,
_mcl_blast_resistance = 1,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
pos.y = pos.y + 1
after_dig_node(pos, name .. "_t_2", digger)
end,
on_rightclick = function(pos, node, clicker)
if not minetest.is_protected(pos, clicker:get_player_name()) then
on_rightclick(pos, 1, name .. "_t_2", name .. "_b_1", name .. "_t_1", {3,0,1,2})
end
end,
on_rotate = function(pos, node, user, mode, new_param2)
return on_rotate(pos, node, 1, user, name .. "_t_2", mode)
end,
sounds = def.sounds,
sunlight_propagates = def.sunlight,
on_blast = function() end
})
minetest.register_node(name .. "_t_2", {
tiles = {tt[2], tt[2], tt[2], tt[2], tt[1] .. "^[transformfx", tt[1]},
paramtype = "light",
paramtype2 = "facedir",
use_texture_alpha = "clip",
is_ground_content = false,
node_dig_prediction = "",
drop = "",
drawtype = "nodebox",
node_box = { type = "fixed", fixed = def.node_box_top },
selection_box = { type = "fixed", fixed = def.selection_box_top },
groups = def.groups,
_mcl_hardness = 0.8,
_mcl_blast_resistance = 1,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
pos.y = pos.y - 1
after_dig_node(pos, name .. "_b_2", digger)
end,
on_rightclick = function(pos, node, clicker)
if not minetest.is_protected(pos, clicker:get_player_name()) then
on_rightclick(pos, -1, name .. "_b_2", name .. "_t_1", name .. "_b_1", {3,0,1,2})
end
end,
on_rotate = function(pos, node, user, mode, new_param2)
return on_rotate(pos, node, -1, user, name .. "_b_2", mode)
end,
sounds = def.sounds,
sunlight_propagates = def.sunlight,
on_blast = function() end
})
end
-- Protected Wooden Door
local name = "protector:door_wood"
register_door(name, {
description = S("Protected Wooden Door"),
inventory_image = "doors_wood.png^protector_logo.png",
groups = {snappy = 1, choppy = 2, dig_immediate = 2, unbreakable = 1, axey = 1},
tiles_bottom = {"doors_wood_b.png^protector_logo.png", "doors_brown.png"},
tiles_top = {"doors_wood_a.png", "doors_brown.png"},
sounds = default.node_sound_wood_defaults(),
sunlight = false
})
if protector_crafts then
if mcl then
minetest.register_craft({
output = name,
recipe = { {"mcl_doors:wooden_door", "mcl_core:gold_ingot"} }
})
else
minetest.register_craft({
output = name,
recipe = {
{"group:wood", "group:wood"},
{"group:wood", "default:copper_ingot"},
{"group:wood", "group:wood"}
}
})
minetest.register_craft({
output = name,
recipe = { {"doors:door_wood", "default:copper_ingot"} }
})
end
end
-- Protected Steel Door
local name = "protector:door_steel"
register_door(name, {
description = S("Protected Steel Door"),
inventory_image = "doors_steel.png^protector_logo.png",
groups = {
snappy = 1, bendy = 2, cracky = 1,
level = (mcl and 0 or 2), pickaxey = 2, unbreakable = 1
},
tiles_bottom = {"doors_steel_b.png^protector_logo.png", "doors_grey.png"},
tiles_top = {"doors_steel_a.png", "doors_grey.png"},
sounds = default.node_sound_metal_defaults(),
sunlight = false,
})
if protector_crafts then
if mcl then
minetest.register_craft({
output = name,
recipe = { {"mcl_doors:iron_door", "mcl_core:gold_ingot"} }
})
else
minetest.register_craft({
output = name,
recipe = {
{"default:steel_ingot", "default:steel_ingot"},
{"default:steel_ingot", "default:copper_ingot"},
{"default:steel_ingot", "default:steel_ingot"}
}
})
minetest.register_craft({
output = name,
recipe = { {"doors:door_steel", "default:copper_ingot"} }
})
end
end
----trapdoor----
local function register_trapdoor(name, def)
local name_closed = name
local name_opened = name .. "_open"
def.on_rightclick = function (pos, node, clicker, itemstack, pointed_thing)
if minetest.is_protected(pos, clicker:get_player_name()) then return end
local newname = node.name == name_closed and name_opened or name_closed
minetest.sound_play("default_dug_node",
{pos = pos, gain = 0.3, max_hear_distance = 10}, true)
minetest.swap_node(pos,
{name = newname, param1 = node.param1, param2 = node.param2})
end
-- Common trapdoor configuration
def.drawtype = "nodebox"
def.paramtype = "light"
def.paramtype2 = "facedir"
def.use_texture_alpha = "clip"
def.is_ground_content = false
def.node_dig_prediction = ""
local def_opened = table.copy(def)
local def_closed = table.copy(def)
def_closed.node_box = {
type = "fixed", fixed = {-0.5, -0.5, -0.5, 0.5, -6/16, 0.5}
}
def_closed.selection_box = {
type = "fixed", fixed = {-0.5, -0.5, -0.5, 0.5, -6/16, 0.5}
}
def_closed.tiles = { def.tile_front, def.tile_front, def.tile_side, def.tile_side,
def.tile_side, def.tile_side }
def_opened.node_box = {
type = "fixed", fixed = {-0.5, -0.5, 6/16, 0.5, 0.5, 0.5}
}
def_opened.selection_box = {
type = "fixed", fixed = {-0.5, -0.5, 6/16, 0.5, 0.5, 0.5}
}
def_opened.tiles = { def.tile_side, def.tile_side,
def.tile_side .. "^[transform3",
def.tile_side .. "^[transform1",
def.tile_front, def.tile_front }
def_opened.drop = name_closed
def_opened.groups.not_in_creative_inventory = 1
minetest.register_node(name_opened, def_opened)
minetest.register_node(name_closed, def_closed)
end
-- Protected Wooden Trapdoor
register_trapdoor("protector:trapdoor", {
description = S("Protected Trapdoor"),
inventory_image = "doors_trapdoor.png^protector_logo.png",
wield_image = "doors_trapdoor.png^protector_logo.png",
tile_front = "doors_trapdoor.png^protector_logo.png",
tile_side = "doors_trapdoor_side.png",
groups = {snappy = 1, choppy = 2, dig_immediate = 2, unbreakable = 1, axey = 1},
_mcl_hardness = 0.8,
_mcl_blast_resistance = 1,
sounds = default.node_sound_wood_defaults(),
})
if protector_crafts then
if mcl then
minetest.register_craft({
output = "protector:trapdoor",
recipe = { {"mcl_doors:trapdoor", "mcl_core:gold_ingot"} }
})
else
minetest.register_craft({
output = "protector:trapdoor 2",
recipe = {
{"group:wood", "default:copper_ingot", "group:wood"},
{"group:wood", "group:wood", "group:wood"}
}
})
minetest.register_craft({
output = "protector:trapdoor",
recipe = { {"doors:trapdoor", "default:copper_ingot"} }
})
end
end
-- Protected Steel Trapdoor
register_trapdoor("protector:trapdoor_steel", {
description = S("Protected Steel Trapdoor"),
inventory_image = "doors_trapdoor_steel.png^protector_logo.png",
wield_image = "doors_trapdoor_steel.png^protector_logo.png",
tile_front = "doors_trapdoor_steel.png^protector_logo.png",
tile_side = "doors_trapdoor_steel_side.png",
groups = {
snappy = 1, bendy = 2, cracky = 1, melty = 2, level = (mcl and 0 or 2),
unbreakable = 1, pickaxey = 2
},
_mcl_hardness = 1,
_mcl_blast_resistance = 1,
sounds = default.node_sound_metal_defaults()
})
if protector_crafts then
if mcl then
minetest.register_craft({
output = "protector:trapdoor_steel",
recipe = { {"mcl_doors:iron_trapdoor", "mcl_core:gold_ingot"} }
})
else
minetest.register_craft({
output = "protector:trapdoor_steel",
recipe = {
{"default:copper_ingot", "default:steel_ingot"},
{"default:steel_ingot", "default:steel_ingot"}
}
})
minetest.register_craft({
output = "protector:trapdoor_steel",
recipe = { {"doors:trapdoor_steel", "default:copper_ingot"} }
})
end
end
-- Protected Chest
local chest_size = mcl and (9 * 3) or (8 * 4)
minetest.register_node("protector:chest", {
description = S("Protected Chest"),
tiles = {
"default_chest_top.png", "default_chest_top.png",
"default_chest_side.png", "default_chest_side.png",
"default_chest_side.png", "default_chest_front.png^protector_logo.png"
},
paramtype2 = "facedir",
groups = {dig_immediate = 2, unbreakable = 1},
legacy_facedir_simple = true,
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
on_construct = function(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
meta:set_string("infotext", S("Protected Chest"))
meta:set_string("name", S("Protected Chest"))
inv:set_size("main", chest_size)
end,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
if inv:is_empty("main") then
if not minetest.is_protected(pos, player:get_player_name()) then
return true
end
end
end,
on_metadata_inventory_put = function(pos, listname, index, stack, player)
minetest.log("action", player:get_player_name()
.. " moves stuff to protected chest at " .. minetest.pos_to_string(pos))
end,
on_metadata_inventory_take = function(pos, listname, index, stack, player)
minetest.log("action", player:get_player_name()
.. " takes stuff from protected chest at " .. minetest.pos_to_string(pos))
end,
on_metadata_inventory_move = function(
pos, from_list, from_index, to_list, to_index, count, player)
minetest.log("action", player:get_player_name()
.. " moves stuff inside protected chest at " .. minetest.pos_to_string(pos))
end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
if minetest.is_protected(pos, player:get_player_name()) then
return 0
end
return stack:get_count()
end,
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
if minetest.is_protected(pos, player:get_player_name()) then
return 0
end
return stack:get_count()
end,
allow_metadata_inventory_move = function(
pos, from_list, from_index, to_list, to_index, count, player)
if minetest.is_protected(pos, player:get_player_name()) then
return 0
end
return count
end,
on_rightclick = function(pos, node, clicker)
if minetest.is_protected(pos, clicker:get_player_name()) then return end
local meta = minetest.get_meta(pos) ; if not meta then return end
local spos = pos.x .. "," .. pos.y .. "," ..pos.z
local formspec
-- mineclone support
if mcl and mcf then
formspec = "size[9,8.75]"
.. "label[0,0;" .. minetest.formspec_escape(
minetest.colorize("#313131", "Protected Chest")) .. "]"
.. "list[nodemeta:" .. spos .. ";main;0,0.5;9,3;]"
.. mcl_formspec.get_itemslot_bg(0,0.5,9,3)
.. "image_button[3.0,3.5;1.05,0.8;protector_up_icon.png;protect_up;]"
.. "image_button[4.0,3.5;1.05,0.8;protector_down_icon.png;protect_down;]"
.. "label[0,4.0;" .. minetest.formspec_escape(
minetest.colorize("#313131", "Inventory")) .. "]"
.. "list[current_player;main;0,4.5;9,3;9]"
.. mcl_formspec.get_itemslot_bg(0,4.5,9,3)
.. "list[current_player;main;0,7.74;9,1;]"
.. mcl_formspec.get_itemslot_bg(0,7.74,9,1)
.. "listring[nodemeta:" .. spos .. ";main]"
.. "listring[current_player;main]"
else -- default formspec
formspec = "size[8,9]"
.. "list[nodemeta:".. spos .. ";main;0,0.3;8,4;]"
.. "image_button[-0.01,4.26;1.05,0.8;protector_up_icon.png;protect_up;]"
.. "image_button[0.98,4.26;1.05,0.8;protector_down_icon.png;protect_down;]"
.. "tooltip[protect_up;" .. S("To Chest") .. "]"
.. "tooltip[protect_down;" .. S("To Inventory") .. "]"
.. "field[2.3,4.8;4,0.25;protect_name;;"
.. meta:get_string("name") .. "]"
.. "button[5.99,4.5;2.05,0.25;protect_rename;" .. S("Rename") .. "]"
.. "list[current_player;main;0,5;8,1;]"
.. "list[current_player;main;0,6.08;8,3;8]"
.. "listring[nodemeta:" .. spos .. ";main]"
.. "listring[current_player;main]"
end
minetest.show_formspec(clicker:get_player_name(),
"protector:chest_" .. minetest.pos_to_string(pos), formspec)
end,
on_blast = function() end
})
-- Container transfer helper
local function to_from(src, dst)
local stack, item, leftover
local size = dst:get_size("main")
for i = 1, size do
stack = src:get_stack("main", i)
item = stack:get_name()
if item ~= "" and dst:room_for_item("main", item) then
leftover = dst:add_item("main", stack)
if leftover and not leftover:is_empty() then
src:set_stack("main", i, leftover)
else
src:set_stack("main", i, nil)
end
end
end
end
-- Protected Chest formspec buttons
minetest.register_on_player_receive_fields(function(player, formname, fields)
if string.sub(formname, 0, 16) ~= "protector:chest_" then return end
local pos_s = string.sub(formname, 17)
local pos = minetest.string_to_pos(pos_s)
if minetest.is_protected(pos, player:get_player_name()) then return end
local meta = minetest.get_meta(pos) ; if not meta then return end
local chest_inv = meta:get_inventory() ; if not chest_inv then return end
local player_inv = player:get_inventory()
-- copy contents of player inventory to chest
if fields.protect_up then
to_from(player_inv, chest_inv)
-- copy contents of chest to player inventory
elseif fields.protect_down then
to_from(chest_inv, player_inv)
elseif fields.protect_name or fields.protect_rename then
-- change chest infotext to display name
if fields.protect_name ~= "" then
if fields.protect_name ~= string.match(fields.protect_name, "[%w%s_-]+")
or fields.protect_name:len() > 35 then
return
end
meta:set_string("name", fields.protect_name)
meta:set_string("infotext", fields.protect_name)
else
meta:set_string("name", S("Protected Chest"))
meta:set_string("infotext", S("Protected Chest"))
end
end
end)
-- Protected Chest recipes
if protector_crafts then
if mcl then
minetest.register_craft({
output = "protector:chest",
recipe = { {"mcl_chests:chest", "mcl_core:gold_ingot"} }
})
else
minetest.register_craft({
output = "protector:chest",
recipe = {
{"group:wood", "group:wood", "group:wood"},
{"group:wood", "default:copper_ingot", "group:wood"},
{"group:wood", "group:wood", "group:wood"}
}
})
minetest.register_craft({
output = "protector:chest",
recipe = { {"default:chest", "default:copper_ingot"} }
})
end
end

30
hud.lua
View file

@ -1,36 +1,33 @@
-- translation and protector radius -- translation and protector radius
local S = minetest.get_translator("protector") local S = core.get_translator("protector")
local radius = (tonumber(minetest.settings:get("protector_radius")) or 5) local radius = protector.radius
-- radius limiter (minetest cannot handle node volume of more than 4096000)
if radius > 30 then radius = 30 end
-- hud settings -- hud settings
local hud = {} local hud = {}
local hud_timer = 0 local hud_timer = 0
local hud_interval = (tonumber(minetest.settings:get("protector_hud_interval")) or 5) local hud_interval = (tonumber(core.settings:get("protector_hud_interval")) or 4)
local hud_style = minetest.has_feature("hud_def_type_field") local hud_style = core.has_feature("hud_def_type_field")
if hud_interval > 0 then if hud_interval > 0 then
minetest.register_globalstep(function(dtime) core.register_globalstep(function(dtime)
-- every 5 seconds
hud_timer = hud_timer + dtime hud_timer = hud_timer + dtime
if hud_timer < hud_interval then return end if hud_timer < hud_interval then return end
hud_timer = 0 hud_timer = 0
for _, player in pairs(minetest.get_connected_players()) do for _, player in pairs(core.get_connected_players()) do
local name = player:get_player_name() local name = player:get_player_name()
local pos = vector.round(player:get_pos()) local pos = vector.round(player:get_pos())
local hud_text = "" local hud_text = ""
local protectors = minetest.find_nodes_in_area( local protectors = core.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},
{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_hidden"}) {"protector:protect","protector:protect2", "protector:protect_hidden"})
@ -38,10 +35,15 @@ minetest.register_globalstep(function(dtime)
if #protectors > 0 then if #protectors > 0 then
local npos = protectors[1] local npos = protectors[1]
local meta = minetest.get_meta(npos) local meta = core.get_meta(npos)
local nodeowner = meta:get_string("owner") local nodeowner = meta:get_string("owner")
local members = meta:get_string("members"):split(" ")
hud_text = S("Owner: @1", nodeowner) hud_text = S("Owner: @1", nodeowner)
if #members > 0 then
hud_text = hud_text .. " [" .. #members .. "]"
end
end end
if not hud[name] then if not hud[name] then
@ -73,7 +75,7 @@ minetest.register_globalstep(function(dtime)
end end
end) end)
minetest.register_on_leaveplayer(function(player) core.register_on_leaveplayer(function(player)
hud[player:get_player_name()] = nil hud[player:get_player_name()] = nil
end) end)

514
init.lua
View file

@ -1,7 +1,7 @@
-- default support (for use with MineClone2 and other [games] -- default support (for use with MineClone2 and other [games]
if not minetest.global_exists("default") then if not core.global_exists("default") then
default = { default = {
node_sound_stone_defaults = function(table) return {} end, node_sound_stone_defaults = function(table) return {} end,
@ -11,7 +11,7 @@ if not minetest.global_exists("default") then
} }
end end
if minetest.get_modpath("mcl_sounds") then if core.get_modpath("mcl_sounds") then
default.node_sound_stone_defaults = mcl_sounds.node_sound_stone_defaults default.node_sound_stone_defaults = mcl_sounds.node_sound_stone_defaults
default.node_sound_wood_defaults = mcl_sounds.node_sound_wood_defaults default.node_sound_wood_defaults = mcl_sounds.node_sound_wood_defaults
default.node_sound_metal_defaults = mcl_sounds.node_sound_metal_defaults default.node_sound_metal_defaults = mcl_sounds.node_sound_metal_defaults
@ -19,34 +19,45 @@ end
-- modpath, formspec helper and translator -- modpath, formspec helper and translator
local MP = minetest.get_modpath(minetest.get_current_modname()) local MP = core.get_modpath(core.get_current_modname())
local F = minetest.formspec_escape local F = core.formspec_escape
local S = minetest.get_translator("protector") local S = core.get_translator("protector")
-- global table -- global table
protector = { mod = "redo", modpath = MP } protector = {
mod = "redo",
-- settings max_shares = 12,
radius = tonumber(core.settings:get("protector_radius")) or 5
local factions_available = minetest.global_exists("factions") }
local protector_max_share_count = 12
local protector_radius = tonumber(minetest.settings:get("protector_radius")) or 5
local protector_flip = minetest.settings:get_bool("protector_flip") or false
local protector_hurt = tonumber(minetest.settings:get("protector_hurt")) or 0
local protector_spawn = tonumber(minetest.settings:get("protector_spawn")
or minetest.settings:get("protector_pvp_spawn")) or 0
local protector_show = tonumber(minetest.settings:get("protector_show_interval")) or 5
local protector_recipe = minetest.settings:get_bool("protector_recipe") ~= false
local protector_msg = minetest.settings:get_bool("protector_msg") ~= false
-- radius limiter (minetest cannot handle node volume of more than 4096000) -- radius limiter (minetest cannot handle node volume of more than 4096000)
if protector_radius > 30 then protector_radius = 30 end if protector.radius > 30 then protector.radius = 30 end
-- playerfactions check
local factions_available = core.global_exists("factions")
if factions_available then protector.max_shares = 8 end
-- localize math
local math_floor, math_pi = math.floor, math.pi
-- settings
local protector_flip = core.settings:get_bool("protector_flip") or false
local protector_hurt = tonumber(core.settings:get("protector_hurt")) or 0
local protector_spawn = tonumber(core.settings:get("protector_spawn")
or core.settings:get("protector_pvp_spawn")) or 0
local protector_show = tonumber(core.settings:get("protector_show_interval")) or 5
local protector_recipe = core.settings:get_bool("protector_recipe") ~= false
local protector_msg = core.settings:get_bool("protector_msg") ~= false
-- get static spawn position -- get static spawn position
local statspawn = minetest.string_to_pos(minetest.settings:get("static_spawnpoint")) local statspawn = core.string_to_pos(core.settings:get("static_spawnpoint"))
or {x = 0, y = 2, z = 0} or {x = 0, y = 2, z = 0}
-- return list of members as a table -- return list of members as a table
@ -56,6 +67,10 @@ local function get_member_list(meta)
return meta:get_string("members"):split(" ") return meta:get_string("members"):split(" ")
end end
local function get_faction_list(meta)
return meta:get_string("factions"):split(" ")
end
-- write member list table in protector meta as string -- write member list table in protector meta as string
local function set_member_list(meta, list) local function set_member_list(meta, list)
@ -63,6 +78,10 @@ local function set_member_list(meta, list)
meta:set_string("members", table.concat(list, " ")) meta:set_string("members", table.concat(list, " "))
end end
local function set_faction_list(meta, list)
meta:set_string("factions", table.concat(list, " "))
end
-- check for owner name -- check for owner name
local function is_owner(meta, name) local function is_owner(meta, name)
@ -74,38 +93,19 @@ end
local function is_member(meta, name) local function is_member(meta, name)
if factions_available and meta:get_int("faction_members") == 1 then
if factions.version == nil then
-- backward compatibility
if factions.get_player_faction(name) ~= nil
and factions.get_player_faction(meta:get_string("owner")) ==
factions.get_player_faction(name) then
return true
end
else
-- is member if player and owner share at least one faction
local player_factions = factions.get_player_factions(name)
local owner = meta:get_string("owner")
if player_factions ~= nil and player_factions ~= false then
for _, f in ipairs(player_factions) do
if factions.player_is_in_faction(f, owner) then
return true
end
end
end
end
end
for _, n in pairs(get_member_list(meta)) do for _, n in pairs(get_member_list(meta)) do
if n == name then return true end if n == name then return true end
end end
if factions_available then
for _, faction in pairs(get_faction_list(meta)) do
if factions.player_is_in_faction(faction, name) then
return true
end
end
end
return false return false
end end
@ -119,18 +119,24 @@ local function add_member(meta, name)
-- Constant (20) defined by player.h -- Constant (20) defined by player.h
if name:len() > 25 then return end if name:len() > 25 then return end
-- does name already exist?
if is_owner(meta, name) or is_member(meta, name) then return end
local list = get_member_list(meta) local list = get_member_list(meta)
if #list >= protector_max_share_count then return end if #list >= protector.max_shares then return end
table.insert(list, name) table.insert(list, name)
set_member_list(meta, list) set_member_list(meta, list)
end end
local function add_faction(meta, name)
if name ~= string.match(name, "[%w_-]+") then return end
if name:len() > 25 then return end
local list = get_faction_list(meta)
if #list >= 4 then return end
table.insert(list, name)
set_faction_list(meta, list)
end
-- remove player name from table -- remove player name from table
local function del_member(meta, name) local function del_member(meta, name)
@ -140,14 +146,24 @@ local function del_member(meta, name)
for i, n in pairs(list) do for i, n in pairs(list) do
if n == name then if n == name then
table.remove(list, i) table.remove(list, i) ; break
break
end end
end end
set_member_list(meta, list) set_member_list(meta, list)
end end
local function del_faction(meta, name)
local list = get_faction_list(meta)
for i, n in pairs(list) do
if n == name then
table.remove(list, i)
break
end
end
set_faction_list(meta, list)
end
-- protector interface -- protector interface
local function protector_formspec(meta) local function protector_formspec(meta)
@ -157,73 +173,72 @@ local function protector_formspec(meta)
.. default.gui_bg_img .. default.gui_bg_img
.. "label[2.5,0;" .. F(S("-- Protector interface --")) .. "]" .. "label[2.5,0;" .. F(S("-- Protector interface --")) .. "]"
.. "label[0,1;" .. F(S("PUNCH node to show protected area")) .. "]" .. "label[0,1;" .. F(S("PUNCH node to show protected area")) .. "]"
.. "label[0,2;" .. F(S("Members:")) .. "]" .. "label[0,1.5;" .. F(S("Members:")) .. "]"
.. "button_exit[2.5,6.2;3,0.5;close_me;" .. F(S("Close")) .. "]" .. "button_exit[2.5,6.2;3,0.5;close_me;" .. F(S("Close")) .. "]"
.. "field_close_on_enter[protector_add_member;false]" .. "field_close_on_enter[protector_add_member;false]"
local members = get_member_list(meta) local members = get_member_list(meta)
local npp = protector_max_share_count -- max users added to protector list
local i = 0
local checkbox_faction = false
-- Display the checkbox only if the owner is member of at least 1 faction
if factions_available then if factions_available then
formspec = formspec .. "label[0,4.25;" .. F(S("Factions:")) .. "]"
if factions.version == nil then .. "field_close_on_enter[protector_add_faction;false]"
-- backward compatibility
if factions.get_player_faction(meta:get_string("owner")) then
checkbox_faction = true
end
else
local player_factions = factions.get_player_factions(meta:get_string("owner"))
if player_factions ~= nil and #player_factions >= 1 then
checkbox_faction = true
end
end
end
if checkbox_faction 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 end
local i = 0
for n = 1, #members do for n = 1, #members do
if i < npp then if i < protector.max_shares then
-- show username -- show username
formspec = formspec .. "button[" .. (i % 4 * 2) formspec = formspec .. "button[" .. (i % 4 * 2)
.. "," .. math.floor(i / 4 + 3) .. "," .. (math.floor(i / 4) + 2.5)
.. ";1.5,.5;protector_member;" .. F(members[n]) .. "]" .. ";1.5,.5;protector_member;" .. F(members[n]) .. "]"
-- username remove button -- username remove button
.. "button[" .. (i % 4 * 2 + 1.25) .. "," .. "button[" .. (i % 4 * 2 + 1.25) .. ","
.. math.floor(i / 4 + 3) .. (math.floor(i / 4) + 2.5)
.. ";.75,.5;protector_del_member_" .. F(members[n]) .. ";X]" .. ";.75,.5;protector_del_member_" .. F(members[n]) .. ";X]"
end end
i = i + 1 i = i + 1
end end
if i < npp then if i < protector.max_shares then
-- user name entry field -- user name entry field
formspec = formspec .. "field[" .. (i % 4 * 2 + 1 / 3) .. "," formspec = formspec .. "field[" .. (i % 4 * 2 + 1 / 3) .. ","
.. (math.floor(i / 4 + 3) + 1 / 3) .. (math.floor(i / 4) + 2.5 + 1 / 3)
.. ";1.433,.5;protector_add_member;;]" .. ";1.433,.5;protector_add_member;;]"
-- username add button -- username add button
.."button[" .. (i % 4 * 2 + 1.25) .. "," .."button[" .. (i % 4 * 2 + 1.25) .. ","
.. math.floor(i / 4 + 3) .. ";.75,.5;protector_submit;+]" .. (math.floor(i / 4) + 2.5) .. ";.75,.5;protector_submit;+]"
end end
if factions_available then
local member_factions = get_faction_list(meta)
i = 0
for n = 1, #member_factions do
if i < 4 then
formspec = formspec .. "button[" .. (i % 4 * 2)
.. "," .. math.floor(i / 4 + 5)
.. ";1.5,.5;protector_faction;" .. F(member_factions[n]) .. "]"
.. "button[" .. (i % 4 * 2 + 1.25) .. ","
.. math.floor(i / 4 + 5)
.. ";.75,.5;protector_del_faction_" .. F(member_factions[n]) .. ";X]"
end
i = i + 1
end
if i < 4 then
formspec = formspec .. "field[" .. (i % 4 * 2 + 1 / 3) .. ","
.. (math.floor(i / 4 + 5) + 1 / 3)
.. ";1.433,.5;protector_add_faction;;]"
.."button[" .. (i % 4 * 2 + 1.25) .. ","
.. math.floor(i / 4 + 5) .. ";.75,.5;protector_submit_faction;+]"
end
end
return formspec return formspec
end end
@ -243,15 +258,14 @@ end
-- show protection message if enabled -- show protection message if enabled
local function show_msg(player, msg) local function show_msg(player_name, msg)
-- if messages disabled or no player name provided -- if messages disabled or no player name provided
if protector_msg == false or not player or player == "" then return end if protector_msg == false or not player_name or player_name == "" then return end
minetest.chat_send_player(player, msg) core.chat_send_player(player_name, msg)
end end
-- Infolevel: -- Infolevel:
-- 0 for no info -- 0 for no info
-- 1 for "This area is owned by <owner> !" if you can't dig -- 1 for "This area is owned by <owner> !" if you can't dig
@ -264,7 +278,7 @@ function protector.can_dig(r, pos, digger, onlyowner, infolevel)
-- protector_bypass privileged users can override protection -- protector_bypass privileged users can override protection
if infolevel == 1 if infolevel == 1
and minetest.check_player_privs(digger, {protection_bypass = true}) then and core.check_player_privs(digger, {protection_bypass = true}) then
return true return true
end end
@ -275,13 +289,13 @@ function protector.can_dig(r, pos, digger, onlyowner, infolevel)
if inside_spawn(pos, protector_spawn) then if inside_spawn(pos, protector_spawn) then
show_msg(digger, S("Spawn @1 has been protected up to a @2 block radius.", show_msg(digger, S("Spawn @1 has been protected up to a @2 block radius.",
minetest.pos_to_string(statspawn), protector_spawn)) core.pos_to_string(statspawn), protector_spawn))
return false return false
end end
-- find the protector nodes -- find the protector nodes
local pos = minetest.find_nodes_in_area( local pos = core.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},
{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_hidden"}) {"protector:protect", "protector:protect2", "protector:protect_hidden"})
@ -290,7 +304,7 @@ function protector.can_dig(r, pos, digger, onlyowner, infolevel)
for n = 1, #pos do for n = 1, #pos do
meta = minetest.get_meta(pos[n]) meta = core.get_meta(pos[n])
owner = meta:get_string("owner") or "" owner = meta:get_string("owner") or ""
members = meta:get_string("members") or "" members = meta:get_string("members") or ""
@ -309,14 +323,14 @@ function protector.can_dig(r, pos, digger, onlyowner, infolevel)
-- when using protector as tool, show protector information -- when using protector as tool, show protector information
if infolevel == 2 then if infolevel == 2 then
minetest.chat_send_player(digger, core.chat_send_player(digger,
S("This area is owned by @1", owner) .. ".") S("This area is owned by @1", owner) .. ".")
minetest.chat_send_player(digger, core.chat_send_player(digger,
S("Protection located at: @1", minetest.pos_to_string(pos[n]))) S("Protection located at: @1", core.pos_to_string(pos[n])))
if members ~= "" then if members ~= "" then
minetest.chat_send_player(digger, S("Members: @1.", members)) core.chat_send_player(digger, S("Members: @1.", members))
end end
return false return false
@ -328,10 +342,10 @@ function protector.can_dig(r, pos, digger, onlyowner, infolevel)
if infolevel == 2 then if infolevel == 2 then
if #pos < 1 then if #pos < 1 then
minetest.chat_send_player(digger, S("This area is not protected.")) core.chat_send_player(digger, S("This area is not protected."))
end end
minetest.chat_send_player(digger, S("You can build here.")) core.chat_send_player(digger, S("You can build here."))
end end
return true return true
@ -339,9 +353,9 @@ end
-- add protector hurt and flip to protection violation function -- add protector hurt and flip to protection violation function
minetest.register_on_protection_violation(function(pos, name) core.register_on_protection_violation(function(pos, name)
local player = minetest.get_player_by_name(name) local player = core.get_player_by_name(name)
if player and player:is_player() then if player and player:is_player() then
@ -349,7 +363,7 @@ minetest.register_on_protection_violation(function(pos, name)
if protector_hurt > 0 and player:get_hp() > 0 then if protector_hurt > 0 and player:get_hp() > 0 then
-- This delay fixes item duplication bug (thanks luk3yx) -- This delay fixes item duplication bug (thanks luk3yx)
minetest.after(0.1, function(player) core.after(0.1, function(player)
player:set_hp(player:get_hp() - protector_hurt) player:set_hp(player:get_hp() - protector_hurt)
end, player) end, player)
end end
@ -358,10 +372,10 @@ minetest.register_on_protection_violation(function(pos, name)
if protector_flip then if protector_flip then
-- yaw + 180° -- yaw + 180°
local yaw = player:get_look_horizontal() + math.pi local yaw = player:get_look_horizontal() + math_pi
if yaw > 2 * math.pi then if yaw > 2 * math_pi then
yaw = yaw - 2 * math.pi yaw = yaw - 2 * math_pi
end end
player:set_look_horizontal(yaw) player:set_look_horizontal(yaw)
@ -381,16 +395,16 @@ end)
-- backup old is_protected function -- backup old is_protected function
local old_is_protected = minetest.is_protected local old_is_protected = core.is_protected
-- check for protected area, return true if protected and digger isn't on list -- check for protected area, return true if protected and digger isn't on list
function minetest.is_protected(pos, digger) function core.is_protected(pos, digger)
digger = digger or "" -- nil check digger = digger or "" -- nil check
-- is area protected against digger? -- is area protected against digger?
if not protector.can_dig(protector_radius, pos, digger, false, 1) then if not protector.can_dig(protector.radius, pos, digger, false, 1) then
return true return true
end end
@ -408,32 +422,32 @@ local function check_overlap(itemstack, placer, pointed_thing)
local name = placer:get_player_name() local name = placer:get_player_name()
-- make sure protector doesn't overlap onto protected spawn area -- make sure protector doesn't overlap onto protected spawn area
if inside_spawn(pos, protector_spawn + protector_radius) then if inside_spawn(pos, protector_spawn + protector.radius) then
minetest.chat_send_player(name, core.chat_send_player(name,
S("Spawn @1 has been protected up to a @2 block radius.", S("Spawn @1 has been protected up to a @2 block radius.",
minetest.pos_to_string(statspawn), protector_spawn)) core.pos_to_string(statspawn), protector_spawn))
return itemstack return itemstack
end end
-- make sure protector doesn't overlap any other player's area -- make sure protector doesn't overlap any other player's area
if not protector.can_dig(protector_radius * 2, pos, name, true, 3) then if not protector.can_dig(protector.radius * 2, pos, name, true, 3) then
minetest.chat_send_player(name, core.chat_send_player(name,
S("Overlaps into above players protected area")) S("Overlaps into above players protected area"))
return itemstack return itemstack
end end
return minetest.item_place(itemstack, placer, pointed_thing) return core.item_place(itemstack, placer, pointed_thing)
end end
-- remove protector display entities -- remove protector display entities
local function del_display(pos) local function del_display(pos)
local objects = minetest.get_objects_inside_radius(pos, 0.5) local objects = core.get_objects_inside_radius(pos, 0.5)
for _, v in ipairs(objects) do for _, v in ipairs(objects) do
@ -451,35 +465,34 @@ local player_pos = {}
local stone_tex = "default_stone.png" local stone_tex = "default_stone.png"
if minetest.get_modpath("nc_terrain") then if core.get_modpath("nc_terrain") then
stone_tex = "nc_terrain_stone.png" stone_tex = "nc_terrain_stone.png"
end end
-- protection node -- protector default
local def = {
minetest.register_node("protector:protect", {
description = S("Protection Block") .. " (" .. S("USE for area check") .. ")", description = S("Protection Block") .. " (" .. S("USE for area check") .. ")",
drawtype = "nodebox",
tiles = { tiles = {
stone_tex .. "^protector_overlay.png", stone_tex .. "^protector_overlay.png",
stone_tex .. "^protector_overlay.png", stone_tex .. "^protector_overlay.png",
stone_tex .. "^protector_overlay.png^protector_logo.png" stone_tex .. "^protector_overlay.png^protector_logo.png"
}, },
drawtype = "nodebox",
node_box = {type = "fixed", fixed = {{-0.499 ,-0.499, -0.499, 0.499, 0.499, 0.499}}},
sounds = default.node_sound_stone_defaults(), sounds = default.node_sound_stone_defaults(),
groups = {dig_immediate = 2, unbreakable = 1}, groups = {dig_immediate = 2, unbreakable = 1},
is_ground_content = false, is_ground_content = false,
paramtype = "light", paramtype = "light",
light_source = 4, light_source = 4,
walkable = true,
node_box = {
type = "fixed", fixed = {{-0.499 ,-0.499, -0.499, 0.499, 0.499, 0.499}}
},
on_place = check_overlap, on_place = check_overlap,
after_place_node = function(pos, placer) after_place_node = function(pos, placer)
local meta = minetest.get_meta(pos) local meta = core.get_meta(pos)
meta:set_string("owner", placer:get_player_name() or "") meta:set_string("owner", placer:get_player_name() or "")
meta:set_string("members", "") meta:set_string("members", "")
@ -491,28 +504,28 @@ minetest.register_node("protector:protect", {
if pointed_thing.type ~= "node" then return end if pointed_thing.type ~= "node" then return end
protector.can_dig(protector_radius, pointed_thing.under, protector.can_dig(protector.radius, pointed_thing.under,
user:get_player_name(), false, 2) user:get_player_name(), false, 2)
end, end,
on_rightclick = function(pos, node, clicker, itemstack) on_rightclick = function(pos, node, clicker, itemstack)
local meta = minetest.get_meta(pos) local meta = core.get_meta(pos)
local name = clicker:get_player_name() local name = clicker:get_player_name()
if meta and protector.can_dig(1, pos, name, true, 1) then if meta and protector.can_dig(1, pos, name, true, 1) then
player_pos[name] = pos player_pos[name] = pos
minetest.show_formspec(name, "protector:node", protector_formspec(meta)) core.show_formspec(name, "protector:node", protector_formspec(meta))
end end
end, end,
on_punch = function(pos, node, puncher) on_punch = function(pos, node, puncher)
if minetest.is_protected(pos, puncher:get_player_name()) then return end if core.is_protected(pos, puncher:get_player_name()) then return end
minetest.add_entity(pos, "protector:display") core.add_entity(pos, "protector:display")
end, end,
can_dig = function(pos, player) can_dig = function(pos, player)
@ -523,7 +536,11 @@ minetest.register_node("protector:protect", {
on_blast = function() end, on_blast = function() end,
after_destruct = del_display after_destruct = del_display
}) }
-- protection node
core.register_node("protector:protect", table.copy(def))
-- default recipe and alternative for MineClone2 -- default recipe and alternative for MineClone2
@ -532,12 +549,12 @@ if protector_recipe then
local item_gold = "default:gold_ingot" local item_gold = "default:gold_ingot"
local item_stone = "default:stone" local item_stone = "default:stone"
if minetest.get_modpath("mcl_core") then if core.get_modpath("mcl_core") then
item_gold = "mcl_core:gold_ingot" item_gold = "mcl_core:gold_ingot"
item_stone = "mcl_core:stone" item_stone = "mcl_core:stone"
end end
minetest.register_craft({ core.register_craft({
output = "protector:protect", output = "protector:protect",
recipe = { recipe = {
{item_stone, item_stone, item_stone}, {item_stone, item_stone, item_stone},
@ -549,95 +566,37 @@ end
-- protection logo -- protection logo
minetest.register_node("protector:protect2", { def.description = S("Protection Logo") .. " (" .. S("USE for area check") .. ")"
description = S("Protection Logo") .. " (" .. S("USE for area check") .. ")", def.tiles = {"protector_logo.png"}
tiles = {"protector_logo.png"}, def.wield_image = "protector_logo.png"
wield_image = "protector_logo.png", def.inventory_image = "protector_logo.png"
inventory_image = "protector_logo.png", def.use_texture_alpha = "clip"
sounds = default.node_sound_stone_defaults(), def.paramtype2 = "wallmounted"
groups = {dig_immediate = 2, unbreakable = 1}, def.legacy_wallmounted = true
is_ground_content = false, def.sunlight_propagates = true
use_texture_alpha = "clip", def.node_box = {
paramtype = "light",
paramtype2 = "wallmounted",
legacy_wallmounted = true,
light_source = 4,
drawtype = "nodebox",
sunlight_propagates = true,
walkable = true,
node_box = {
type = "wallmounted", type = "wallmounted",
wall_top = {-0.375, 0.4375, -0.5, 0.375, 0.5, 0.5}, 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_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} wall_side = {-0.5, -0.5, -0.375, -0.4375, 0.5, 0.375}
}, }
selection_box = {type = "wallmounted"}, def.selection_box = {type = "wallmounted"}
on_place = check_overlap, core.register_node("protector:protect2", table.copy(def))
after_place_node = function(pos, placer)
local meta = minetest.get_meta(pos)
meta:set_string("owner", placer:get_player_name() or "")
meta:set_string("members", "")
meta:set_string("infotext",
S("Protection (owned by @1)", meta:get_string("owner")))
end,
on_use = function(itemstack, user, pointed_thing)
if pointed_thing.type ~= "node" then return end
protector.can_dig(protector_radius, pointed_thing.under,
user:get_player_name(), false, 2)
end,
on_rightclick = function(pos, node, clicker, itemstack)
local meta = minetest.get_meta(pos)
local name = clicker:get_player_name()
if meta and protector.can_dig(1, pos, name, true, 1) then
player_pos[name] = pos
minetest.show_formspec(name, "protector:node", protector_formspec(meta))
end
end,
on_punch = function(pos, node, puncher)
if minetest.is_protected(pos, puncher:get_player_name()) then return end
minetest.add_entity(pos, "protector:display")
end,
can_dig = function(pos, player)
return player and protector.can_dig(1, pos, player:get_player_name(), true, 1)
end,
on_blast = function() end,
after_destruct = del_display
})
-- recipes to switch between protectors -- recipes to switch between protectors
minetest.register_craft({ core.register_craft({
output = "protector:protect", output = "protector:protect", recipe = {{"protector:protect2"}}
recipe = {{"protector:protect2"}}
}) })
minetest.register_craft({ core.register_craft({
output = "protector:protect2", output = "protector:protect2", recipe = {{"protector:protect"}}
recipe = {{"protector:protect"}}
}) })
-- check formspec buttons or when name entered -- check formspec buttons or when name entered
minetest.register_on_player_receive_fields(function(player, formname, fields) core.register_on_player_receive_fields(function(player, formname, fields)
if formname ~= "protector:node" then return end if formname ~= "protector:node" then return end
@ -661,18 +620,28 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end end
-- are we adding member to a protection node ? (csm protection) -- are we adding member to a protection node ? (csm protection)
local nod = minetest.get_node(pos).name local nod = core.get_node(pos).name
if nod ~= "protector:protect" and nod ~= "protector:protect2" then if nod ~= "protector:protect" and nod ~= "protector:protect2" then
player_pos[name] = nil player_pos[name] = nil
return return
end end
local meta = minetest.get_meta(pos) ; if not meta then return end local meta = core.get_meta(pos) ; if not meta then return end
-- add faction members -- add faction members
if factions_available and fields.faction_members ~= nil then if factions_available then
meta:set_int("faction_members", fields.faction_members == "true" and 1 or 0) local add_faction_input = fields.protector_add_faction
if add_faction_input and add_faction_input ~= "" then
for _, i in pairs(add_faction_input:split(" ")) do
add_faction(meta, i)
end
end
for field, value in pairs(fields) do
if string.sub(field, 0, string.len("protector_del_faction_")) == "protector_del_faction_" then
del_faction(meta, string.sub(field, string.len("protector_del_faction_") + 1))
end
end
end end
-- add member [+] -- add member [+]
@ -689,17 +658,16 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if string.sub(field, 0, if string.sub(field, 0,
string.len("protector_del_member_")) == "protector_del_member_" then string.len("protector_del_member_")) == "protector_del_member_" then
del_member(meta, del_member(meta, string.sub(field,string.len("protector_del_member_") + 1))
string.sub(field,string.len("protector_del_member_") + 1))
end end
end end
minetest.show_formspec(name, formname, protector_formspec(meta)) core.show_formspec(name, formname, protector_formspec(meta))
end) end)
-- display entity shown when protector node is punched -- display entity shown when protector node is punched
minetest.register_entity("protector:display", { core.register_entity("protector:display", {
initial_properties = { initial_properties = {
physical = false, physical = false,
@ -725,9 +693,9 @@ minetest.register_entity("protector:display", {
-- Display-zone node, Do NOT place the display as a node, -- Display-zone node, Do NOT place the display as a node,
-- it is made to be used as an entity (see above) -- it is made to be used as an entity (see above)
local x = protector_radius local r = protector.radius
minetest.register_node("protector:display_node", { core.register_node("protector:display_node", {
tiles = {"protector_display.png"}, tiles = {"protector_display.png"},
use_texture_alpha = "clip", use_texture_alpha = "clip",
walkable = false, walkable = false,
@ -735,40 +703,126 @@ minetest.register_node("protector:display_node", {
node_box = { node_box = {
type = "fixed", type = "fixed",
fixed = { fixed = {
{-(x+.55), -(x+.55), -(x+.55), -(x+.45), (x+.55), (x+.55)}, -- sides {-(r+.55), -(r+.55), -(r+.55), -(r+.45), (r+.55), (r+.55)}, -- sides
{-(x+.55), -(x+.55), (x+.45), (x+.55), (x+.55), (x+.55)}, {-(r+.55), -(r+.55), (r+.45), (r+.55), (r+.55), (r+.55)},
{(x+.45), -(x+.55), -(x+.55), (x+.55), (x+.55), (x+.55)}, {(r+.45), -(r+.55), -(r+.55), (r+.55), (r+.55), (r+.55)},
{-(x+.55), -(x+.55), -(x+.55), (x+.55), (x+.55), -(x+.45)}, {-(r+.55), -(r+.55), -(r+.55), (r+.55), (r+.55), -(r+.45)},
{-(x+.55), (x+.45), -(x+.55), (x+.55), (x+.55), (x+.55)}, -- top {-(r+.55), (r+.45), -(r+.55), (r+.55), (r+.55), (r+.55)}, -- top
{-(x+.55), -(x+.55), -(x+.55), (x+.55), -(x+.45), (x+.55)}, -- bottom {-(r+.55), -(r+.55), -(r+.55), (r+.55), -(r+.45), (r+.55)}, -- bottom
{-.55,-.55,-.55, .55,.55,.55} -- middle (surrounding protector) {-.55,-.55,-.55, .55,.55,.55} -- middle (surrounding protector)
} }
}, },
selection_box = {type = "regular"}, selection_box = {type = "regular"},
paramtype = "light", paramtype = "light",
groups = {dig_immediate = 3, not_in_creative_inventory = 1}, groups = {dig_immediate = 3, not_in_creative_inventory = 1},
drop = "" drop = "",
on_blast = function() end
}) })
-- load mod sections -- load mod sections
dofile(MP .. "/doors_chest.lua") dofile(MP .. "/doors.lua")
dofile(MP .. "/chest.lua")
dofile(MP .. "/pvp.lua") dofile(MP .. "/pvp.lua")
dofile(MP .. "/admin.lua") dofile(MP .. "/admin.lua")
dofile(MP .. "/tool.lua") dofile(MP .. "/tool.lua")
dofile(MP .. "/hud.lua") dofile(MP .. "/hud.lua")
if minetest.get_modpath("lucky_block") then if core.get_modpath("lucky_block") then
dofile(MP .. "/lucky_block.lua") dofile(MP .. "/lucky_block.lua")
end end
-- stop mesecon pistons from pushing protectors -- stop mesecon pistons from pushing protectors
if minetest.get_modpath("mesecons_mvps") then if core.get_modpath("mesecons_mvps") then
mesecon.register_mvps_stopper("protector:protect") mesecon.register_mvps_stopper("protector:protect")
mesecon.register_mvps_stopper("protector:protect2") mesecon.register_mvps_stopper("protector:protect2")
mesecon.register_mvps_stopper("protector:protect_hidden") mesecon.register_mvps_stopper("protector:protect_hidden")
mesecon.register_mvps_stopper("protector:chest") mesecon.register_mvps_stopper("protector:chest")
end end
-- player command to add member names to local protection
core.register_chatcommand("protector_add_member", {
params = "",
description = S("Add member names to local protection"),
privs = {interact = true},
func = function(name, param)
if param == "" then return end
local to_add = param:split(" ")
local player = core.get_player_by_name(name)
local pos = player:get_pos()
-- find the protector nodes
local pos = core.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_hidden"})
local meta, owner
for n = 1, #pos do
meta = core.get_meta(pos[n])
owner = meta:get_string("owner") or ""
if owner == name
or core.check_player_privs(name, {protection_bypass = true}) then
for m = 1, #to_add do
add_member(meta, to_add[m])
end
core.add_entity(pos[n], "protector:display")
end
end
end
})
-- player command to remove member names from local protection
core.register_chatcommand("protector_del_member", {
params = "",
description = S("Remove member names from local protection"),
privs = {interact = true},
func = function(name, param)
if param == "" then return end
local to_del = param:split(" ")
local player = core.get_player_by_name(name)
local pos = player:get_pos()
-- find the protector nodes
local pos = core.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_hidden"})
local meta, owner
for n = 1, #pos do
meta = core.get_meta(pos[n])
owner = meta:get_string("owner") or ""
if owner == name
or core.check_player_privs(name, {protection_bypass = true}) then
for m = 1, #to_del do
del_member(meta, to_del[m])
end
core.add_entity(pos[n], "protector:display")
end
end
end
})
print ("[MOD] Protector Redo loaded") print ("[MOD] Protector Redo loaded")

View file

@ -1,6 +1,6 @@
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2016 TenPlus1 Copyright (c) 2025 TenPlus1
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View file

@ -11,6 +11,9 @@ Replacing Protector name '@1' with '@2'=Ersetze Besitzer der Störschützer von
Show protected areas of your nearby protectors=Zeige geschützte Bereiche der Störschützer in der Nähe Show protected areas of your nearby protectors=Zeige geschützte Bereiche der Störschützer in der Nähe
Protector Names to remove: @1=Störschutznamen zum Entfernen: @1 Protector Names to remove: @1=Störschutznamen zum Entfernen: @1
Name List Reset=Namensliste zurückgesetzt Name List Reset=Namensliste zurückgesetzt
Invalid player name!=
Player name too long=
Player not found.=
### doors_chest.lua ### ### doors_chest.lua ###
Protected Wooden Door=Geschützte Holztür Protected Wooden Door=Geschützte Holztür
@ -30,6 +33,7 @@ Members:=Mitglieder:
Close=Schließen Close=Schließen
Protection located at: @1=Störschutz befindet sich bei: @1 Protection located at: @1=Störschutz befindet sich bei: @1
Members: @1.=Mitglieder: @1. Members: @1.=Mitglieder: @1.
Allow faction access=
This area is not protected.=Dieser Bereich ist nicht geschützt. This area is not protected.=Dieser Bereich ist nicht geschützt.
You can build here.=Du kannst hier bauen. You can build here.=Du kannst hier bauen.
Overlaps into above players protected area=Überlappung im geschützen Bereich eines Spielers Overlaps into above players protected area=Überlappung im geschützen Bereich eines Spielers
@ -40,11 +44,6 @@ Protection Logo=Störschutzlogo
Spawn @1 has been protected up to a @2 block radius.=Spawn @1 ist geschützt mit einem Radius von @2 Blöcke. Spawn @1 has been protected up to a @2 block radius.=Spawn @1 ist geschützt mit einem Radius von @2 Blöcke.
This area is owned by @1=Dieser Bereich gehört @1 This area is owned by @1=Dieser Bereich gehört @1
### pvp.lua ###
[Protector] on_punchplayer called with nil objects=on_punchplayer wurde durch \"nil objects\" aufgerufen
[Protector] pvp_protect not active, update your version of Minetest=pvp_protect ist nicht aktiv, aktualisiere deine Minetestversion
[Protector] pvp_protect is disabled=pvp_protect ist ausgeschaltet
### hud.lua ### ### hud.lua ###
Owner: @1=Besitzer: @1 Owner: @1=Besitzer: @1
@ -53,3 +52,6 @@ Protector Placer Tool (stand near protector, face direction and use)=Störschutz
Protector already in place!=Störschutz is bereits platziert! Protector already in place!=Störschutz is bereits platziert!
No protectors available to place!=Keine Störschützer mehr im Inventar! No protectors available to place!=Keine Störschützer mehr im Inventar!
"Protector placed at @1"=Störschutz befindet sich bei: @1 "Protector placed at @1"=Störschutz befindet sich bei: @1
Out of bounds!=
Cannot place protector, already protected at @1=
Cannot place protector, container at @1=

View file

@ -11,6 +11,9 @@ Replacing Protector name '@1' with '@2'=Reemplazando el nombre del protector '@1
Show protected areas of your nearby protectors=Mostrar áreas protegidas de sus protectores cercanos Show protected areas of your nearby protectors=Mostrar áreas protegidas de sus protectores cercanos
Protector Names to remove: @1=Nombres de protectores para eliminar: @1 Protector Names to remove: @1=Nombres de protectores para eliminar: @1
Name List Reset=Restablecer lista de nombres Name List Reset=Restablecer lista de nombres
Invalid player name!=
Player name too long=
Player not found.=
### doors_chest.lua ### ### doors_chest.lua ###
Protected Wooden Door=Puerta de madera protegida Protected Wooden Door=Puerta de madera protegida
@ -30,6 +33,7 @@ Members:=Miembros:
Close=Cerrar Close=Cerrar
Protection located at: @1=Protección ubicada en: @1 Protection located at: @1=Protección ubicada en: @1
Members: @1.=Miembros: @1. Members: @1.=Miembros: @1.
Allow faction access=
This area is not protected.=Esta área no está protegida. This area is not protected.=Esta área no está protegida.
You can build here.=Puedes construir aquí. You can build here.=Puedes construir aquí.
Overlaps into above players protected area=Se superpone en el área protegida de los jugadores anteriores Overlaps into above players protected area=Se superpone en el área protegida de los jugadores anteriores
@ -40,11 +44,6 @@ Protection Logo=Logotipo de la protección
Spawn @1 has been protected up to a @2 block radius.=Spawn @1 ha sido protegido hasta un radio de bloque @2. Spawn @1 has been protected up to a @2 block radius.=Spawn @1 ha sido protegido hasta un radio de bloque @2.
This area is owned by @1=Esta área es propiedad de @1 This area is owned by @1=Esta área es propiedad de @1
### pvp.lua ###
[Protector] on_punchplayer called with nil objects=[Protector] on_punchplayer llamado con objetos nulos.
[Protector] pvp_protect not active, update your version of Minetest=[Protector] pvp_protect no está activo, actualiza tu versión de Minetest
[Protector] pvp_protect is disabled=[Protector] pvp_protect está deshabilitado
### hud.lua ### ### hud.lua ###
Owner: @1=Propietario: @1 Owner: @1=Propietario: @1
@ -53,3 +52,6 @@ Protector Placer Tool (stand near protector, face direction and use)=Herramienta
Protector already in place!=¡El protector ya está en este lugar! Protector already in place!=¡El protector ya está en este lugar!
No protectors available to place!=¡No hay protectores disponibles para colocar! No protectors available to place!=¡No hay protectores disponibles para colocar!
Protector placed at @1=Protector colocado en @1 Protector placed at @1=Protector colocado en @1
Out of bounds!=
Cannot place protector, already protected at @1=
Cannot place protector, container at @1=

View file

@ -11,6 +11,9 @@ Replacing Protector name '@1' with '@2'=
Show protected areas of your nearby protectors=Affichez les zones protégées de vos protecteurs à proximité Show protected areas of your nearby protectors=Affichez les zones protégées de vos protecteurs à proximité
Protector Names to remove: @1=Noms de protecteurs à supprimer: @1 Protector Names to remove: @1=Noms de protecteurs à supprimer: @1
Name List Reset=Liste de noms réinitialiser Name List Reset=Liste de noms réinitialiser
Invalid player name!=
Player name too long=
Player not found.=
### doors_chest.lua ### ### doors_chest.lua ###
Protected Wooden Door=Porte en bois protégée Protected Wooden Door=Porte en bois protégée
@ -30,6 +33,7 @@ Members:=Membres:
Close=Fermer Close=Fermer
Protection located at: @1=Protection située à: @1 Protection located at: @1=Protection située à: @1
Members: @1.=Membres: @1. Members: @1.=Membres: @1.
Allow faction access=
This area is not protected.=msgstr "Cette zone n'est pas protégée. This area is not protected.=msgstr "Cette zone n'est pas protégée.
You can build here.=Vous pouvez construire ici. You can build here.=Vous pouvez construire ici.
Overlaps into above players protected area=Vous chevauché une zone protégé. Overlaps into above players protected area=Vous chevauché une zone protégé.
@ -40,11 +44,6 @@ Protection Logo=Logo de protection
Spawn @1 has been protected up to a @2 block radius.= Spawn @1 has been protected up to a @2 block radius.=
This area is owned by @1=Cette zone appartient à @1! This area is owned by @1=Cette zone appartient à @1!
### pvp.lua ###
[Protector] on_punchplayer called with nil objects=[Protector] on_punchplayer appelé avec des objets nil
[Protector] pvp_protect not active, update your version of Minetest=[Protector] pvp_protect est désactivé, mettez à jour votre version de Minetest
[Protector] pvp_protect is disabled=[Protector] pvp_protect est désactivé
### hud.lua ### ### hud.lua ###
Owner: @1=Propriétaire: @1 Owner: @1=Propriétaire: @1
@ -53,3 +52,6 @@ Protector Placer Tool (stand near protector, face direction and use)=Outil de pl
Protector already in place!=Protecteur déjà en place! Protector already in place!=Protecteur déjà en place!
No protectors available to place!=Aucun protecteur disponible à placer! No protectors available to place!=Aucun protecteur disponible à placer!
Protector placed at @1=Protection située à: @1 Protector placed at @1=Protection située à: @1
Out of bounds!=
Cannot place protector, already protected at @1=
Cannot place protector, container at @1=

View file

@ -11,6 +11,9 @@ Replacing Protector name '@1' with '@2'=Sostituzione del nome del protettore '@1
Show protected areas of your nearby protectors=Mostra le aree protette dei protettori vicino a te Show protected areas of your nearby protectors=Mostra le aree protette dei protettori vicino a te
Protector Names to remove: @1=Nomi dei protettori da eliminare: @1 Protector Names to remove: @1=Nomi dei protettori da eliminare: @1
Name List Reset=Azzera l'elenco dei nomi Name List Reset=Azzera l'elenco dei nomi
Invalid player name!=
Player name too long=
Player not found.=
### doors_chest.lua ### ### doors_chest.lua ###
Protected Wooden Door=Porta di legno protetta Protected Wooden Door=Porta di legno protetta
@ -30,6 +33,7 @@ Members:=Membri:
Close=Chiudi Close=Chiudi
Protection located at: @1=Protezione collocata a: @1 Protection located at: @1=Protezione collocata a: @1
Members: @1.=Membri: @1. Members: @1.=Membri: @1.
Allow faction access=
This area is not protected.=Quest'area non è protetta. This area is not protected.=Quest'area non è protetta.
You can build here.=Qui puoi costruire. You can build here.=Qui puoi costruire.
Overlaps into above players protected area=Si sovrappone ad un'area sovrastante protetta dai giocatori Overlaps into above players protected area=Si sovrappone ad un'area sovrastante protetta dai giocatori
@ -40,11 +44,6 @@ Protection Logo=Logo di protezione
Spawn @1 has been protected up to a @2 block radius.=Lo spawn @1 è stato protetto fino a un raggio di @2 blocchi. Spawn @1 has been protected up to a @2 block radius.=Lo spawn @1 è stato protetto fino a un raggio di @2 blocchi.
This area is owned by @1=Quest'area è di proprietà di @1 This area is owned by @1=Quest'area è di proprietà di @1
### pvp.lua ###
[Protector] on_punchplayer called with nil objects=[Protector] on_punchplayer chiamato con oggetti nil
[Protector] pvp_protect not active, update your version of Minetest=[Protector] pvp_protect non attiva, aggiorna la tua versione di Minetest
[Protector] pvp_protect is disabled=[Protector] pvp_protect è disattivato
### hud.lua ### ### hud.lua ###
Owner: @1=Proprietario: @1 Owner: @1=Proprietario: @1
@ -53,3 +52,6 @@ Protector Placer Tool (stand near protector, face direction and use)=Strumento d
Protector already in place!=Protettore già presente! Protector already in place!=Protettore già presente!
No protectors available to place!=Nessun protettore disponibile da posizionare! No protectors available to place!=Nessun protettore disponibile da posizionare!
Protector placed at @1=Protettore posizionato a @1 Protector placed at @1=Protettore posizionato a @1
Out of bounds!=
Cannot place protector, already protected at @1=
Cannot place protector, container at @1=

View file

@ -1,55 +1,62 @@
# textdomain: protector # textdomain: protector
# author: CodeXP # author: SkyBuilder1717
# last update: 2018/Jul/10 # last update: 2025/Jan/27
### admin.lua ### ### admin.lua ###
Remove Protectors around players (separate names with spaces)=Удалить защиту рядом с игроками (перечислить имена, разделяя пробелами) Remove Protectors around players (separate names with spaces)=Удалить Защитников вокруг игроков (отделяйте имена с помощью пробела)
<names list>=<список имён> <names list>=<игроки>
Replace Protector Owner with name provided=Заменить владельца защиты новым владельцем Replace Protector Owner with name provided=Заменить Владельца Защитника с доставленным именем
<owner name> <name to replace with>=<имя владельца> <имя нового владельца> <owner name> <name to replace with>=<владелец> <новый владелец>
Replacing Protector name '@1' with '@2'=Заменяется владелец защиты с '@1' на '@2' Replacing Protector name '@1' with '@2'=Замена Имени Защитника '@1' с '@2'
Show protected areas of your nearby protectors=Показать ближайшие защищённые территории Show protected areas of your nearby protectors=Показать защищённые зоны Защитниками с вами неподалёку
Protector Names to remove: @1=Имена, подлежащие удалению: @1 Protector Names to remove: @1=Имена Защитников чтобы удалить: @1
Name List Reset=Очистить список имён Name List Reset=Сброс Список Имён
Invalid player name!=Неправильное имя игрока!
Player name too long=Имя игрока слишком длинное
Player not found.=Игрок не найден.
### doors_chest.lua ### ### doors_chest.lua ###
Protected Wooden Door=Защищённая яблоневая дверь Protected Wooden Door=Защищённая Деревянная Дверь
Protected Steel Door=Защищённая стальная дверь Protected Steel Door=Защищённая Стальная Дверь
Protected Trapdoor=Защищённый яблоневый люк Protected Trapdoor=Защищённый Люк
Protected Steel Trapdoor=Защищённый стальной люк Protected Steel Trapdoor=Защищённый Стальной Люк
Protected Chest=Защищённый сундук Protected Chest=Защищённый Сундук
To Chest=В сундук To Chest=В Сундук
To Inventory=В инвентрарь To Inventory=В Инвентарь
Protected Chest (@1)=Защищённый сундук (@1) Protected Chest (@1)=Защищённый Сундук (@1)
### init.lua ### ### init.lua ###
-- Protector interface --=-- Настройка защиты -- -- Protector interface --=-- Интерфейс Защитника --
PUNCH node to show protected area=СТУКНУТЬ узел для подсветки защищённой территории PUNCH node to show protected area=УДАРЬТЕ по блоку чтобы показать защищённую зону
USE for area check=ЛКМ для проверки защищённой территории USE for area check=ИСПОЛЬЗУЙТЕ для проверки зоны
Members:=Участники: Members:=Участники:
Close=Закрыть Close=Закрыть
Protection located at: @1=Защита находится на координатах @1 Allow faction access=Разрешить частичный доступ
Protection located at: @1=Защитник расположен на: @1
Members: @1.=Участники: @1. Members: @1.=Участники: @1.
This area is not protected.=Территория свободна. This area is not protected.=Эта зона не защищена.
You can build here.=Здесь можно ставить блоки. You can build here.=Вы можете здесь строить.
Overlaps into above players protected area=Защитный блок не может быть установлен: пересечение с областями, защищёнными другими игроками Overlaps into above players protected area=Перекрывает защищенную зону вышеперечисленных игроков
Protection Block=Защитный блок Protection Block=Блок Защиты
Protection (owned by @1)=Защита игрока @1 Protection (owned by @1)=Защита (владелец: @1)
Protection Logo=Защитный знак Protection Logo=Логотип Защиты
[MOD] Protector Redo loaded=[МОД] Protector Redo загружен [MOD] Protector Redo loaded=[MOD] Protector Redo загружен
Spawn @1 has been protected up to a @2 block radius.=Спаун @1 защищён в радиусе @2 блока. Spawn @1 has been protected up to a @2 block radius.=Спавн @1 был защищён радиусом в блоках @2.
This area is owned by @1=Эта территория пренадлежит @1 This area is owned by @1=Эта зона принадлежит @1.
### pvp.lua ### ### pvp.lua ###
[Protector] on_punchplayer called with nil objects=[Защита] on_punchplayer вызвана с нулевыми объектами [Protector] on_punchplayer called with nil objects=on_punchplayer вызван на нулевом объекте
[Protector] pvp_protect not active, update your version of Minetest=[Защита] pvp_protect неактивен, обновите версию Minetest [Protector] pvp_protect not active, update your version of Luanti=[Protector] pvp_protect не активен, обновите версию Luanti
[Protector] pvp_protect is disabled=[Защита] pvp_protect отключён [Protector] pvp_protect is disabled=[Protector] pvp_protect выключен
### hud.lua ### ### hud.lua ###
Owner: @1=Владелец: @1 Owner: @1=Владелец: @1
### tool.lua ### ### tool.lua ###
Protector Placer Tool (stand near protector, face direction and use)=Инструмент установки защиты (встаньте рядом с защитой, повернитесь в нужном направлении и используйте) Protector Placer Tool (stand near protector, face direction and use)=Инструмент Размещения Защитника (встаньте рядом с Защитником, повернитесь к нему и используйте предмет)
Protector already in place!=Защита уже установлена! Protector already in place!=Защитник уже стоит на этом месте!
No protectors available to place!=У вас нет защитных блоков в инвентаре! No protectors available to place!=Нет доступных Защитников чтобы поставить!
Protector placed at @1=Защита находится на координатах @1 Out of bounds!=За пределами!
Protector placed at @1=Защитник размещён на @1
Cannot place protector, already protected at @1=Нельзя поставить Защитник, другой Защитник уже на @1
Cannot place protector, container at @1=Нельзя поставить Защитник, контейнер на @1

View file

@ -11,6 +11,9 @@ Replacing Protector name '@1' with '@2'='@1' Koruyucu adını '@2' ile değişti
Show protected areas of your nearby protectors=Yakındaki koruyucuların korunan alanlarını göster Show protected areas of your nearby protectors=Yakındaki koruyucuların korunan alanlarını göster
Protector Names to remove: @1=Silinecek korumaların isimleri: @1 Protector Names to remove: @1=Silinecek korumaların isimleri: @1
Name List Reset=İsim listesini sıfırla Name List Reset=İsim listesini sıfırla
Invalid player name!=
Player name too long=
Player not found.=
### doors_chest.lua ### ### doors_chest.lua ###
Protected Wooden Door=Korumalı ahşap kapı Protected Wooden Door=Korumalı ahşap kapı
@ -30,6 +33,7 @@ Members:=Üyeler
Close=Kapat Close=Kapat
Protection located at: @1=Korumanın bulunduğu yer @1 Protection located at: @1=Korumanın bulunduğu yer @1
Members: @1.=Üyeler @1. Members: @1.=Üyeler @1.
Allow faction access=
This area is not protected.=Bu alan korumalı değildir. This area is not protected.=Bu alan korumalı değildir.
You can build here.=Buraya inşaa edebilirsiniz. You can build here.=Buraya inşaa edebilirsiniz.
Overlaps into above players protected area=Yukarıdaki oyuncuların koruma alanı ile çakışıyor Overlaps into above players protected area=Yukarıdaki oyuncuların koruma alanı ile çakışıyor
@ -40,11 +44,6 @@ Protection Logo=Koruma arması
Spawn @1 has been protected up to a @2 block radius.=Spawn @1, @2 blok yarıçapa kadar korunur. Spawn @1 has been protected up to a @2 block radius.=Spawn @1, @2 blok yarıçapa kadar korunur.
This area is owned by @1=Burasının sahibi @1! This area is owned by @1=Burasının sahibi @1!
### pvp.lua ###
[Protector] on_punchplayer called with nil objects=[Protector] on_punchplayer boş objelerle çağrıldı
[Protector] pvp_protect not active, update your version of Minetest=[Protector] pvp_protect aktif değil, Minetest sürümünüzü güncelleyin.
[Protector] pvp_protect is disabled=[Protector] pvp_protect kapatıldı.
### hud.lua ### ### hud.lua ###
Owner: @1=Sahip: @1 Owner: @1=Sahip: @1
@ -53,3 +52,6 @@ Protector Placer Tool (stand near protector, face direction and use)=Koruyucu Ye
Protector already in place!=Koruyucu zaten yerinde! Protector already in place!=Koruyucu zaten yerinde!
No protectors available to place!=Yerleştirilecek koruyucu yok! No protectors available to place!=Yerleştirilecek koruyucu yok!
Protector placed at @1=Korumanın bulunduğu yer @1 Protector placed at @1=Korumanın bulunduğu yer @1
Out of bounds!=
Cannot place protector, already protected at @1=
Cannot place protector, container at @1=

56
locale/protector.uk.tr Normal file
View file

@ -0,0 +1,56 @@
# textdomain: protector
Protector Redo=Захист
Lets players craft special blocks to protect their builds or disable PVP in areas.=Дозволяє гравцям створювати спеціальні блоки для захисту їхніх споруд або вимкнення PVP на певних територіях.
### admin.lua ###
Remove Protectors around players (separate names with spaces)=Видалити захист поряд із гравцями (перечислити імена, розділяючи пробілами)
<names list>=<список імен>
Replace Protector Owner with name provided=Замінити власника захисту новим власником
<owner name> <name to replace with>=<ім'я власника> <ім'я нового власника>
Replacing Protector name '@1' with '@2'=Заміняється власник захисту із '@1' на '@2'
Show protected areas of your nearby protectors=Показати найближчі захищені території
Protector Names to remove: @1=Імена, які будуть видалені: @1
Name List Reset=Очистити список імен
### doors_chest.lua ###
Protected Wooden Door=Захищені дерев'яні двері
Protected Steel Door=Захищені сталеві двері
Protected Trapdoor=Захищений дерев'яний люк
Protected Steel Trapdoor=Захищений сталевий люк
Protected Chest=Захищена скриня
To Chest=В скриню
To Inventory=В інвентар
Protected Chest (@1)=Захищена скриня (@1)
### init.lua ###
-- Protector interface --=-- Налаштування захисту --
PUNCH node to show protected area=ВДАРИТИ блок для підсвітки захищеної території
USE for area check=ЛКМ для перевірки захищеної території
Members:=Учасники:
Close=Закрити
Protection located at: @1=Захист знаходиться на координатах: @1
Members: @1.=Учасники: @1.
This area is not protected.=Територія вільна.
You can build here.=Тут можна будувати.
Overlaps into above players protected area=Блок захисту не може бути встановлений тут, десь поруч є територія іншого гравця
Protection Block=Блок захисту території
Protection (owned by @1)=Захист території гравця @1
Protection Logo=Захисний знак
[MOD] Protector Redo loaded=[МОД] Protector Redo завантажено
Spawn @1 has been protected up to a @2 block radius.=Спавн @1 захищений у радіусі @2 блока.
This area is owned by @1=Ця територія належить гравцю @1
### pvp.lua ###
[Protector] on_punchplayer called with nil objects=[Захист] on_punchplayer викликана із нульовими об'єктами
[Protector] pvp_protect not active, update your version of Minetest=[Захист] pvp_protect неактивний, оновіть версію Luanti
[Protector] pvp_protect is disabled=[Защита] pvp_protect вимкнений
### hud.lua ###
Owner: @1=Територія належить @1
### tool.lua ###
Protector Placer Tool (stand near protector, face direction and use)=Інструмент встановлення захисту (встаньте поруч із захистом, поверніться в потрібному напрямку і використайте)
Protector already in place!=Захист уже встановлено!
No protectors available to place!=У вас немає блоків захисту території в інвентарю!
Protector placed at @1=Захист знаходиться на координатах @1

59
locale/template.txt Normal file
View file

@ -0,0 +1,59 @@
# textdomain: protector
# author: ?
# last update: 2020/Jul/12
### admin.lua ###
Remove Protectors around players (separate names with spaces)=
<names list>=
Replace Protector Owner with name provided=
<owner name> <name to replace with>=
Replacing Protector name '@1' with '@2'=
Show protected areas of your nearby protectors=
Protector Names to remove: @1=
Name List Reset=
Invalid player name!=
Player name too long=
Player not found.=
### doors_chest.lua ###
Protected Wooden Door=
Protected Steel Door=
Protected Trapdoor=
Protected Steel Trapdoor=
Protected Chest=
To Chest=
To Inventory=
Protected Chest (@1)=
### init.lua ###
-- Protector interface --=
PUNCH node to show protected area=
USE for area check=
Members:=
Close=
Protection located at: @1=
Members: @1.=
Allow faction access=
This area is not protected.=
You can build here.=
Overlaps into above players protected area=
Protection Block=
Protection (owned by @1)=
Protection Logo=
[MOD] Protector Redo loaded=
Spawn @1 has been protected up to a @2 block radius.=
This area is owned by @1=
Add member names to local protection
Remove member names from local protection
### hud.lua ###
Owner: @1=
### tool.lua ###
Protector Placer Tool (stand near protector, face direction and use)=
Protector already in place!=
Out of bounds!=
No protectors available to place!=
Protector placed at @1=
Cannot place protector, already protected at @1=
Cannot place protector, container at @1=

View file

@ -2,13 +2,13 @@
-- add lucky blocks -- add lucky blocks
lucky_block:add_blocks({ lucky_block:add_blocks({
{"dro", {"protector:protect"}, 3}, {"dro", {"protector:protect"}, 2},
{"dro", {"protector:protect2"}, 3}, {"dro", {"protector:protect2"}, 2},
{"dro", {"protector:door_wood"}, 1}, {"dro", {"protector:door_wood"}, 2},
{"dro", {"protector:door_steel"}, 1}, {"dro", {"protector:door_steel"}, 2},
{"exp", 5, true}, {"exp", 5, true},
{"dro", {"protector:trapdoor"}, 1}, {"dro", {"protector:trapdoor"}, 2},
{"dro", {"protector:trapdoor_steel"}, 1}, {"dro", {"protector:trapdoor_steel"}, 2},
{"dro", {"protector:tool"}, 1}, {"dro", {"protector:tool"}, 1},
{"dro", {"protector:chest"}, 1}, {"dro", {"protector:chest"}, 1},
{"exp"} {"exp"}

22
pvp.lua
View file

@ -1,26 +1,26 @@
-- get static spawn position -- get static spawn position
local statspawn = minetest.string_to_pos(minetest.settings:get("static_spawnpoint")) local statspawn = core.string_to_pos(core.settings:get("static_spawnpoint"))
or {x = 0, y = 2, z = 0} or {x = 0, y = 2, z = 0}
-- is spawn protected -- is spawn protected
local protector_spawn = tonumber(minetest.settings:get("protector_spawn") local protector_spawn = tonumber(core.settings:get("protector_spawn")
or minetest.settings:get("protector_pvp_spawn")) or 0 or core.settings:get("protector_pvp_spawn")) or 0
-- is night-only pvp enabled -- is night-only pvp enabled
local protector_night_pvp = minetest.settings:get_bool("protector_night_pvp") local protector_night_pvp = core.settings:get_bool("protector_night_pvp")
-- disables PVP in your own protected areas -- disables PVP in your own protected areas
if minetest.settings:get_bool("enable_pvp") if core.settings:get_bool("enable_pvp")
and minetest.settings:get_bool("protector_pvp") then and core.settings:get_bool("protector_pvp") then
if minetest.register_on_punchplayer then if core.register_on_punchplayer then
minetest.register_on_punchplayer(function(player, hitter, core.register_on_punchplayer(function(player, hitter,
time_from_last_punch, tool_capabilities, dir, damage) time_from_last_punch, tool_capabilities, dir, damage)
if not player or not hitter then if not player or not hitter then
@ -46,7 +46,7 @@ and minetest.settings:get_bool("protector_pvp") then
if protector_night_pvp then if protector_night_pvp then
-- get time of day -- get time of day
local tod = minetest.get_timeofday() or 0 local tod = core.get_timeofday() or 0
if tod > 0.2 and tod < 0.8 then if tod > 0.2 and tod < 0.8 then
-- --
@ -56,16 +56,14 @@ and minetest.settings:get_bool("protector_pvp") then
end end
-- is player being punched inside a protected area ? -- is player being punched inside a protected area ?
if minetest.is_protected(pos, hitter:get_player_name()) then if core.is_protected(pos, hitter:get_player_name()) then
return true return true
end end
return false return false
end) end)
else else
print("[MOD] Protector - pvp_protect not active, update your version of Minetest") print("[MOD] Protector - pvp_protect not active, update your version of Minetest")
end end
else else
print("[MOD] Protector - pvp_protect is disabled") print("[MOD] Protector - pvp_protect is disabled")

Binary file not shown.

Before

Width:  |  Height:  |  Size: 82 KiB

After

Width:  |  Height:  |  Size: 64 KiB

Before After
Before After

View file

@ -1,19 +1,15 @@
-- protector placement tool (thanks to Shara for code and idea) -- protector placement tool (thanks to Shara for code and idea)
local S = minetest.get_translator("protector") local S = core.get_translator("protector")
-- get protection radius -- get protection radius
local r = tonumber(minetest.settings:get("protector_radius")) or 5 local r = protector.radius
-- radius limiter (minetest cannot handle node volume of more than 4096000)
if r > 30 then r = 30 end
-- protector placement tool -- protector placement tool
minetest.register_craftitem("protector:tool", { core.register_craftitem("protector:tool", {
description = S("Protector Placer Tool (stand near protector, face direction and use)"), description = S("Protector Placer Tool (stand near protector, face direction and use)"),
inventory_image = "protector_tool.png", inventory_image = "protector_tool.png",
stack_max = 1, stack_max = 1,
@ -24,7 +20,7 @@ minetest.register_craftitem("protector:tool", {
-- check for protector near player (2 block radius) -- check for protector near player (2 block radius)
local pos = user:get_pos() local pos = user:get_pos()
local pp = minetest.find_nodes_in_area( local pp = core.find_nodes_in_area(
vector.subtract(pos, 2), vector.add(pos, 2), vector.subtract(pos, 2), vector.add(pos, 2),
{"protector:protect", "protector:protect2", "protector:protect_hidden"}) {"protector:protect", "protector:protect2", "protector:protect_hidden"})
@ -33,28 +29,23 @@ minetest.register_craftitem("protector:tool", {
pos = pp[1] -- take position of first protector found pos = pp[1] -- take position of first protector found
-- get members on protector -- get members on protector
local meta = minetest.get_meta(pos) local meta = core.get_meta(pos)
local members = meta:get_string("members") or "" local members = meta:get_string("members") or ""
local faction = meta:get_int("faction_members")
-- get direction player is facing -- get direction player is facing
local dir = minetest.dir_to_facedir( user:get_look_dir() ) local dir = core.dir_to_facedir( user:get_look_dir() )
local vec = {x = 0, y = 0, z = 0} local vec = {x = 0, y = 0, z = 0}
local gap = (r * 2) + 1 local gap = (r * 2) + 1
local pit = user:get_look_vertical() local pit = user:get_look_vertical()
-- set placement coords -- set placement coords
if pit > 1.2 then if pit > 1.2 then vec.y = -gap -- up
vec.y = -gap -- up elseif pit < -1.2 then vec.y = gap -- down
elseif pit < -1.2 then elseif dir == 0 then vec.z = gap -- north
vec.y = gap -- down elseif dir == 1 then vec.x = gap -- east
elseif dir == 0 then elseif dir == 2 then vec.z = -gap -- south
vec.z = gap -- north elseif dir == 3 then vec.x = -gap -- west
elseif dir == 1 then
vec.x = gap -- east
elseif dir == 2 then
vec.z = -gap -- south
elseif dir == 3 then
vec.x = -gap -- west
end end
-- new position -- new position
@ -65,26 +56,26 @@ minetest.register_craftitem("protector:tool", {
-- does placing a protector overlap existing area -- does placing a protector overlap existing area
if not protector.can_dig(r * 2, pos, user:get_player_name(), true, 3) then if not protector.can_dig(r * 2, pos, user:get_player_name(), true, 3) then
minetest.chat_send_player(name, core.chat_send_player(name,
S("Overlaps into above players protected area")) S("Overlaps into above players protected area"))
return return
end end
-- does a protector already exist ? -- does a protector already exist ?
if #minetest.find_nodes_in_area(vector.subtract(pos, 1), vector.add(pos, 1), if #core.find_nodes_in_area(vector.subtract(pos, 1), vector.add(pos, 1),
{"protector:protect", "protector:protect2", {"protector:protect", "protector:protect2",
"protector:protect_hidden"}) > 0 then "protector:protect_hidden"}) > 0 then
minetest.chat_send_player(name, S("Protector already in place!")) core.chat_send_player(name, S("Protector already in place!"))
return return
end end
-- do not place protector out of map bounds or replace bedrock -- do not place protector out of map bounds or replace bedrock
if #minetest.find_nodes_in_area(pos, pos, {"ignore", "mcl_core:bedrock"}) > 0 then if #core.find_nodes_in_area(pos, pos, {"ignore", "mcl_core:bedrock"}) > 0 then
minetest.chat_send_player(name, S("Out of bounds!")) core.chat_send_player(name, S("Out of bounds!"))
return return
end end
@ -96,7 +87,7 @@ minetest.register_craftitem("protector:tool", {
if not inv:contains_item("main", "protector:protect") if not inv:contains_item("main", "protector:protect")
and not inv:contains_item("main", "protector:protect2") then and not inv:contains_item("main", "protector:protect2") then
minetest.chat_send_player(name, core.chat_send_player(name,
S("No protectors available to place!")) S("No protectors available to place!"))
return return
@ -117,28 +108,29 @@ minetest.register_craftitem("protector:tool", {
end end
-- do not replace containers with inventory space -- do not replace containers with inventory space
local inv = minetest.get_inventory({type = "node", pos = pos}) local inv = core.get_inventory({type = "node", pos = pos})
if inv then if inv then
minetest.chat_send_player(name, S("Cannot place protector, container at") .. core.chat_send_player(name,
" " .. minetest.pos_to_string(pos)) S("Cannot place protector, container at @1",
core.pos_to_string(pos)))
return return
end end
-- protection check for other mods like Areas -- protection check for other mods like Areas
if minetest.is_protected(pos, name) then if core.is_protected(pos, name) then
minetest.chat_send_player(name, core.chat_send_player(name,
S("Cannot place protector, already protected at") S("Cannot place protector, already protected at @1",
.. " " .. minetest.pos_to_string(pos)) core.pos_to_string(pos)))
return return
end end
-- place protector -- place protector
minetest.set_node(pos, {name = nod, param2 = 1}) core.set_node(pos, {name = nod, param2 = 1})
-- set protector metadata -- set protector metadata
local meta = minetest.get_meta(pos) local meta = core.get_meta(pos)
meta:set_string("owner", name) meta:set_string("owner", name)
meta:set_string("infotext", "Protection (owned by " .. name .. ")") meta:set_string("infotext", "Protection (owned by " .. name .. ")")
@ -146,13 +138,13 @@ minetest.register_craftitem("protector:tool", {
-- copy members across if holding sneak when using tool -- copy members across if holding sneak when using tool
if user:get_player_control().sneak then if user:get_player_control().sneak then
meta:set_string("members", members) meta:set_string("members", members)
meta:set_int("faction_members", faction)
else else
meta:set_string("members", "") meta:set_string("members", "")
end end
minetest.chat_send_player(name, core.chat_send_player(name,
S("Protector placed at") .. S("Protector placed at @1", core.pos_to_string(pos)))
" " .. minetest.pos_to_string(pos))
end end
}) })
@ -160,11 +152,11 @@ minetest.register_craftitem("protector:tool", {
local df = "default:steel_ingot" local df = "default:steel_ingot"
if minetest.get_modpath("mcl_core") then if core.get_modpath("mcl_core") then
df = "mcl_core:iron_ingot" df = "mcl_core:iron_ingot"
end end
minetest.register_craft({ core.register_craft({
output = "protector:tool", output = "protector:tool",
recipe = { recipe = {
{df, df, df}, {df, df, df},