tweak and tidy code
This commit is contained in:
parent
f272486f4f
commit
ce84ac68b2
45
admin.lua
45
admin.lua
@ -1,27 +1,30 @@
|
|||||||
|
|
||||||
local S = protector.intllib
|
-- translation and default name vars
|
||||||
|
|
||||||
|
local S = minetest.get_translator("protector")
|
||||||
local removal_names = ""
|
local removal_names = ""
|
||||||
local replace_names = ""
|
local replace_names = ""
|
||||||
|
|
||||||
|
-- remove protection command
|
||||||
|
|
||||||
minetest.register_chatcommand("protector_remove", {
|
minetest.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
|
if not param or param == "" then
|
||||||
|
|
||||||
minetest.chat_send_player(name,
|
minetest.chat_send_player(name,
|
||||||
S("Protector Names to remove: @1",
|
S("Protector Names to remove: @1", removal_names))
|
||||||
removal_names))
|
|
||||||
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if param == "-" then
|
if param == "-" then
|
||||||
|
|
||||||
minetest.chat_send_player(name,
|
minetest.chat_send_player(name, S("Name List Reset"))
|
||||||
S("Name List Reset"))
|
|
||||||
|
|
||||||
removal_names = ""
|
removal_names = ""
|
||||||
|
|
||||||
@ -32,11 +35,13 @@ minetest.register_chatcommand("protector_remove", {
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- replace protection command
|
||||||
|
|
||||||
minetest.register_chatcommand("protector_replace", {
|
minetest.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},
|
||||||
|
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
|
|
||||||
-- reset list to empty
|
-- reset list to empty
|
||||||
@ -50,13 +55,11 @@ minetest.register_chatcommand("protector_replace", {
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- show name info
|
-- show name info
|
||||||
if param == ""
|
if param == "" and replace_names ~= "" then
|
||||||
and replace_names ~= "" then
|
|
||||||
|
|
||||||
local names = replace_names:split(" ")
|
local names = replace_names:split(" ")
|
||||||
|
|
||||||
minetest.chat_send_player(name,
|
minetest.chat_send_player(name, S("Replacing Protector name @1 with @2",
|
||||||
S("Replacing Protector name @1 with @2",
|
|
||||||
names[1] or "", names[2] or ""))
|
names[1] or "", names[2] or ""))
|
||||||
|
|
||||||
return
|
return
|
||||||
@ -66,18 +69,17 @@ minetest.register_chatcommand("protector_replace", {
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- Abm to remove or replace protectors within active player area
|
||||||
|
|
||||||
minetest.register_abm({
|
minetest.register_abm({
|
||||||
nodenames = {"protector:protect", "protector:protect2", "protector:protect_hidden"},
|
nodenames = {"protector:protect", "protector:protect2", "protector:protect_hidden"},
|
||||||
interval = 6,
|
interval = 6,
|
||||||
chance = 1,
|
chance = 1,
|
||||||
catch_up = false,
|
catch_up = false,
|
||||||
|
|
||||||
action = function(pos, node)
|
action = function(pos, node)
|
||||||
|
|
||||||
if removal_names == ""
|
if removal_names == "" and replace_names == "" then return end
|
||||||
and replace_names == "" then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
|
|
||||||
@ -90,9 +92,7 @@ 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
|
if n == owner then minetest.set_node(pos, {name = "air"}) end
|
||||||
minetest.set_node(pos, {name = "air"})
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -108,16 +108,19 @@ minetest.register_abm({
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
-- get protection radius
|
-- get protection radius (max 30)
|
||||||
|
|
||||||
local r = tonumber(minetest.settings:get("protector_radius")) or 5
|
local r = tonumber(minetest.settings:get("protector_radius")) or 5
|
||||||
|
|
||||||
if r > 30 then r = 30 end
|
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", {
|
minetest.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 = minetest.get_player_by_name(name)
|
||||||
@ -145,8 +148,8 @@ minetest.register_chatcommand("protector_show_area", {
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
-- ability to hide protection blocks (borrowed from doors mod :)
|
-- ability to hide protection blocks (borrowed from doors mod :)
|
||||||
|
|
||||||
minetest.register_node("protector:protect_hidden", {
|
minetest.register_node("protector:protect_hidden", {
|
||||||
description = "Hidden Protector",
|
description = "Hidden Protector",
|
||||||
drawtype = "airlike",
|
drawtype = "airlike",
|
||||||
@ -165,11 +168,11 @@ minetest.register_node("protector:protect_hidden", {
|
|||||||
on_blast = function() end,
|
on_blast = function() end,
|
||||||
-- 1px block inside door hinge near node top
|
-- 1px block inside door hinge near node top
|
||||||
collision_box = {
|
collision_box = {
|
||||||
type = "fixed",
|
type = "fixed", fixed = {-15/32, 13/32, -15/32, -13/32, 1/2, -13/32}
|
||||||
fixed = {-15/32, 13/32, -15/32, -13/32, 1/2, -13/32}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- make own protectors visible in area
|
||||||
|
|
||||||
minetest.register_chatcommand("protector_show", {
|
minetest.register_chatcommand("protector_show", {
|
||||||
params = "",
|
params = "",
|
||||||
@ -206,6 +209,8 @@ minetest.register_chatcommand("protector_show", {
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- make own protectors invisible in area
|
||||||
|
|
||||||
minetest.register_chatcommand("protector_hide", {
|
minetest.register_chatcommand("protector_hide", {
|
||||||
params = "",
|
params = "",
|
||||||
description = S("Hide your nearby protection blocks"),
|
description = S("Hide your nearby protection blocks"),
|
||||||
|
240
doors_chest.lua
240
doors_chest.lua
@ -1,20 +1,22 @@
|
|||||||
|
|
||||||
-- Since the doors mod has changed in the latest daily builds I have taken the
|
-- doors code from an old client re-used
|
||||||
-- WTFPL licenced code from the old doors mod and included an edited version
|
|
||||||
-- within this mod for local use.
|
|
||||||
|
|
||||||
local S = protector.intllib
|
local S = minetest.get_translator("protector")
|
||||||
local F = minetest.formspec_escape
|
local F = minetest.formspec_escape
|
||||||
|
|
||||||
-- MineClone2 support
|
-- MineClone2 support
|
||||||
|
|
||||||
local mcl = minetest.get_modpath("mcl_core")
|
local mcl = minetest.get_modpath("mcl_core")
|
||||||
local mcf = minetest.get_modpath("mcl_formspec")
|
local mcf = minetest.get_modpath("mcl_formspec")
|
||||||
|
|
||||||
-- Are crafts enabled?
|
-- Are crafts enabled?
|
||||||
|
|
||||||
local protector_crafts = minetest.settings:get_bool("protector_crafts") ~= false
|
local protector_crafts = minetest.settings:get_bool("protector_crafts") ~= false
|
||||||
|
|
||||||
-- Registers a door
|
-- Registers a door
|
||||||
function register_door(name, def)
|
|
||||||
|
local function register_door(name, def)
|
||||||
|
|
||||||
def.groups.not_in_creative_inventory = 1
|
def.groups.not_in_creative_inventory = 1
|
||||||
def.groups.handy = 1
|
def.groups.handy = 1
|
||||||
|
|
||||||
@ -24,20 +26,20 @@ function register_door(name, def)
|
|||||||
def.node_box_top = box
|
def.node_box_top = box
|
||||||
def.selection_box_bottom = box
|
def.selection_box_bottom = box
|
||||||
def.selection_box_top = box
|
def.selection_box_top = box
|
||||||
def.sound_close_door = "doors_door_close"
|
|
||||||
def.sound_open_door = "doors_door_open"
|
|
||||||
|
|
||||||
minetest.register_craftitem(name, {
|
minetest.register_craftitem(name, {
|
||||||
description = def.description,
|
description = def.description,
|
||||||
inventory_image = def.inventory_image,
|
inventory_image = def.inventory_image,
|
||||||
|
|
||||||
on_place = function(itemstack, placer, pointed_thing)
|
on_place = function(itemstack, placer, pointed_thing)
|
||||||
|
|
||||||
if pointed_thing.type ~= "node" then
|
if pointed_thing.type ~= "node" then
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
|
|
||||||
local ptu = pointed_thing.under
|
local ptu = pointed_thing.under
|
||||||
local nu = minetest.get_node(ptu)
|
local nu = minetest.get_node(ptu)
|
||||||
|
|
||||||
if minetest.registered_nodes[nu.name]
|
if minetest.registered_nodes[nu.name]
|
||||||
and minetest.registered_nodes[nu.name].on_rightclick then
|
and minetest.registered_nodes[nu.name].on_rightclick then
|
||||||
return minetest.registered_nodes[nu.name].on_rightclick(ptu, nu, placer, itemstack)
|
return minetest.registered_nodes[nu.name].on_rightclick(ptu, nu, placer, itemstack)
|
||||||
@ -45,24 +47,24 @@ function register_door(name, def)
|
|||||||
|
|
||||||
local pt = pointed_thing.above
|
local pt = pointed_thing.above
|
||||||
local pt2 = {x=pt.x, y=pt.y, z=pt.z}
|
local pt2 = {x=pt.x, y=pt.y, z=pt.z}
|
||||||
|
|
||||||
pt2.y = pt2.y+1
|
pt2.y = pt2.y+1
|
||||||
if
|
|
||||||
not minetest.registered_nodes[minetest.get_node(pt).name].buildable_to or
|
if not minetest.registered_nodes[minetest.get_node(pt).name].buildable_to
|
||||||
not minetest.registered_nodes[minetest.get_node(pt2).name].buildable_to or
|
or not minetest.registered_nodes[minetest.get_node(pt2).name].buildable_to
|
||||||
not placer or
|
or not placer or not placer:is_player() then
|
||||||
not placer:is_player()
|
|
||||||
then
|
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
|
|
||||||
if minetest.is_protected(pt, placer:get_player_name()) or
|
if minetest.is_protected(pt, placer:get_player_name())
|
||||||
minetest.is_protected(pt2, placer:get_player_name()) then
|
or minetest.is_protected(pt2, placer:get_player_name()) then
|
||||||
minetest.record_protection_violation(pt, placer:get_player_name())
|
minetest.record_protection_violation(pt, placer:get_player_name())
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
|
|
||||||
local p2 = minetest.dir_to_facedir(placer:get_look_dir())
|
local p2 = minetest.dir_to_facedir(placer:get_look_dir())
|
||||||
local pt3 = {x=pt.x, y=pt.y, z=pt.z}
|
local pt3 = {x=pt.x, y=pt.y, z=pt.z}
|
||||||
|
|
||||||
if p2 == 0 then
|
if p2 == 0 then
|
||||||
pt3.x = pt3.x-1
|
pt3.x = pt3.x-1
|
||||||
elseif p2 == 1 then
|
elseif p2 == 1 then
|
||||||
@ -72,12 +74,14 @@ function register_door(name, def)
|
|||||||
elseif p2 == 3 then
|
elseif p2 == 3 then
|
||||||
pt3.z = pt3.z-1
|
pt3.z = pt3.z-1
|
||||||
end
|
end
|
||||||
|
|
||||||
if minetest.get_item_group(minetest.get_node(pt3).name, "door") == 0 then
|
if minetest.get_item_group(minetest.get_node(pt3).name, "door") == 0 then
|
||||||
minetest.set_node(pt, {name=name.."_b_1", param2=p2})
|
minetest.set_node(pt, {name = name.."_b_1", param2 = p2})
|
||||||
minetest.set_node(pt2, {name=name.."_t_1", param2=p2})
|
minetest.set_node(pt2, {name = name.."_t_1", param2 = p2})
|
||||||
else
|
else
|
||||||
minetest.set_node(pt, {name=name.."_b_2", param2=p2})
|
minetest.set_node(pt, {name = name.."_b_2", param2 = p2})
|
||||||
minetest.set_node(pt2, {name=name.."_t_2", param2=p2})
|
minetest.set_node(pt2, {name = name.."_t_2", param2 = p2})
|
||||||
|
|
||||||
minetest.get_meta(pt):set_int("right", 1)
|
minetest.get_meta(pt):set_int("right", 1)
|
||||||
minetest.get_meta(pt2):set_int("right", 1)
|
minetest.get_meta(pt2):set_int("right", 1)
|
||||||
end
|
end
|
||||||
@ -85,74 +89,73 @@ function register_door(name, def)
|
|||||||
if not minetest.settings:get_bool("creative_mode") then
|
if not minetest.settings:get_bool("creative_mode") then
|
||||||
itemstack:take_item()
|
itemstack:take_item()
|
||||||
end
|
end
|
||||||
|
|
||||||
return itemstack
|
return itemstack
|
||||||
end,
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
local tt = def.tiles_top
|
local tt = def.tiles_top
|
||||||
local tb = def.tiles_bottom
|
local tb = def.tiles_bottom
|
||||||
|
|
||||||
local function after_dig_node(pos, name, digger)
|
local function after_dig_node(pos, name, digger)
|
||||||
|
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
|
|
||||||
if node.name == name then
|
if node.name == name then
|
||||||
minetest.node_dig(pos, node, digger)
|
minetest.node_dig(pos, node, digger)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function on_rightclick(pos, dir, check_name, replace, replace_dir, params)
|
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
|
||||||
|
|
||||||
|
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
|
pos.y = pos.y-dir
|
||||||
|
|
||||||
minetest.swap_node(pos, {name=replace, param2=p2})
|
minetest.swap_node(pos, {name=replace, param2=p2})
|
||||||
|
|
||||||
local snd_1 = def.sound_close_door
|
minetest.sound_play("default_dug_node",
|
||||||
local snd_2 = def.sound_open_door
|
{pos = pos, gain = 0.3, max_hear_distance = 10}, true)
|
||||||
if params[1] == 3 then
|
|
||||||
snd_1 = def.sound_open_door
|
|
||||||
snd_2 = def.sound_close_door
|
|
||||||
end
|
|
||||||
|
|
||||||
if minetest.get_meta(pos):get_int("right") ~= 0 then
|
|
||||||
minetest.sound_play(snd_1, {pos = pos, gain = 0.3, max_hear_distance = 10}, true)
|
|
||||||
else
|
|
||||||
minetest.sound_play(snd_2, {pos = pos, gain = 0.3, max_hear_distance = 10}, true)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function on_rotate(pos, node, dir, user, check_name, mode, new_param2)
|
local function on_rotate(pos, node, dir, user, check_name, mode, new_param2)
|
||||||
|
|
||||||
if mode ~= screwdriver.ROTATE_FACE then
|
if mode ~= screwdriver.ROTATE_FACE then return false end
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
pos.y = pos.y + dir
|
pos.y = pos.y + dir
|
||||||
if minetest.get_node(pos).name ~= check_name then
|
|
||||||
return false
|
if minetest.get_node(pos).name ~= check_name then return false end
|
||||||
end
|
|
||||||
if minetest.is_protected(pos, user:get_player_name()) then
|
if minetest.is_protected(pos, user:get_player_name()) then
|
||||||
minetest.record_protection_violation(pos, user:get_player_name())
|
minetest.record_protection_violation(pos, user:get_player_name())
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
local node2 = minetest.get_node(pos)
|
local node2 = minetest.get_node(pos)
|
||||||
|
|
||||||
node2.param2 = (node2.param2 + 1) % 4
|
node2.param2 = (node2.param2 + 1) % 4
|
||||||
|
|
||||||
minetest.swap_node(pos, node2)
|
minetest.swap_node(pos, node2)
|
||||||
|
|
||||||
pos.y = pos.y - dir
|
pos.y = pos.y - dir
|
||||||
|
|
||||||
node.param2 = (node.param2 + 1) % 4
|
node.param2 = (node.param2 + 1) % 4
|
||||||
|
|
||||||
minetest.swap_node(pos, node)
|
minetest.swap_node(pos, node)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_node(name.."_b_1", {
|
minetest.register_node(name .. "_b_1", {
|
||||||
tiles = {tb[2], tb[2], tb[2], tb[2], tb[1], tb[1].."^[transformfx"},
|
tiles = {tb[2], tb[2], tb[2], tb[2], tb[1], tb[1] .. "^[transformfx"},
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
use_texture_alpha = "clip",
|
use_texture_alpha = "clip",
|
||||||
@ -160,30 +163,29 @@ function register_door(name, def)
|
|||||||
drop = name,
|
drop = name,
|
||||||
drawtype = "nodebox",
|
drawtype = "nodebox",
|
||||||
node_box = {
|
node_box = {
|
||||||
type = "fixed",
|
type = "fixed", fixed = def.node_box_bottom
|
||||||
fixed = def.node_box_bottom
|
|
||||||
},
|
},
|
||||||
selection_box = {
|
selection_box = {
|
||||||
type = "fixed",
|
type = "fixed", fixed = def.selection_box_bottom
|
||||||
fixed = def.selection_box_bottom
|
|
||||||
},
|
},
|
||||||
groups = def.groups,
|
groups = def.groups,
|
||||||
_mcl_hardness = 0.8,
|
_mcl_hardness = 0.8,
|
||||||
_mcl_blast_resistance = 1,
|
_mcl_blast_resistance = 1,
|
||||||
|
|
||||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||||
pos.y = pos.y+1
|
pos.y = pos.y + 1
|
||||||
after_dig_node(pos, name.."_t_1", digger)
|
after_dig_node(pos, name.."_t_1", digger)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_rightclick = function(pos, node, clicker)
|
on_rightclick = function(pos, node, clicker)
|
||||||
|
|
||||||
if not minetest.is_protected(pos, clicker:get_player_name()) then
|
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})
|
on_rightclick(pos, 1, name .. "_t_1", name .. "_b_2", name .. "_t_2", {1,2,3,0})
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_rotate = function(pos, node, user, mode, new_param2)
|
on_rotate = function(pos, node, user, mode, new_param2)
|
||||||
return on_rotate(pos, node, 1, user, name.."_t_1", mode)
|
return on_rotate(pos, node, 1, user, name .. "_t_1", mode)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
sounds = def.sounds,
|
sounds = def.sounds,
|
||||||
@ -191,8 +193,8 @@ function register_door(name, def)
|
|||||||
on_blast = function() end,
|
on_blast = function() end,
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_node(name.."_t_1", {
|
minetest.register_node(name .. "_t_1", {
|
||||||
tiles = {tt[2], tt[2], tt[2], tt[2], tt[1], tt[1].."^[transformfx"},
|
tiles = {tt[2], tt[2], tt[2], tt[2], tt[1], tt[1] .. "^[transformfx"},
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
use_texture_alpha = "clip",
|
use_texture_alpha = "clip",
|
||||||
@ -200,12 +202,10 @@ function register_door(name, def)
|
|||||||
drop = "",
|
drop = "",
|
||||||
drawtype = "nodebox",
|
drawtype = "nodebox",
|
||||||
node_box = {
|
node_box = {
|
||||||
type = "fixed",
|
type = "fixed", fixed = def.node_box_top
|
||||||
fixed = def.node_box_top
|
|
||||||
},
|
},
|
||||||
selection_box = {
|
selection_box = {
|
||||||
type = "fixed",
|
type = "fixed", fixed = def.selection_box_top
|
||||||
fixed = def.selection_box_top
|
|
||||||
},
|
},
|
||||||
groups = def.groups,
|
groups = def.groups,
|
||||||
_mcl_hardness = 0.8,
|
_mcl_hardness = 0.8,
|
||||||
@ -213,17 +213,17 @@ function register_door(name, def)
|
|||||||
|
|
||||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||||
pos.y = pos.y-1
|
pos.y = pos.y-1
|
||||||
after_dig_node(pos, name.."_b_1", digger)
|
after_dig_node(pos, name .. "_b_1", digger)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_rightclick = function(pos, node, clicker)
|
on_rightclick = function(pos, node, clicker)
|
||||||
if not minetest.is_protected(pos, clicker:get_player_name()) then
|
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})
|
on_rightclick(pos, -1, name .. "_b_1", name .. "_t_2", name .. "_b_2", {1,2,3,0})
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_rotate = function(pos, node, user, mode, new_param2)
|
on_rotate = function(pos, node, user, mode, new_param2)
|
||||||
return on_rotate(pos, node, -1, user, name.."_b_1", mode)
|
return on_rotate(pos, node, -1, user, name .. "_b_1", mode)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
sounds = def.sounds,
|
sounds = def.sounds,
|
||||||
@ -232,7 +232,7 @@ function register_door(name, def)
|
|||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_node(name.."_b_2", {
|
minetest.register_node(name.."_b_2", {
|
||||||
tiles = {tb[2], tb[2], tb[2], tb[2], tb[1].."^[transformfx", tb[1]},
|
tiles = {tb[2], tb[2], tb[2], tb[2], tb[1] .. "^[transformfx", tb[1]},
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
use_texture_alpha = "clip",
|
use_texture_alpha = "clip",
|
||||||
@ -240,30 +240,28 @@ function register_door(name, def)
|
|||||||
drop = name,
|
drop = name,
|
||||||
drawtype = "nodebox",
|
drawtype = "nodebox",
|
||||||
node_box = {
|
node_box = {
|
||||||
type = "fixed",
|
type = "fixed", fixed = def.node_box_bottom
|
||||||
fixed = def.node_box_bottom
|
|
||||||
},
|
},
|
||||||
selection_box = {
|
selection_box = {
|
||||||
type = "fixed",
|
type = "fixed", fixed = def.selection_box_bottom
|
||||||
fixed = def.selection_box_bottom
|
|
||||||
},
|
},
|
||||||
groups = def.groups,
|
groups = def.groups,
|
||||||
_mcl_hardness = 0.8,
|
_mcl_hardness = 0.8,
|
||||||
_mcl_blast_resistance = 1,
|
_mcl_blast_resistance = 1,
|
||||||
|
|
||||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||||
pos.y = pos.y+1
|
pos.y = pos.y + 1
|
||||||
after_dig_node(pos, name.."_t_2", digger)
|
after_dig_node(pos, name .. "_t_2", digger)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_rightclick = function(pos, node, clicker)
|
on_rightclick = function(pos, node, clicker)
|
||||||
if not minetest.is_protected(pos, clicker:get_player_name()) then
|
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})
|
on_rightclick(pos, 1, name .. "_t_2", name .. "_b_1", name .. "_t_1", {3,0,1,2})
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_rotate = function(pos, node, user, mode, new_param2)
|
on_rotate = function(pos, node, user, mode, new_param2)
|
||||||
return on_rotate(pos, node, 1, user, name.."_t_2", mode)
|
return on_rotate(pos, node, 1, user, name .. "_t_2", mode)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
sounds = def.sounds,
|
sounds = def.sounds,
|
||||||
@ -271,8 +269,8 @@ function register_door(name, def)
|
|||||||
on_blast = function() end,
|
on_blast = function() end,
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_node(name.."_t_2", {
|
minetest.register_node(name .. "_t_2", {
|
||||||
tiles = {tt[2], tt[2], tt[2], tt[2], tt[1].."^[transformfx", tt[1]},
|
tiles = {tt[2], tt[2], tt[2], tt[2], tt[1] .. "^[transformfx", tt[1]},
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
use_texture_alpha = "clip",
|
use_texture_alpha = "clip",
|
||||||
@ -280,30 +278,28 @@ function register_door(name, def)
|
|||||||
drop = "",
|
drop = "",
|
||||||
drawtype = "nodebox",
|
drawtype = "nodebox",
|
||||||
node_box = {
|
node_box = {
|
||||||
type = "fixed",
|
type = "fixed", fixed = def.node_box_top
|
||||||
fixed = def.node_box_top
|
|
||||||
},
|
},
|
||||||
selection_box = {
|
selection_box = {
|
||||||
type = "fixed",
|
type = "fixed", fixed = def.selection_box_top
|
||||||
fixed = def.selection_box_top
|
|
||||||
},
|
},
|
||||||
groups = def.groups,
|
groups = def.groups,
|
||||||
_mcl_hardness = 0.8,
|
_mcl_hardness = 0.8,
|
||||||
_mcl_blast_resistance = 1,
|
_mcl_blast_resistance = 1,
|
||||||
|
|
||||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||||
pos.y = pos.y-1
|
pos.y = pos.y - 1
|
||||||
after_dig_node(pos, name.."_b_2", digger)
|
after_dig_node(pos, name .. "_b_2", digger)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_rightclick = function(pos, node, clicker)
|
on_rightclick = function(pos, node, clicker)
|
||||||
if not minetest.is_protected(pos, clicker:get_player_name()) then
|
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})
|
on_rightclick(pos, -1, name .. "_b_2", name .. "_t_1", name .. "_b_1", {3,0,1,2})
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_rotate = function(pos, node, user, mode, new_param2)
|
on_rotate = function(pos, node, user, mode, new_param2)
|
||||||
return on_rotate(pos, node, -1, user, name.."_b_2", mode)
|
return on_rotate(pos, node, -1, user, name .. "_b_2", mode)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
sounds = def.sounds,
|
sounds = def.sounds,
|
||||||
@ -319,10 +315,7 @@ local name = "protector:door_wood"
|
|||||||
register_door(name, {
|
register_door(name, {
|
||||||
description = S("Protected Wooden Door"),
|
description = S("Protected Wooden Door"),
|
||||||
inventory_image = "doors_wood.png^protector_logo.png",
|
inventory_image = "doors_wood.png^protector_logo.png",
|
||||||
groups = {
|
groups = {snappy = 1, choppy = 2, dig_immediate = 2, unbreakable = 1, axey = 1},
|
||||||
snappy = 1, choppy = 2, dig_immediate = 2,
|
|
||||||
unbreakable = 1, axey = 1, --door = 1
|
|
||||||
},
|
|
||||||
tiles_bottom = {"doors_wood_b.png^protector_logo.png", "doors_brown.png"},
|
tiles_bottom = {"doors_wood_b.png^protector_logo.png", "doors_brown.png"},
|
||||||
tiles_top = {"doors_wood_a.png", "doors_brown.png"},
|
tiles_top = {"doors_wood_a.png", "doors_brown.png"},
|
||||||
sounds = default.node_sound_wood_defaults(),
|
sounds = default.node_sound_wood_defaults(),
|
||||||
@ -330,7 +323,9 @@ register_door(name, {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if protector_crafts then
|
if protector_crafts then
|
||||||
|
|
||||||
if mcl then
|
if mcl then
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = name,
|
output = name,
|
||||||
recipe = {
|
recipe = {
|
||||||
@ -365,7 +360,7 @@ register_door(name, {
|
|||||||
inventory_image = "doors_steel.png^protector_logo.png",
|
inventory_image = "doors_steel.png^protector_logo.png",
|
||||||
groups = {
|
groups = {
|
||||||
snappy = 1, bendy = 2, cracky = 1,
|
snappy = 1, bendy = 2, cracky = 1,
|
||||||
level = mcl and 0 or 2, pickaxey = 2, unbreakable = 1, -- door = 1
|
level = (mcl and 0 or 2), pickaxey = 2, unbreakable = 1
|
||||||
},
|
},
|
||||||
tiles_bottom = {"doors_steel_b.png^protector_logo.png", "doors_grey.png"},
|
tiles_bottom = {"doors_steel_b.png^protector_logo.png", "doors_grey.png"},
|
||||||
tiles_top = {"doors_steel_a.png", "doors_grey.png"},
|
tiles_top = {"doors_steel_a.png", "doors_grey.png"},
|
||||||
@ -404,21 +399,20 @@ end
|
|||||||
|
|
||||||
----trapdoor----
|
----trapdoor----
|
||||||
|
|
||||||
function register_trapdoor(name, def)
|
local function register_trapdoor(name, def)
|
||||||
|
|
||||||
local name_closed = name
|
local name_closed = name
|
||||||
local name_opened = name.."_open"
|
local name_opened = name .. "_open"
|
||||||
|
|
||||||
def.on_rightclick = function (pos, node, clicker, itemstack, pointed_thing)
|
def.on_rightclick = function (pos, node, clicker, itemstack, pointed_thing)
|
||||||
if minetest.is_protected(pos, clicker:get_player_name()) then
|
|
||||||
return
|
if minetest.is_protected(pos, clicker:get_player_name()) then return end
|
||||||
end
|
|
||||||
local newname = node.name == name_closed and name_opened or name_closed
|
local newname = node.name == name_closed and name_opened or name_closed
|
||||||
local sound = false
|
|
||||||
if node.name == name_closed then sound = "doors_door_open" end
|
minetest.sound_play("default_dug_node",
|
||||||
if node.name == name_opened then sound = "doors_door_close" end
|
{pos = pos, gain = 0.3, max_hear_distance = 10}, true)
|
||||||
if sound then
|
|
||||||
minetest.sound_play(sound, {pos = pos, gain = 0.3, max_hear_distance = 10}, true)
|
|
||||||
end
|
|
||||||
minetest.swap_node(pos, {name = newname, param1 = node.param1, param2 = node.param2})
|
minetest.swap_node(pos, {name = newname, param1 = node.param1, param2 = node.param2})
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -433,23 +427,19 @@ function register_trapdoor(name, def)
|
|||||||
local def_closed = table.copy(def)
|
local def_closed = table.copy(def)
|
||||||
|
|
||||||
def_closed.node_box = {
|
def_closed.node_box = {
|
||||||
type = "fixed",
|
type = "fixed", fixed = {-0.5, -0.5, -0.5, 0.5, -6/16, 0.5}
|
||||||
fixed = {-0.5, -0.5, -0.5, 0.5, -6/16, 0.5}
|
|
||||||
}
|
}
|
||||||
def_closed.selection_box = {
|
def_closed.selection_box = {
|
||||||
type = "fixed",
|
type = "fixed", fixed = {-0.5, -0.5, -0.5, 0.5, -6/16, 0.5}
|
||||||
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_closed.tiles = { def.tile_front, def.tile_front, def.tile_side, def.tile_side,
|
||||||
def.tile_side, def.tile_side }
|
def.tile_side, def.tile_side }
|
||||||
|
|
||||||
def_opened.node_box = {
|
def_opened.node_box = {
|
||||||
type = "fixed",
|
type = "fixed", fixed = {-0.5, -0.5, 6/16, 0.5, 0.5, 0.5}
|
||||||
fixed = {-0.5, -0.5, 6/16, 0.5, 0.5, 0.5}
|
|
||||||
}
|
}
|
||||||
def_opened.selection_box = {
|
def_opened.selection_box = {
|
||||||
type = "fixed",
|
type = "fixed", fixed = {-0.5, -0.5, 6/16, 0.5, 0.5, 0.5}
|
||||||
fixed = {-0.5, -0.5, 6/16, 0.5, 0.5, 0.5}
|
|
||||||
}
|
}
|
||||||
def_opened.tiles = { def.tile_side, def.tile_side,
|
def_opened.tiles = { def.tile_side, def.tile_side,
|
||||||
def.tile_side .. "^[transform3",
|
def.tile_side .. "^[transform3",
|
||||||
@ -471,17 +461,16 @@ register_trapdoor("protector:trapdoor", {
|
|||||||
wield_image = "doors_trapdoor.png^protector_logo.png",
|
wield_image = "doors_trapdoor.png^protector_logo.png",
|
||||||
tile_front = "doors_trapdoor.png^protector_logo.png",
|
tile_front = "doors_trapdoor.png^protector_logo.png",
|
||||||
tile_side = "doors_trapdoor_side.png",
|
tile_side = "doors_trapdoor_side.png",
|
||||||
groups = {
|
groups = {snappy = 1, choppy = 2, dig_immediate = 2, unbreakable = 1, axey = 1},
|
||||||
snappy = 1, choppy = 2, dig_immediate = 2,
|
|
||||||
unbreakable = 1, axey = 1, --door = 1
|
|
||||||
},
|
|
||||||
_mcl_hardness = 0.8,
|
_mcl_hardness = 0.8,
|
||||||
_mcl_blast_resistance = 1,
|
_mcl_blast_resistance = 1,
|
||||||
sounds = default.node_sound_wood_defaults(),
|
sounds = default.node_sound_wood_defaults(),
|
||||||
})
|
})
|
||||||
|
|
||||||
if protector_crafts then
|
if protector_crafts then
|
||||||
|
|
||||||
if mcl then
|
if mcl then
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = "protector:trapdoor",
|
output = "protector:trapdoor",
|
||||||
recipe = {
|
recipe = {
|
||||||
@ -515,8 +504,8 @@ register_trapdoor("protector:trapdoor_steel", {
|
|||||||
tile_front = "doors_trapdoor_steel.png^protector_logo.png",
|
tile_front = "doors_trapdoor_steel.png^protector_logo.png",
|
||||||
tile_side = "doors_trapdoor_steel_side.png",
|
tile_side = "doors_trapdoor_steel_side.png",
|
||||||
groups = {
|
groups = {
|
||||||
snappy = 1, bendy = 2, cracky = 1, melty = 2, level = mcl and 0 or 2,
|
snappy = 1, bendy = 2, cracky = 1, melty = 2, level = (mcl and 0 or 2),
|
||||||
unbreakable = 1, pickaxey = 2, --door = 1
|
unbreakable = 1, pickaxey = 2
|
||||||
},
|
},
|
||||||
_mcl_hardness = 1,
|
_mcl_hardness = 1,
|
||||||
_mcl_blast_resistance = 1,
|
_mcl_blast_resistance = 1,
|
||||||
@ -524,6 +513,7 @@ register_trapdoor("protector:trapdoor_steel", {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if protector_crafts then
|
if protector_crafts then
|
||||||
|
|
||||||
if mcl then
|
if mcl then
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = "protector:trapdoor_steel",
|
output = "protector:trapdoor_steel",
|
||||||
@ -592,23 +582,20 @@ minetest.register_node("protector:chest", {
|
|||||||
on_metadata_inventory_put = function(pos, listname, index, stack, player)
|
on_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||||
|
|
||||||
minetest.log("action", player:get_player_name() ..
|
minetest.log("action", player:get_player_name() ..
|
||||||
" moves stuff to protected chest at " ..
|
" moves stuff to protected chest at " .. minetest.pos_to_string(pos))
|
||||||
minetest.pos_to_string(pos))
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_metadata_inventory_take = function(pos, listname, index, stack, player)
|
on_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||||
|
|
||||||
minetest.log("action", player:get_player_name() ..
|
minetest.log("action", player:get_player_name() ..
|
||||||
" takes stuff from protected chest at " ..
|
" takes stuff from protected chest at " .. minetest.pos_to_string(pos))
|
||||||
minetest.pos_to_string(pos))
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_metadata_inventory_move = function(
|
on_metadata_inventory_move = function(
|
||||||
pos, from_list, from_index, to_list, to_index, count, player)
|
pos, from_list, from_index, to_list, to_index, count, player)
|
||||||
|
|
||||||
minetest.log("action", player:get_player_name() ..
|
minetest.log("action", player:get_player_name() ..
|
||||||
" moves stuff inside protected chest at " ..
|
" moves stuff inside protected chest at " .. minetest.pos_to_string(pos))
|
||||||
minetest.pos_to_string(pos))
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||||
@ -645,11 +632,7 @@ minetest.register_node("protector:chest", {
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos) ; if not meta then return end
|
||||||
|
|
||||||
if not meta then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local spos = pos.x .. "," .. pos.y .. "," ..pos.z
|
local spos = pos.x .. "," .. pos.y .. "," ..pos.z
|
||||||
local formspec
|
local formspec
|
||||||
@ -701,7 +684,8 @@ minetest.register_node("protector:chest", {
|
|||||||
})
|
})
|
||||||
|
|
||||||
-- Container transfer helper
|
-- Container transfer helper
|
||||||
local to_from = function(src, dst)
|
|
||||||
|
local function to_from(src, dst)
|
||||||
|
|
||||||
local stack, item, leftover
|
local stack, item, leftover
|
||||||
local size = dst:get_size("main")
|
local size = dst:get_size("main")
|
||||||
@ -728,16 +712,12 @@ end
|
|||||||
|
|
||||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
|
|
||||||
if string.sub(formname, 0, 16) ~= "protector:chest_" then
|
if string.sub(formname, 0, 16) ~= "protector:chest_" then return end
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local pos_s = string.sub(formname, 17)
|
local pos_s = string.sub(formname, 17)
|
||||||
local pos = minetest.string_to_pos(pos_s)
|
local pos = minetest.string_to_pos(pos_s)
|
||||||
|
|
||||||
if minetest.is_protected(pos, player:get_player_name()) then
|
if minetest.is_protected(pos, player:get_player_name()) then return end
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local meta = minetest.get_meta(pos) ; if not meta 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 chest_inv = meta:get_inventory() ; if not chest_inv then return end
|
||||||
|
15
hud.lua
15
hud.lua
@ -1,23 +1,27 @@
|
|||||||
|
|
||||||
local S = protector.intllib
|
-- translation and protector radius
|
||||||
|
|
||||||
|
local S = minetest.get_translator("protector")
|
||||||
local radius = (tonumber(minetest.settings:get("protector_radius")) or 5)
|
local radius = (tonumber(minetest.settings:get("protector_radius")) or 5)
|
||||||
|
|
||||||
-- radius limiter (minetest cannot handle node volume of more than 4096000)
|
-- radius limiter (minetest cannot handle node volume of more than 4096000)
|
||||||
|
|
||||||
if radius > 30 then radius = 30 end
|
if radius > 30 then radius = 30 end
|
||||||
|
|
||||||
|
-- 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(minetest.settings:get("protector_hud_interval")) or 5)
|
||||||
local hud_style = minetest.has_feature("hud_def_type_field")
|
local hud_style = minetest.has_feature("hud_def_type_field")
|
||||||
|
|
||||||
if hud_interval > 0 then
|
if hud_interval > 0 then
|
||||||
|
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
|
|
||||||
-- every 5 seconds
|
-- every 5 seconds
|
||||||
hud_timer = hud_timer + dtime
|
hud_timer = hud_timer + dtime
|
||||||
if hud_timer < hud_interval then
|
if hud_timer < hud_interval then return end
|
||||||
return
|
|
||||||
end
|
|
||||||
hud_timer = 0
|
hud_timer = 0
|
||||||
|
|
||||||
for _, player in pairs(minetest.get_connected_players()) do
|
for _, player in pairs(minetest.get_connected_players()) do
|
||||||
@ -32,6 +36,7 @@ minetest.register_globalstep(function(dtime)
|
|||||||
{"protector:protect","protector:protect2", "protector:protect_hidden"})
|
{"protector:protect","protector:protect2", "protector:protect_hidden"})
|
||||||
|
|
||||||
if #protectors > 0 then
|
if #protectors > 0 then
|
||||||
|
|
||||||
local npos = protectors[1]
|
local npos = protectors[1]
|
||||||
local meta = minetest.get_meta(npos)
|
local meta = minetest.get_meta(npos)
|
||||||
local nodeowner = meta:get_string("owner")
|
local nodeowner = meta:get_string("owner")
|
||||||
@ -72,4 +77,4 @@ minetest.register_on_leaveplayer(function(player)
|
|||||||
hud[player:get_player_name()] = nil
|
hud[player:get_player_name()] = nil
|
||||||
end)
|
end)
|
||||||
|
|
||||||
end
|
end -- END hud_interval > 0
|
||||||
|
274
init.lua
274
init.lua
@ -1,12 +1,14 @@
|
|||||||
|
|
||||||
-- default support (for use with MineClone2 and other [games]
|
-- default support (for use with MineClone2 and other [games]
|
||||||
default = default or {
|
|
||||||
|
if not minetest.global_exists("default") then
|
||||||
|
|
||||||
|
default = {
|
||||||
node_sound_stone_defaults = function(table) end,
|
node_sound_stone_defaults = function(table) end,
|
||||||
node_sound_wood_defaults = function(table) end,
|
node_sound_wood_defaults = function(table) end,
|
||||||
gui_bg = "",
|
gui_bg = "", gui_bg_img = "", gui_slots = ""
|
||||||
gui_bg_img = "",
|
}
|
||||||
gui_slots = ""
|
end
|
||||||
}
|
|
||||||
|
|
||||||
if minetest.get_modpath("mcl_sounds") then
|
if minetest.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
|
||||||
@ -14,23 +16,20 @@ if minetest.get_modpath("mcl_sounds") then
|
|||||||
default.node_sound_metal_defaults = mcl_sounds.node_sound_metal_defaults
|
default.node_sound_metal_defaults = mcl_sounds.node_sound_metal_defaults
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- modpath, formspec helper and translator
|
||||||
|
|
||||||
local MP = minetest.get_modpath(minetest.get_current_modname())
|
local MP = minetest.get_modpath(minetest.get_current_modname())
|
||||||
local F = minetest.formspec_escape
|
local F = minetest.formspec_escape
|
||||||
|
|
||||||
-- Translation support
|
|
||||||
local S = minetest.get_translator("protector")
|
local S = minetest.get_translator("protector")
|
||||||
|
|
||||||
-- Load support for factions
|
-- global table
|
||||||
|
|
||||||
|
protector = { mod = "redo", modpath = MP }
|
||||||
|
|
||||||
|
-- settings
|
||||||
|
|
||||||
local factions_available = minetest.global_exists("factions")
|
local factions_available = minetest.global_exists("factions")
|
||||||
|
|
||||||
protector = {
|
|
||||||
mod = "redo",
|
|
||||||
modpath = MP,
|
|
||||||
intllib = S
|
|
||||||
}
|
|
||||||
|
|
||||||
local protector_max_share_count = 12
|
local protector_max_share_count = 12
|
||||||
-- get minetest.conf settings
|
|
||||||
local protector_radius = tonumber(minetest.settings:get("protector_radius")) or 5
|
local protector_radius = tonumber(minetest.settings:get("protector_radius")) or 5
|
||||||
local protector_flip = minetest.settings:get_bool("protector_flip") or false
|
local protector_flip = minetest.settings:get_bool("protector_flip") or false
|
||||||
local protector_hurt = tonumber(minetest.settings:get("protector_hurt")) or 0
|
local protector_hurt = tonumber(minetest.settings:get("protector_hurt")) or 0
|
||||||
@ -41,40 +40,40 @@ local protector_recipe = minetest.settings:get_bool("protector_recipe") ~= false
|
|||||||
local protector_msg = minetest.settings:get_bool("protector_msg") ~= 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
|
||||||
|
|
||||||
|
|
||||||
-- get static spawn position
|
-- get static spawn position
|
||||||
|
|
||||||
local statspawn = minetest.string_to_pos(minetest.settings:get("static_spawnpoint"))
|
local statspawn = minetest.string_to_pos(minetest.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
|
||||||
local get_member_list = function(meta)
|
|
||||||
|
local function get_member_list(meta)
|
||||||
|
|
||||||
return meta:get_string("members"):split(" ")
|
return meta:get_string("members"):split(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- write member list table in protector meta as string
|
-- write member list table in protector meta as string
|
||||||
local set_member_list = function(meta, list)
|
|
||||||
|
local function set_member_list(meta, list)
|
||||||
|
|
||||||
meta:set_string("members", table.concat(list, " "))
|
meta:set_string("members", table.concat(list, " "))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- check for owner name
|
-- check for owner name
|
||||||
local is_owner = function(meta, name)
|
|
||||||
|
local function is_owner(meta, name)
|
||||||
|
|
||||||
return name == meta:get_string("owner")
|
return name == meta:get_string("owner")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- check for member name
|
-- check for member name
|
||||||
local is_member = function(meta, name)
|
|
||||||
|
|
||||||
if factions_available
|
local function is_member(meta, name)
|
||||||
and meta:get_int("faction_members") == 1 then
|
|
||||||
|
if factions_available and meta:get_int("faction_members") == 1 then
|
||||||
|
|
||||||
if factions.version == nil then
|
if factions.version == nil then
|
||||||
|
|
||||||
@ -103,48 +102,37 @@ local is_member = function(meta, name)
|
|||||||
|
|
||||||
for _, n in pairs(get_member_list(meta)) do
|
for _, n in pairs(get_member_list(meta)) do
|
||||||
|
|
||||||
if n == name then
|
if n == name then return true end
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- add player name to table as member
|
-- add player name to table as member
|
||||||
local add_member = function(meta, name)
|
|
||||||
|
local function add_member(meta, name)
|
||||||
|
|
||||||
-- Validate player name for MT compliance
|
-- Validate player name for MT compliance
|
||||||
if name ~= string.match(name, "[%w_-]+") then
|
if name ~= string.match(name, "[%w_-]+") then return end
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Constant (20) defined by player.h
|
-- Constant (20) defined by player.h
|
||||||
if name:len() > 25 then
|
if name:len() > 25 then return end
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
-- does name already exist?
|
-- does name already exist?
|
||||||
if is_owner(meta, name)
|
if is_owner(meta, name) or is_member(meta, name) then return end
|
||||||
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
|
if #list >= protector_max_share_count then return end
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
table.insert(list, name)
|
table.insert(list, name)
|
||||||
|
|
||||||
set_member_list(meta, list)
|
set_member_list(meta, list)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- remove player name from table
|
-- remove player name from table
|
||||||
local del_member = function(meta, name)
|
|
||||||
|
local function del_member(meta, name)
|
||||||
|
|
||||||
local list = get_member_list(meta)
|
local list = get_member_list(meta)
|
||||||
|
|
||||||
@ -159,9 +147,9 @@ local del_member = function(meta, name)
|
|||||||
set_member_list(meta, list)
|
set_member_list(meta, list)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- protector interface
|
-- protector interface
|
||||||
local protector_formspec = function(meta)
|
|
||||||
|
local function protector_formspec(meta)
|
||||||
|
|
||||||
local formspec = "size[8,7]"
|
local formspec = "size[8,7]"
|
||||||
.. default.gui_bg
|
.. default.gui_bg
|
||||||
@ -201,9 +189,7 @@ local protector_formspec = function(meta)
|
|||||||
.. ";" .. (meta:get_int("faction_members") == 1 and
|
.. ";" .. (meta:get_int("faction_members") == 1 and
|
||||||
"true" or "false") .. "]"
|
"true" or "false") .. "]"
|
||||||
|
|
||||||
if npp > 8 then
|
if npp > 8 then npp = 8 end
|
||||||
npp = 8
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
for n = 1, #members do
|
for n = 1, #members do
|
||||||
@ -240,35 +226,26 @@ local protector_formspec = function(meta)
|
|||||||
return formspec
|
return formspec
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- check if pos is inside a protected spawn area
|
-- check if pos is inside a protected spawn area
|
||||||
local inside_spawn = function(pos, radius)
|
|
||||||
|
|
||||||
if protector_spawn <= 0 then
|
local function inside_spawn(pos, radius)
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
if pos.x < statspawn.x + radius
|
if protector_spawn <= 0 then return false end
|
||||||
and pos.x > statspawn.x - radius
|
|
||||||
and pos.y < statspawn.y + radius
|
if pos.x < statspawn.x + radius and pos.x > statspawn.x - radius
|
||||||
and pos.y > statspawn.y - radius
|
and pos.y < statspawn.y + radius and pos.y > statspawn.y - radius
|
||||||
and pos.z < statspawn.z + radius
|
and pos.z < statspawn.z + radius and pos.z > statspawn.z - radius then
|
||||||
and pos.z > statspawn.z - radius then
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- show protection message if enabled
|
-- show protection message if enabled
|
||||||
local show_msg = function(player, msg)
|
|
||||||
|
local function show_msg(player, 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
|
if protector_msg == false or not player or player == "" then return end
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
minetest.chat_send_player(player, msg)
|
minetest.chat_send_player(player, msg)
|
||||||
end
|
end
|
||||||
@ -280,11 +257,9 @@ end
|
|||||||
-- 2 for "This area is owned by <owner>.
|
-- 2 for "This area is owned by <owner>.
|
||||||
-- 3 for checking protector overlaps
|
-- 3 for checking protector overlaps
|
||||||
|
|
||||||
protector.can_dig = function(r, pos, digger, onlyowner, infolevel)
|
function protector.can_dig(r, pos, digger, onlyowner, infolevel)
|
||||||
|
|
||||||
if not digger or not pos then
|
if not digger or not pos then return false end
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
-- protector_bypass privileged users can override protection
|
-- protector_bypass privileged users can override protection
|
||||||
if infolevel == 1
|
if infolevel == 1
|
||||||
@ -298,8 +273,7 @@ protector.can_dig = function(r, pos, digger, onlyowner, infolevel)
|
|||||||
-- is spawn area protected ?
|
-- is spawn area protected ?
|
||||||
if inside_spawn(pos, protector_spawn) then
|
if inside_spawn(pos, protector_spawn) then
|
||||||
|
|
||||||
show_msg(digger,
|
show_msg(digger, 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))
|
minetest.pos_to_string(statspawn), protector_spawn))
|
||||||
|
|
||||||
return false
|
return false
|
||||||
@ -325,8 +299,7 @@ protector.can_dig = function(r, pos, digger, onlyowner, infolevel)
|
|||||||
-- and you aren't on the member list
|
-- and you aren't on the member list
|
||||||
if onlyowner or not is_member(meta, digger) then
|
if onlyowner or not is_member(meta, digger) then
|
||||||
|
|
||||||
show_msg(digger,
|
show_msg(digger, S("This area is owned by @1", owner) .. "!")
|
||||||
S("This area is owned by @1", owner) .. "!")
|
|
||||||
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
@ -342,7 +315,6 @@ protector.can_dig = function(r, pos, digger, onlyowner, infolevel)
|
|||||||
S("Protection located at: @1", minetest.pos_to_string(pos[n])))
|
S("Protection located at: @1", minetest.pos_to_string(pos[n])))
|
||||||
|
|
||||||
if members ~= "" then
|
if members ~= "" then
|
||||||
|
|
||||||
minetest.chat_send_player(digger, S("Members: @1.", members))
|
minetest.chat_send_player(digger, S("Members: @1.", members))
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -355,7 +327,6 @@ protector.can_dig = function(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."))
|
minetest.chat_send_player(digger, S("This area is not protected."))
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -365,8 +336,8 @@ protector.can_dig = function(r, pos, digger, onlyowner, infolevel)
|
|||||||
return true
|
return true
|
||||||
end
|
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)
|
minetest.register_on_protection_violation(function(pos, name)
|
||||||
|
|
||||||
local player = minetest.get_player_by_name(name)
|
local player = minetest.get_player_by_name(name)
|
||||||
@ -401,21 +372,18 @@ minetest.register_on_protection_violation(function(pos, name)
|
|||||||
local pla_pos = player:get_pos()
|
local pla_pos = player:get_pos()
|
||||||
|
|
||||||
if pos.y < pla_pos.y then
|
if pos.y < pla_pos.y then
|
||||||
|
player:set_pos({x = pla_pos.x, y = pla_pos.y + 0.8, z = pla_pos.z})
|
||||||
player:set_pos({
|
|
||||||
x = pla_pos.x,
|
|
||||||
y = pla_pos.y + 0.8,
|
|
||||||
z = pla_pos.z
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
-- backup old is_protected function
|
||||||
|
|
||||||
local old_is_protected = minetest.is_protected
|
local old_is_protected = minetest.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 minetest.is_protected(pos, digger)
|
||||||
|
|
||||||
digger = digger or "" -- nil check
|
digger = digger or "" -- nil check
|
||||||
@ -429,13 +397,11 @@ function minetest.is_protected(pos, digger)
|
|||||||
return old_is_protected(pos, digger)
|
return old_is_protected(pos, digger)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- make sure protection block doesn't overlap another protector's area
|
-- make sure protection block doesn't overlap another protector's area
|
||||||
local check_overlap = function(itemstack, placer, pointed_thing)
|
|
||||||
|
|
||||||
if pointed_thing.type ~= "node" then
|
local function check_overlap(itemstack, placer, pointed_thing)
|
||||||
return itemstack
|
|
||||||
end
|
if pointed_thing.type ~= "node" then return itemstack end
|
||||||
|
|
||||||
local pos = pointed_thing.above
|
local pos = pointed_thing.above
|
||||||
local name = placer:get_player_name()
|
local name = placer:get_player_name()
|
||||||
@ -460,28 +426,28 @@ local check_overlap = function(itemstack, placer, pointed_thing)
|
|||||||
end
|
end
|
||||||
|
|
||||||
return minetest.item_place(itemstack, placer, pointed_thing)
|
return minetest.item_place(itemstack, placer, pointed_thing)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- remove protector display entities
|
-- remove protector display entities
|
||||||
local del_display = function(pos)
|
|
||||||
|
local function del_display(pos)
|
||||||
|
|
||||||
local objects = minetest.get_objects_inside_radius(pos, 0.5)
|
local objects = minetest.get_objects_inside_radius(pos, 0.5)
|
||||||
|
|
||||||
for _, v in ipairs(objects) do
|
for _, v in ipairs(objects) do
|
||||||
|
|
||||||
if v and v:get_luaentity()
|
if v and v:get_luaentity() and v:get_luaentity().name == "protector:display" then
|
||||||
and v:get_luaentity().name == "protector:display" then
|
|
||||||
v:remove()
|
v:remove()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- temporary pos store
|
-- temporary position store
|
||||||
|
|
||||||
local player_pos = {}
|
local player_pos = {}
|
||||||
|
|
||||||
-- protection node
|
-- protection node
|
||||||
|
|
||||||
minetest.register_node("protector:protect", {
|
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",
|
drawtype = "nodebox",
|
||||||
@ -497,10 +463,7 @@ minetest.register_node("protector:protect", {
|
|||||||
light_source = 4,
|
light_source = 4,
|
||||||
|
|
||||||
node_box = {
|
node_box = {
|
||||||
type = "fixed",
|
type = "fixed", fixed = {{-0.499 ,-0.499, -0.499, 0.499, 0.499, 0.499}}
|
||||||
fixed = {
|
|
||||||
{-0.499 ,-0.499, -0.499, 0.499, 0.499, 0.499}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
on_place = check_overlap,
|
on_place = check_overlap,
|
||||||
@ -517,9 +480,7 @@ minetest.register_node("protector:protect", {
|
|||||||
|
|
||||||
on_use = function(itemstack, user, pointed_thing)
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
|
|
||||||
if pointed_thing.type ~= "node" then
|
if pointed_thing.type ~= "node" then return end
|
||||||
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)
|
||||||
@ -530,8 +491,7 @@ minetest.register_node("protector:protect", {
|
|||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local name = clicker:get_player_name()
|
local name = clicker:get_player_name()
|
||||||
|
|
||||||
if meta
|
if meta and protector.can_dig(1, pos, name, true, 1) then
|
||||||
and protector.can_dig(1, pos, name, true, 1) then
|
|
||||||
|
|
||||||
player_pos[name] = pos
|
player_pos[name] = pos
|
||||||
|
|
||||||
@ -541,9 +501,7 @@ minetest.register_node("protector:protect", {
|
|||||||
|
|
||||||
on_punch = function(pos, node, puncher)
|
on_punch = function(pos, node, puncher)
|
||||||
|
|
||||||
if minetest.is_protected(pos, puncher:get_player_name()) then
|
if minetest.is_protected(pos, puncher:get_player_name()) then return end
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
minetest.add_entity(pos, "protector:display")
|
minetest.add_entity(pos, "protector:display")
|
||||||
end,
|
end,
|
||||||
@ -559,32 +517,29 @@ minetest.register_node("protector:protect", {
|
|||||||
})
|
})
|
||||||
|
|
||||||
-- default recipe and alternative for MineClone2
|
-- default recipe and alternative for MineClone2
|
||||||
|
|
||||||
if protector_recipe then
|
if protector_recipe then
|
||||||
|
|
||||||
if minetest.registered_items["default:stone"] then
|
local item_gold = "default:gold_ingot"
|
||||||
|
local item_stone = "default:stone"
|
||||||
|
|
||||||
minetest.register_craft({
|
if minetest.get_modpath("mcl_core") then
|
||||||
output = "protector:protect",
|
item_gold = "mcl_core:gold_ingot"
|
||||||
recipe = {
|
item_stone = "mcl_core:stone"
|
||||||
{"default:stone", "default:stone", "default:stone"},
|
|
||||||
{"default:stone", "default:gold_ingot", "default:stone"},
|
|
||||||
{"default:stone", "default:stone", "default:stone"}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
else
|
|
||||||
|
|
||||||
minetest.register_craft({
|
|
||||||
output = "protector:protect",
|
|
||||||
recipe = {
|
|
||||||
{"mcl_core:stone", "mcl_core:stone", "mcl_core:stone"},
|
|
||||||
{"mcl_core:stone", "mcl_core:gold_ingot", "mcl_core:stone"},
|
|
||||||
{"mcl_core:stone", "mcl_core:stone", "mcl_core:stone"}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
minetest.register_craft({
|
||||||
|
output = "protector:protect",
|
||||||
|
recipe = {
|
||||||
|
{item_stone, item_stone, item_stone},
|
||||||
|
{item_stone, item_gold, item_stone},
|
||||||
|
{item_stone, item_stone, item_stone}
|
||||||
|
}
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
-- protection logo
|
-- protection logo
|
||||||
|
|
||||||
minetest.register_node("protector:protect2", {
|
minetest.register_node("protector:protect2", {
|
||||||
description = S("Protection Logo") .. " (" .. S("USE for area check") .. ")",
|
description = S("Protection Logo") .. " (" .. S("USE for area check") .. ")",
|
||||||
tiles = {"protector_logo.png"},
|
tiles = {"protector_logo.png"},
|
||||||
@ -623,9 +578,7 @@ minetest.register_node("protector:protect2", {
|
|||||||
|
|
||||||
on_use = function(itemstack, user, pointed_thing)
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
|
|
||||||
if pointed_thing.type ~= "node" then
|
if pointed_thing.type ~= "node" then return end
|
||||||
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)
|
||||||
@ -636,8 +589,7 @@ minetest.register_node("protector:protect2", {
|
|||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local name = clicker:get_player_name()
|
local name = clicker:get_player_name()
|
||||||
|
|
||||||
if meta
|
if meta and protector.can_dig(1, pos, name, true, 1) then
|
||||||
and protector.can_dig(1, pos, name, true, 1) then
|
|
||||||
|
|
||||||
player_pos[name] = pos
|
player_pos[name] = pos
|
||||||
|
|
||||||
@ -647,9 +599,7 @@ minetest.register_node("protector:protect2", {
|
|||||||
|
|
||||||
on_punch = function(pos, node, puncher)
|
on_punch = function(pos, node, puncher)
|
||||||
|
|
||||||
if minetest.is_protected(pos, puncher:get_player_name()) then
|
if minetest.is_protected(pos, puncher:get_player_name()) then return end
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
minetest.add_entity(pos, "protector:display")
|
minetest.add_entity(pos, "protector:display")
|
||||||
end,
|
end,
|
||||||
@ -665,6 +615,7 @@ minetest.register_node("protector:protect2", {
|
|||||||
})
|
})
|
||||||
|
|
||||||
-- recipes to switch between protectors
|
-- recipes to switch between protectors
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = "protector:protect",
|
output = "protector:protect",
|
||||||
recipe = {{"protector:protect2"}}
|
recipe = {{"protector:protect2"}}
|
||||||
@ -675,20 +626,16 @@ minetest.register_craft({
|
|||||||
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)
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
|
|
||||||
if formname ~= "protector:node" then
|
if formname ~= "protector:node" then return end
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local pos = player_pos[name]
|
local pos = player_pos[name]
|
||||||
|
|
||||||
if not name or not pos then
|
if not name or not pos then return end
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local add_member_input = fields.protector_add_member
|
local add_member_input = fields.protector_add_member
|
||||||
|
|
||||||
@ -707,17 +654,12 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
-- 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 = minetest.get_node(pos).name
|
||||||
|
|
||||||
if nod ~= "protector:protect"
|
if nod ~= "protector:protect" and nod ~= "protector:protect2" then
|
||||||
and nod ~= "protector:protect2" then
|
|
||||||
player_pos[name] = nil
|
player_pos[name] = nil
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos) ; if not meta then return end
|
||||||
|
|
||||||
if not meta then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
-- add faction members
|
-- add faction members
|
||||||
if factions_available and fields.faction_members ~= nil then
|
if factions_available and fields.faction_members ~= nil then
|
||||||
@ -746,12 +688,11 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
minetest.show_formspec(name, formname, protector_formspec(meta))
|
minetest.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", {
|
minetest.register_entity("protector:display", {
|
||||||
|
|
||||||
initial_properties = {
|
initial_properties = {
|
||||||
|
|
||||||
physical = false,
|
physical = false,
|
||||||
collisionbox = {0, 0, 0, 0, 0, 0},
|
collisionbox = {0, 0, 0, 0, 0, 0},
|
||||||
visual = "wielditem",
|
visual = "wielditem",
|
||||||
@ -768,17 +709,15 @@ minetest.register_entity("protector:display", {
|
|||||||
self.timer = self.timer + dtime
|
self.timer = self.timer + dtime
|
||||||
|
|
||||||
-- remove after set number of seconds
|
-- remove after set number of seconds
|
||||||
if self.timer > protector_show then
|
if self.timer > protector_show then self.object:remove() end
|
||||||
self.object:remove()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
-- 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 x = protector_radius
|
||||||
|
|
||||||
minetest.register_node("protector:display_node", {
|
minetest.register_node("protector:display_node", {
|
||||||
tiles = {"protector_display.png"},
|
tiles = {"protector_display.png"},
|
||||||
use_texture_alpha = "clip",
|
use_texture_alpha = "clip",
|
||||||
@ -787,27 +726,22 @@ minetest.register_node("protector:display_node", {
|
|||||||
node_box = {
|
node_box = {
|
||||||
type = "fixed",
|
type = "fixed",
|
||||||
fixed = {
|
fixed = {
|
||||||
-- sides
|
{-(x+.55), -(x+.55), -(x+.55), -(x+.45), (x+.55), (x+.55)}, -- sides
|
||||||
{-(x+.55), -(x+.55), -(x+.55), -(x+.45), (x+.55), (x+.55)},
|
|
||||||
{-(x+.55), -(x+.55), (x+.45), (x+.55), (x+.55), (x+.55)},
|
{-(x+.55), -(x+.55), (x+.45), (x+.55), (x+.55), (x+.55)},
|
||||||
{(x+.45), -(x+.55), -(x+.55), (x+.55), (x+.55), (x+.55)},
|
{(x+.45), -(x+.55), -(x+.55), (x+.55), (x+.55), (x+.55)},
|
||||||
{-(x+.55), -(x+.55), -(x+.55), (x+.55), (x+.55), -(x+.45)},
|
{-(x+.55), -(x+.55), -(x+.55), (x+.55), (x+.55), -(x+.45)},
|
||||||
-- top
|
{-(x+.55), (x+.45), -(x+.55), (x+.55), (x+.55), (x+.55)}, -- top
|
||||||
{-(x+.55), (x+.45), -(x+.55), (x+.55), (x+.55), (x+.55)},
|
{-(x+.55), -(x+.55), -(x+.55), (x+.55), -(x+.45), (x+.55)}, -- bottom
|
||||||
-- bottom
|
{-.55,-.55,-.55, .55,.55,.55} -- middle (surrounding protector)
|
||||||
{-(x+.55), -(x+.55), -(x+.55), (x+.55), -(x+.45), (x+.55)},
|
|
||||||
-- middle (surround protector)
|
|
||||||
{-.55,-.55,-.55, .55,.55,.55}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
selection_box = {
|
selection_box = {type = "regular"},
|
||||||
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 = ""
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- load mod sections
|
||||||
|
|
||||||
dofile(MP .. "/doors_chest.lua")
|
dofile(MP .. "/doors_chest.lua")
|
||||||
dofile(MP .. "/pvp.lua")
|
dofile(MP .. "/pvp.lua")
|
||||||
@ -819,13 +753,13 @@ if minetest.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 minetest.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:chest")
|
mesecon.register_mvps_stopper("protector:chest")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
print ("[MOD] Protector Redo loaded")
|
print ("[MOD] Protector Redo loaded")
|
||||||
|
14
pvp.lua
14
pvp.lua
@ -1,18 +1,20 @@
|
|||||||
|
|
||||||
local S = protector.intllib
|
|
||||||
|
|
||||||
-- get static spawn position
|
-- get static spawn position
|
||||||
|
|
||||||
local statspawn = minetest.string_to_pos(minetest.settings:get("static_spawnpoint"))
|
local statspawn = minetest.string_to_pos(minetest.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(minetest.settings:get("protector_spawn")
|
||||||
or minetest.settings:get("protector_pvp_spawn")) or 0
|
or minetest.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 = minetest.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 minetest.settings:get_bool("enable_pvp")
|
||||||
and minetest.settings:get_bool("protector_pvp") then
|
and minetest.settings:get_bool("protector_pvp") then
|
||||||
|
|
||||||
@ -21,15 +23,13 @@ and minetest.settings:get_bool("protector_pvp") then
|
|||||||
minetest.register_on_punchplayer(function(player, hitter,
|
minetest.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
|
if not player or not hitter then
|
||||||
or not hitter then
|
|
||||||
print("[MOD] Protector - on_punchplayer called with nil objects")
|
print("[MOD] Protector - on_punchplayer called with nil objects")
|
||||||
end
|
|
||||||
|
|
||||||
if not hitter:is_player() then
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if not hitter:is_player() then return false end
|
||||||
|
|
||||||
-- no pvp at spawn area
|
-- no pvp at spawn area
|
||||||
local pos = player:get_pos()
|
local pos = player:get_pos()
|
||||||
|
|
||||||
|
24
tool.lua
24
tool.lua
@ -1,14 +1,18 @@
|
|||||||
|
|
||||||
-- protector placement tool (thanks to Shara for code and idea)
|
-- protector placement tool (thanks to Shara for code and idea)
|
||||||
|
|
||||||
local S = protector.intllib
|
local S = minetest.get_translator("protector")
|
||||||
|
|
||||||
-- get protection radius
|
-- get protection radius
|
||||||
|
|
||||||
local r = tonumber(minetest.settings:get("protector_radius")) or 5
|
local r = tonumber(minetest.settings:get("protector_radius")) or 5
|
||||||
|
|
||||||
-- radius limiter (minetest cannot handle node volume of more than 4096000)
|
-- radius limiter (minetest cannot handle node volume of more than 4096000)
|
||||||
|
|
||||||
if r > 30 then r = 30 end
|
if r > 30 then r = 30 end
|
||||||
|
|
||||||
|
-- protector placement tool
|
||||||
|
|
||||||
minetest.register_craftitem("protector:tool", {
|
minetest.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",
|
||||||
@ -68,8 +72,7 @@ minetest.register_craftitem("protector:tool", {
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- does a protector already exist ?
|
-- does a protector already exist ?
|
||||||
if #minetest.find_nodes_in_area(
|
if #minetest.find_nodes_in_area(vector.subtract(pos, 1), vector.add(pos, 1),
|
||||||
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
|
||||||
|
|
||||||
@ -114,17 +117,17 @@ minetest.register_craftitem("protector:tool", {
|
|||||||
local inv = minetest.get_inventory({type = "node", pos = pos})
|
local inv = minetest.get_inventory({type = "node", pos = pos})
|
||||||
|
|
||||||
if inv then
|
if inv then
|
||||||
minetest.chat_send_player(name,
|
minetest.chat_send_player(name, S("Cannot place protector, container at") ..
|
||||||
S("Cannot place protector, container at") ..
|
|
||||||
" " .. minetest.pos_to_string(pos))
|
" " .. minetest.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 minetest.is_protected(pos, name) then
|
||||||
|
|
||||||
minetest.chat_send_player(name,
|
minetest.chat_send_player(name,
|
||||||
S("Cannot place protector, already protected at") ..
|
S("Cannot place protector, already protected at")
|
||||||
" " .. minetest.pos_to_string(pos))
|
.. " " .. minetest.pos_to_string(pos))
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -147,18 +150,17 @@ minetest.register_craftitem("protector:tool", {
|
|||||||
minetest.chat_send_player(name,
|
minetest.chat_send_player(name,
|
||||||
S("Protector placed at") ..
|
S("Protector placed at") ..
|
||||||
" " .. minetest.pos_to_string(pos))
|
" " .. minetest.pos_to_string(pos))
|
||||||
|
end
|
||||||
end,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
-- tool recipe
|
-- tool recipe
|
||||||
|
|
||||||
local df = "default:steel_ingot"
|
local df = "default:steel_ingot"
|
||||||
|
|
||||||
if not minetest.registered_items[df] then
|
if minetest.get_modpath("mcl_core") then
|
||||||
df = "mcl_core:iron_ingot"
|
df = "mcl_core:iron_ingot"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = "protector:tool",
|
output = "protector:tool",
|
||||||
recipe = {
|
recipe = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user