diff --git a/admin.lua b/admin.lua index c8ae75c..4e28083 100644 --- a/admin.lua +++ b/admin.lua @@ -1,30 +1,27 @@ --- translation and default name vars - -local S = minetest.get_translator("protector") +local S = protector.intllib local removal_names = "" local replace_names = "" --- remove protection command - minetest.register_chatcommand("protector_remove", { params = S(""), description = S("Remove Protectors around players (separate names with spaces)"), privs = {server = true}, - func = function(name, param) if not param or param == "" then minetest.chat_send_player(name, - S("Protector Names to remove: @1", removal_names)) + S("Protector Names to remove: @1", + removal_names)) return end if param == "-" then - minetest.chat_send_player(name, S("Name List Reset")) + minetest.chat_send_player(name, + S("Name List Reset")) removal_names = "" @@ -35,13 +32,11 @@ minetest.register_chatcommand("protector_remove", { end }) --- replace protection command minetest.register_chatcommand("protector_replace", { params = S(" "), description = S("Replace Protector Owner with name provided"), privs = {server = true}, - func = function(name, param) -- reset list to empty @@ -55,11 +50,13 @@ minetest.register_chatcommand("protector_replace", { end -- show name info - if param == "" and replace_names ~= "" then + if param == "" + and replace_names ~= "" then local names = replace_names:split(" ") - minetest.chat_send_player(name, S("Replacing Protector name @1 with @2", + minetest.chat_send_player(name, + S("Replacing Protector name @1 with @2", names[1] or "", names[2] or "")) return @@ -69,17 +66,18 @@ minetest.register_chatcommand("protector_replace", { end }) --- Abm to remove or replace protectors within active player area minetest.register_abm({ nodenames = {"protector:protect", "protector:protect2", "protector:protect_hidden"}, interval = 6, chance = 1, catch_up = false, - action = function(pos, node) - if removal_names == "" and replace_names == "" then return end + if removal_names == "" + and replace_names == "" then + return + end local meta = minetest.get_meta(pos) @@ -92,7 +90,9 @@ minetest.register_abm({ local names = removal_names:split(" ") for _, n in pairs(names) do - if n == owner then minetest.set_node(pos, {name = "air"}) end + if n == owner then + minetest.set_node(pos, {name = "air"}) + end end end @@ -108,19 +108,16 @@ minetest.register_abm({ end }) --- get protection radius (max 30) - +-- get protection radius 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) - minetest.register_chatcommand("protector_show_area", { params = "", description = S("Show protected areas of your nearby protectors"), privs = {}, - func = function(name, param) local player = minetest.get_player_by_name(name) @@ -128,9 +125,9 @@ minetest.register_chatcommand("protector_show_area", { -- find the protector nodes local pos = minetest.find_nodes_in_area( - {x = pos.x - r, y = pos.y - r, z = pos.z - r}, - {x = pos.x + r, y = pos.y + r, z = pos.z + r}, - {"protector:protect", "protector:protect2", "protector:protect_hidden"}) + {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 @@ -148,8 +145,8 @@ minetest.register_chatcommand("protector_show_area", { 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", { description = "Hidden Protector", drawtype = "airlike", @@ -168,11 +165,11 @@ minetest.register_node("protector:protect_hidden", { on_blast = function() end, -- 1px block inside door hinge near node top collision_box = { - type = "fixed", fixed = {-15/32, 13/32, -15/32, -13/32, 1/2, -13/32} + type = "fixed", + fixed = {-15/32, 13/32, -15/32, -13/32, 1/2, -13/32} } }) --- make own protectors visible in area minetest.register_chatcommand("protector_show", { params = "", @@ -190,9 +187,9 @@ minetest.register_chatcommand("protector_show", { local pos = player:get_pos() local a = minetest.find_nodes_in_area( - {x = pos.x - r, y = pos.y - r, z = pos.z - r}, - {x = pos.x + r, y = pos.y + r, z = pos.z + r}, - {"protector:protect_hidden"}) + {x = pos.x - r, y = pos.y - r, z = pos.z - r}, + {x = pos.x + r, y = pos.y + r, z = pos.z + r}, + {"protector:protect_hidden"}) local meta, owner @@ -209,8 +206,6 @@ minetest.register_chatcommand("protector_show", { end }) --- make own protectors invisible in area - minetest.register_chatcommand("protector_hide", { params = "", description = S("Hide your nearby protection blocks"), @@ -227,9 +222,9 @@ minetest.register_chatcommand("protector_hide", { local pos = player:get_pos() local a = minetest.find_nodes_in_area( - {x = pos.x - r, y = pos.y - r, z = pos.z - r}, - {x = pos.x + r, y = pos.y + r, z = pos.z + r}, - {"protector:protect", "protector:protect2"}) + {x = pos.x - r, y = pos.y - r, z = pos.z - r}, + {x = pos.x + r, y = pos.y + r, z = pos.z + r}, + {"protector:protect", "protector:protect2"}) local meta, owner diff --git a/doors_chest.lua b/doors_chest.lua index f3b5e0d..8dd3daf 100644 --- a/doors_chest.lua +++ b/doors_chest.lua @@ -1,88 +1,83 @@ --- doors code from an old client re-used +-- Since the doors mod has changed in the latest daily builds I have taken the +-- WTFPL licenced code from the old doors mod and included an edited version +-- within this mod for local use. -local S = minetest.get_translator("protector") +local S = protector.intllib local F = minetest.formspec_escape --- MineClone support - +-- MineClone2 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) - +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}} + 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 + def.sound_close_door = "doors_door_close" + def.sound_open_door = "doors_door_open" 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 + 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 + 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} - + local pt3 = {x=pt.x, y=pt.y, z=pt.z} if p2 == 0 then - pt3.x = pt3.x - 1 + pt3.x = pt3.x-1 elseif p2 == 1 then - pt3.z = pt3.z + 1 + pt3.z = pt3.z+1 elseif p2 == 2 then - pt3.x = pt3.x + 1 + pt3.x = pt3.x+1 elseif p2 == 3 then - pt3.z = pt3.z - 1 + 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}) + 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(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.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 @@ -90,212 +85,230 @@ local function register_door(name, def) 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 + 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 - + 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] - p2 = params[p2 + 1] + minetest.swap_node(pos, {name=replace_dir, param2=p2}) - minetest.swap_node(pos, {name = replace_dir, param2 = p2}) + pos.y = pos.y-dir + minetest.swap_node(pos, {name=replace, param2=p2}) - pos.y = pos.y - dir + local snd_1 = def.sound_close_door + local snd_2 = def.sound_open_door + if params[1] == 3 then + snd_1 = def.sound_open_door + snd_2 = def.sound_close_door + end - minetest.swap_node(pos, {name = replace, param2=p2}) - - minetest.sound_play("default_dug_node", - {pos = pos, gain = 0.3, max_hear_distance = 10}, true) + if minetest.get_meta(pos):get_int("right") ~= 0 then + minetest.sound_play(snd_1, {pos = pos, gain = 0.3, max_hear_distance = 10}) + else + minetest.sound_play(snd_2, {pos = pos, gain = 0.3, max_hear_distance = 10}) + end end local function on_rotate(pos, node, dir, user, check_name, mode, new_param2) - if mode ~= screwdriver.ROTATE_FACE then return false end + 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.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"}, + 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 }, + 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 + 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}) + 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) + return on_rotate(pos, node, 1, user, name.."_t_1", mode) end, sounds = def.sounds, sunlight_propagates = def.sunlight, - on_blast = function() end + on_blast = function() end, }) - minetest.register_node(name .. "_t_1", { - tiles = {tt[2], tt[2], tt[2], tt[2], tt[1], tt[1] .. "^[transformfx"}, + 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 }, + 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) + 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}) + 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) + return on_rotate(pos, node, -1, user, name.."_b_1", mode) end, sounds = def.sounds, sunlight_propagates = def.sunlight, - on_blast = function() end + on_blast = function() end, }) - minetest.register_node(name .. "_b_2", { - tiles = {tb[2], tb[2], tb[2], tb[2], tb[1] .. "^[transformfx", tb[1]}, + 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 }, + 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) + 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}) + 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) + return on_rotate(pos, node, 1, user, name.."_t_2", mode) end, sounds = def.sounds, sunlight_propagates = def.sunlight, - on_blast = function() end + on_blast = function() end, }) - minetest.register_node(name .. "_t_2", { - tiles = {tt[2], tt[2], tt[2], tt[2], tt[1] .. "^[transformfx", tt[1]}, + 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 }, + 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) + 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}) + 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) + return on_rotate(pos, node, -1, user, name.."_b_2", mode) end, sounds = def.sounds, sunlight_propagates = def.sunlight, - on_blast = function() end + on_blast = function() end, }) end @@ -306,7 +319,10 @@ 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}, + groups = { + 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_top = {"doors_wood_a.png", "doors_brown.png"}, sounds = default.node_sound_wood_defaults(), @@ -314,27 +330,29 @@ register_door(name, { }) if protector_crafts then - if mcl then - - minetest.register_craft({ - output = name, - recipe = { {"mcl_doors:wooden_door", "mcl_core:gold_ingot"} } - }) + 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 = { + {"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"} } - }) + minetest.register_craft({ + output = name, + recipe = { + {"doors:door_wood", "default:copper_ingot"} + } + }) end end @@ -347,7 +365,7 @@ register_door(name, { 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 + level = mcl and 0 or 2, pickaxey = 2, unbreakable = 1, -- door = 1 }, tiles_bottom = {"doors_steel_b.png^protector_logo.png", "doors_grey.png"}, tiles_top = {"doors_steel_a.png", "doors_grey.png"}, @@ -361,7 +379,9 @@ if protector_crafts then minetest.register_craft({ output = name, - recipe = { {"mcl_doors:iron_door", "mcl_core:gold_ingot"} } + recipe = { + {"mcl_doors:iron_door", "mcl_core:gold_ingot"} + } }) else minetest.register_craft({ @@ -375,29 +395,31 @@ if protector_crafts then minetest.register_craft({ output = name, - recipe = { {"doors:door_steel", "default:copper_ingot"} } + recipe = { + {"doors:door_steel", "default:copper_ingot"} + } }) end end ----trapdoor---- -local function register_trapdoor(name, def) - +function register_trapdoor(name, def) local name_closed = name - local name_opened = name .. "_open" + 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 - + 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}) + local sound = false + if node.name == name_closed then sound = "doors_door_open" end + if node.name == name_opened then sound = "doors_door_close" end + if sound then + minetest.sound_play(sound, {pos = pos, gain = 0.3, max_hear_distance = 10}) + end + minetest.swap_node(pos, {name = newname, param1 = node.param1, param2 = node.param2}) end -- Common trapdoor configuration @@ -406,25 +428,28 @@ local function register_trapdoor(name, def) 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} + 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} + 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} + 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} + 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", @@ -446,33 +471,38 @@ register_trapdoor("protector:trapdoor", { 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}, + groups = { + snappy = 1, choppy = 2, dig_immediate = 2, + unbreakable = 1, axey = 1, --door = 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"} } - }) + 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 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"} } - }) + minetest.register_craft({ + output = "protector:trapdoor", + recipe = { + {"doors:trapdoor", "default:copper_ingot"} + } + }) end end @@ -485,35 +515,37 @@ register_trapdoor("protector:trapdoor_steel", { 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 + snappy = 1, bendy = 2, cracky = 1, melty = 2, level = mcl and 0 or 2, + unbreakable = 1, pickaxey = 2, --door = 1 }, _mcl_hardness = 1, _mcl_blast_resistance = 1, - sounds = default.node_sound_metal_defaults() + 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"} } - }) + 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 = { + {"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"} } - }) + minetest.register_craft({ + output = "protector:trapdoor_steel", + recipe = { + {"doors:trapdoor_steel", "default:copper_ingot"} + } + }) end end @@ -559,21 +591,24 @@ minetest.register_node("protector:chest", { 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)) + 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)) + 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)) + 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) @@ -606,9 +641,15 @@ minetest.register_node("protector:chest", { on_rightclick = function(pos, node, clicker) - if minetest.is_protected(pos, clicker:get_player_name()) then return end + 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 meta = minetest.get_meta(pos) + + if not meta then + return + end local spos = pos.x .. "," .. pos.y .. "," ..pos.z local formspec @@ -656,12 +697,11 @@ minetest.register_node("protector:chest", { "protector:chest_" .. minetest.pos_to_string(pos), formspec) end, - on_blast = function() end + on_blast = function() end, }) -- Container transfer helper - -local function to_from(src, dst) +local to_from = function(src, dst) local stack, item, leftover local size = dst:get_size("main") @@ -688,12 +728,16 @@ end minetest.register_on_player_receive_fields(function(player, formname, fields) - if string.sub(formname, 0, 16) ~= "protector:chest_" then return end + 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 + 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 @@ -737,7 +781,9 @@ if protector_crafts then minetest.register_craft({ output = "protector:chest", - recipe = { {"mcl_chests:chest", "mcl_core:gold_ingot"} } + recipe = { + {"mcl_chests:chest", "mcl_core:gold_ingot"} + } }) else minetest.register_craft({ @@ -751,7 +797,9 @@ if protector_crafts then minetest.register_craft({ output = "protector:chest", - recipe = { {"default:chest", "default:copper_ingot"} } + recipe = { + {"default:chest", "default:copper_ingot"} + } }) end end diff --git a/hud.lua b/hud.lua index 9aaae5d..f5b5b00 100644 --- a/hud.lua +++ b/hud.lua @@ -1,27 +1,23 @@ --- translation and protector radius - -local S = minetest.get_translator("protector") +local S = protector.intllib local radius = (tonumber(minetest.settings:get("protector_radius")) or 5) -- radius limiter (minetest cannot handle node volume of more than 4096000) - if radius > 30 then radius = 30 end --- hud settings - local hud = {} local hud_timer = 0 local hud_interval = (tonumber(minetest.settings:get("protector_hud_interval")) or 5) local hud_style = minetest.has_feature("hud_def_type_field") if hud_interval > 0 then - minetest.register_globalstep(function(dtime) -- every 5 seconds hud_timer = hud_timer + dtime - if hud_timer < hud_interval then return end + if hud_timer < hud_interval then + return + end hud_timer = 0 for _, player in pairs(minetest.get_connected_players()) do @@ -31,12 +27,11 @@ minetest.register_globalstep(function(dtime) local hud_text = "" local protectors = minetest.find_nodes_in_area( - {x = pos.x - radius , y = pos.y - radius , z = pos.z - radius}, - {x = pos.x + radius , y = pos.y + radius , z = pos.z + radius}, - {"protector:protect","protector:protect2", "protector:protect_hidden"}) + {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"}) if #protectors > 0 then - local npos = protectors[1] local meta = minetest.get_meta(npos) local nodeowner = meta:get_string("owner") @@ -77,4 +72,4 @@ minetest.register_on_leaveplayer(function(player) hud[player:get_player_name()] = nil end) -end -- END hud_interval > 0 +end diff --git a/init.lua b/init.lua index 5f63c9e..e6ed611 100644 --- a/init.lua +++ b/init.lua @@ -1,15 +1,12 @@ -- default support (for use with MineClone2 and other [games] - -if not minetest.global_exists("default") then - - default = { - node_sound_stone_defaults = function(table) return {} end, - node_sound_wood_defaults = function(table) return {} end, - node_sound_metal_defaults = function(table) return {} end, - gui_bg = "", gui_bg_img = "", gui_slots = "" - } -end +default = default or { + node_sound_stone_defaults = function(table) end, + node_sound_wood_defaults = function(table) end, + gui_bg = "", + gui_bg_img = "", + gui_slots = "" +} if minetest.get_modpath("mcl_sounds") then default.node_sound_stone_defaults = mcl_sounds.node_sound_stone_defaults @@ -17,20 +14,23 @@ if minetest.get_modpath("mcl_sounds") then default.node_sound_metal_defaults = mcl_sounds.node_sound_metal_defaults end --- modpath, formspec helper and translator - local MP = minetest.get_modpath(minetest.get_current_modname()) local F = minetest.formspec_escape + +-- Translation support local S = minetest.get_translator("protector") --- global table - -protector = { mod = "redo", modpath = MP } - --- settings - +-- Load support for factions local factions_available = minetest.global_exists("factions") + +protector = { + mod = "redo", + modpath = MP, + intllib = S +} + local protector_max_share_count = 12 +-- get minetest.conf settings 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 @@ -41,94 +41,110 @@ 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) - 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")) or {x = 0, y = 2, z = 0} --- return list of members as a table -local function get_member_list(meta) +-- return list of members as a table +local get_member_list = function(meta) return meta:get_string("members"):split(" ") end -local function get_faction_list(meta) - return meta:get_string("factions"):split(" ") -end -- write member list table in protector meta as string - -local function set_member_list(meta, list) +local set_member_list = function(meta, list) meta:set_string("members", table.concat(list, " ")) end -local function set_faction_list(meta, list) - meta:set_string("factions", table.concat(list, " ")) -end -- check for owner name - -local function is_owner(meta, name) +local is_owner = function(meta, name) return name == meta:get_string("owner") end --- check for member name -local function is_member(meta, name) +-- check for member name +local is_member = function(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 owner_factions = factions.get_player_factions(name) + local owner = meta:get_string("owner") + + if owner_factions ~= nil and owner_factions ~= false then + + for _, f in ipairs(owner_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 - if n == name then return true 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 + if n == name then + return true end end return false end --- add player name to table as member -local function add_member(meta, name) +-- add player name to table as member +local add_member = function(meta, name) -- Validate player name for MT compliance - if name ~= string.match(name, "[%w_-]+") then return end + if name ~= string.match(name, "[%w_-]+") then + return + end -- 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) - if #list >= protector_max_share_count then return end + if #list >= protector_max_share_count then + return + end table.insert(list, name) set_member_list(meta, list) 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 - -local function del_member(meta, name) +local del_member = function(meta, name) local list = get_member_list(meta) @@ -143,53 +159,65 @@ local function del_member(meta, name) set_member_list(meta, list) 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 - -local function protector_formspec(meta) +local protector_formspec = function(meta) local formspec = "size[8,7]" .. default.gui_bg .. default.gui_bg_img .. "label[2.5,0;" .. F(S("-- Protector interface --")) .. "]" .. "label[0,1;" .. F(S("PUNCH node to show protected area")) .. "]" - .. "label[0,1.5;" .. F(S("Members:")) .. "]" + .. "label[0,2;" .. F(S("Members:")) .. "]" .. "button_exit[2.5,6.2;3,0.5;close_me;" .. F(S("Close")) .. "]" .. "field_close_on_enter[protector_add_member;false]" 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 - formspec = formspec .. "label[0,4.25;" .. F(S("Factions:")) .. "]" - .. "field_close_on_enter[protector_add_faction;false]" - if npp > 8 then npp = 8 end + if factions.version == nil then + + -- 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 - local i = 0 for n = 1, #members do if i < npp then -- show username formspec = formspec .. "button[" .. (i % 4 * 2) - .. "," .. (math.floor(i / 4) + 2.5) + .. "," .. math.floor(i / 4 + 3) .. ";1.5,.5;protector_member;" .. F(members[n]) .. "]" -- username remove button .. "button[" .. (i % 4 * 2 + 1.25) .. "," - .. (math.floor(i / 4) + 2.5) + .. math.floor(i / 4 + 3) .. ";.75,.5;protector_del_member_" .. F(members[n]) .. ";X]" end @@ -200,61 +228,47 @@ local function protector_formspec(meta) -- user name entry field formspec = formspec .. "field[" .. (i % 4 * 2 + 1 / 3) .. "," - .. (math.floor(i / 4) + 2.5 + 1 / 3) + .. (math.floor(i / 4 + 3) + 1 / 3) .. ";1.433,.5;protector_add_member;;]" -- username add button .."button[" .. (i % 4 * 2 + 1.25) .. "," - .. (math.floor(i / 4) + 2.5) .. ";.75,.5;protector_submit;+]" + .. math.floor(i / 4 + 3) .. ";.75,.5;protector_submit;+]" 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 end + -- check if pos is inside a protected spawn area +local inside_spawn = function(pos, radius) -local function inside_spawn(pos, radius) + if protector_spawn <= 0 then + return false + end - if protector_spawn <= 0 then return false end - - if pos.x < statspawn.x + radius and pos.x > statspawn.x - radius - and pos.y < statspawn.y + radius and pos.y > statspawn.y - radius - and pos.z < statspawn.z + radius and pos.z > statspawn.z - radius then + if pos.x < statspawn.x + radius + and pos.x > statspawn.x - radius + and pos.y < statspawn.y + radius + and pos.y > statspawn.y - radius + and pos.z < statspawn.z + radius + and pos.z > statspawn.z - radius then return true end + + return false end --- show protection message if enabled -local function show_msg(player, msg) +-- show protection message if enabled +local show_msg = function(player, msg) -- 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 or player == "" then + return + end minetest.chat_send_player(player, msg) end @@ -266,9 +280,11 @@ end -- 2 for "This area is owned by . -- 3 for checking protector overlaps -function protector.can_dig(r, pos, digger, onlyowner, infolevel) +protector.can_dig = function(r, pos, digger, onlyowner, infolevel) - if not digger or not pos then return false end + if not digger or not pos then + return false + end -- protector_bypass privileged users can override protection if infolevel == 1 @@ -282,7 +298,8 @@ function protector.can_dig(r, pos, digger, onlyowner, infolevel) -- is spawn area protected ? 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)) return false @@ -290,9 +307,9 @@ function protector.can_dig(r, pos, digger, onlyowner, infolevel) -- find the protector nodes local pos = minetest.find_nodes_in_area( - {x = pos.x - r, y = pos.y - r, z = pos.z - r}, - {x = pos.x + r, y = pos.y + r, z = pos.z + r}, - {"protector:protect", "protector:protect2", "protector:protect_hidden"}) + {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, members @@ -308,7 +325,8 @@ function protector.can_dig(r, pos, digger, onlyowner, infolevel) -- and you aren't on the member list if onlyowner or not is_member(meta, digger) then - show_msg(digger, S("This area is owned by @1", owner) .. "!") + show_msg(digger, + S("This area is owned by @1", owner) .. "!") return false end @@ -318,12 +336,13 @@ function protector.can_dig(r, pos, digger, onlyowner, infolevel) if infolevel == 2 then minetest.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, - 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 + minetest.chat_send_player(digger, S("Members: @1.", members)) end @@ -336,6 +355,7 @@ function protector.can_dig(r, pos, digger, onlyowner, infolevel) if infolevel == 2 then if #pos < 1 then + minetest.chat_send_player(digger, S("This area is not protected.")) end @@ -345,8 +365,8 @@ function protector.can_dig(r, pos, digger, onlyowner, infolevel) return true 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) local player = minetest.get_player_by_name(name) @@ -381,18 +401,21 @@ minetest.register_on_protection_violation(function(pos, name) local pla_pos = player:get_pos() 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) --- backup old is_protected function local old_is_protected = minetest.is_protected -- check for protected area, return true if protected and digger isn't on list - function minetest.is_protected(pos, digger) digger = digger or "" -- nil check @@ -406,11 +429,13 @@ function minetest.is_protected(pos, digger) return old_is_protected(pos, digger) end + -- make sure protection block doesn't overlap another protector's area +local check_overlap = function(itemstack, placer, pointed_thing) -local function check_overlap(itemstack, placer, pointed_thing) - - if pointed_thing.type ~= "node" then return itemstack end + if pointed_thing.type ~= "node" then + return itemstack + end local pos = pointed_thing.above local name = placer:get_player_name() @@ -419,8 +444,8 @@ local function check_overlap(itemstack, placer, pointed_thing) if inside_spawn(pos, protector_spawn + protector_radius) then minetest.chat_send_player(name, - S("Spawn @1 has been protected up to a @2 block radius.", - minetest.pos_to_string(statspawn), protector_spawn)) + S("Spawn @1 has been protected up to a @2 block radius.", + minetest.pos_to_string(statspawn), protector_spawn)) return itemstack end @@ -429,49 +454,41 @@ local function check_overlap(itemstack, placer, pointed_thing) if not protector.can_dig(protector_radius * 2, pos, name, true, 3) then minetest.chat_send_player(name, - S("Overlaps into above players protected area")) + S("Overlaps into above players protected area")) return itemstack end return minetest.item_place(itemstack, placer, pointed_thing) + end --- remove protector display entities -local function del_display(pos) +-- remove protector display entities +local del_display = function(pos) local objects = minetest.get_objects_inside_radius(pos, 0.5) for _, v in ipairs(objects) do - if v and v:get_luaentity() and v:get_luaentity().name == "protector:display" then + if v and v:get_luaentity() + and v:get_luaentity().name == "protector:display" then v:remove() end end end --- temporary position store - +-- temporary pos store local player_pos = {} --- stone texture - -local stone_tex = "default_stone.png" - -if minetest.get_modpath("nc_terrain") then - stone_tex = "nc_terrain_stone.png" -end - -- protection node - minetest.register_node("protector:protect", { description = S("Protection Block") .. " (" .. S("USE for area check") .. ")", drawtype = "nodebox", tiles = { - stone_tex .. "^protector_overlay.png", - stone_tex .. "^protector_overlay.png", - stone_tex .. "^protector_overlay.png^protector_logo.png" + "default_stone.png^protector_overlay.png", + "default_stone.png^protector_overlay.png", + "default_stone.png^protector_overlay.png^protector_logo.png" }, sounds = default.node_sound_stone_defaults(), groups = {dig_immediate = 2, unbreakable = 1}, @@ -480,7 +497,10 @@ minetest.register_node("protector:protect", { light_source = 4, node_box = { - type = "fixed", fixed = {{-0.499 ,-0.499, -0.499, 0.499, 0.499, 0.499}} + type = "fixed", + fixed = { + {-0.499 ,-0.499, -0.499, 0.499, 0.499, 0.499} + } }, on_place = check_overlap, @@ -497,7 +517,9 @@ minetest.register_node("protector:protect", { on_use = function(itemstack, user, pointed_thing) - if pointed_thing.type ~= "node" then return end + if pointed_thing.type ~= "node" then + return + end protector.can_dig(protector_radius, pointed_thing.under, user:get_player_name(), false, 2) @@ -508,7 +530,8 @@ minetest.register_node("protector:protect", { local meta = minetest.get_meta(pos) 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 @@ -518,7 +541,9 @@ minetest.register_node("protector:protect", { on_punch = function(pos, node, puncher) - if minetest.is_protected(pos, puncher:get_player_name()) then return end + if minetest.is_protected(pos, puncher:get_player_name()) then + return + end minetest.add_entity(pos, "protector:display") end, @@ -534,29 +559,32 @@ minetest.register_node("protector:protect", { }) -- default recipe and alternative for MineClone2 - if protector_recipe then - local item_gold = "default:gold_ingot" - local item_stone = "default:stone" + if minetest.registered_items["default:stone"] then - if minetest.get_modpath("mcl_core") then - item_gold = "mcl_core:gold_ingot" - item_stone = "mcl_core:stone" + minetest.register_craft({ + output = "protector:protect", + recipe = { + {"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 - - 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 -- protection logo - minetest.register_node("protector:protect2", { description = S("Protection Logo") .. " (" .. S("USE for area check") .. ")", tiles = {"protector_logo.png"}, @@ -595,7 +623,9 @@ minetest.register_node("protector:protect2", { on_use = function(itemstack, user, pointed_thing) - if pointed_thing.type ~= "node" then return end + if pointed_thing.type ~= "node" then + return + end protector.can_dig(protector_radius, pointed_thing.under, user:get_player_name(), false, 2) @@ -606,7 +636,8 @@ minetest.register_node("protector:protect2", { local meta = minetest.get_meta(pos) 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 @@ -616,7 +647,9 @@ minetest.register_node("protector:protect2", { on_punch = function(pos, node, puncher) - if minetest.is_protected(pos, puncher:get_player_name()) then return end + if minetest.is_protected(pos, puncher:get_player_name()) then + return + end minetest.add_entity(pos, "protector:display") end, @@ -632,7 +665,6 @@ minetest.register_node("protector:protect2", { }) -- recipes to switch between protectors - minetest.register_craft({ output = "protector:protect", recipe = {{"protector:protect2"}} @@ -643,16 +675,20 @@ minetest.register_craft({ 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) - if formname ~= "protector:node" then return end + if formname ~= "protector:node" then + return + end local name = player:get_player_name() local pos = player_pos[name] - if not name or not pos then return end + if not name or not pos then + return + end local add_member_input = fields.protector_add_member @@ -671,26 +707,21 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) -- are we adding member to a protection node ? (csm protection) local nod = minetest.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 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 -- add faction members - if factions_available then - 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 + if factions_available and fields.faction_members ~= nil then + meta:set_int("faction_members", fields.faction_members == "true" and 1 or 0) end -- add member [+] @@ -705,21 +736,22 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) for field, value in pairs(fields) do 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, - string.sub(field,string.len("protector_del_member_") + 1)) + string.sub(field,string.len("protector_del_member_") + 1)) end end minetest.show_formspec(name, formname, protector_formspec(meta)) end) --- display entity shown when protector node is punched +-- display entity shown when protector node is punched minetest.register_entity("protector:display", { initial_properties = { + physical = false, collisionbox = {0, 0, 0, 0, 0, 0}, visual = "wielditem", @@ -736,15 +768,17 @@ minetest.register_entity("protector:display", { self.timer = self.timer + dtime -- remove after set number of seconds - if self.timer > protector_show then self.object:remove() end + if self.timer > protector_show then + self.object:remove() + end end }) + -- Display-zone node, Do NOT place the display as a node, -- it is made to be used as an entity (see above) local x = protector_radius - minetest.register_node("protector:display_node", { tiles = {"protector_display.png"}, use_texture_alpha = "clip", @@ -753,22 +787,27 @@ minetest.register_node("protector:display_node", { node_box = { type = "fixed", fixed = { - {-(x+.55), -(x+.55), -(x+.55), -(x+.45), (x+.55), (x+.55)}, -- sides + -- sides + {-(x+.55), -(x+.55), -(x+.55), -(x+.45), (x+.55), (x+.55)}, {-(x+.55), -(x+.55), (x+.45), (x+.55), (x+.55), (x+.55)}, {(x+.45), -(x+.55), -(x+.55), (x+.55), (x+.55), (x+.55)}, {-(x+.55), -(x+.55), -(x+.55), (x+.55), (x+.55), -(x+.45)}, - {-(x+.55), (x+.45), -(x+.55), (x+.55), (x+.55), (x+.55)}, -- top - {-(x+.55), -(x+.55), -(x+.55), (x+.55), -(x+.45), (x+.55)}, -- bottom - {-.55,-.55,-.55, .55,.55,.55} -- middle (surrounding protector) + -- top + {-(x+.55), (x+.45), -(x+.55), (x+.55), (x+.55), (x+.55)}, + -- bottom + {-(x+.55), -(x+.55), -(x+.55), (x+.55), -(x+.45), (x+.55)}, + -- middle (surround protector) + {-.55,-.55,-.55, .55,.55,.55} } }, - selection_box = {type = "regular"}, + selection_box = { + type = "regular", + }, paramtype = "light", groups = {dig_immediate = 3, not_in_creative_inventory = 1}, drop = "" }) --- load mod sections dofile(MP .. "/doors_chest.lua") dofile(MP .. "/pvp.lua") @@ -780,13 +819,13 @@ if minetest.get_modpath("lucky_block") then dofile(MP .. "/lucky_block.lua") end --- stop mesecon pistons from pushing protectors +-- stop mesecon pistons from pushing protectors if minetest.get_modpath("mesecons_mvps") then mesecon.register_mvps_stopper("protector:protect") mesecon.register_mvps_stopper("protector:protect2") - mesecon.register_mvps_stopper("protector:protect_hidden") mesecon.register_mvps_stopper("protector:chest") end + print ("[MOD] Protector Redo loaded") diff --git a/pvp.lua b/pvp.lua index 6860467..7107854 100644 --- a/pvp.lua +++ b/pvp.lua @@ -1,20 +1,18 @@ +local S = protector.intllib + -- get static spawn position - local statspawn = minetest.string_to_pos(minetest.settings:get("static_spawnpoint")) or {x = 0, y = 2, z = 0} -- is spawn protected - 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 - local protector_night_pvp = minetest.settings:get_bool("protector_night_pvp") -- disables PVP in your own protected areas - if minetest.settings:get_bool("enable_pvp") and minetest.settings:get_bool("protector_pvp") then @@ -23,12 +21,14 @@ and minetest.settings:get_bool("protector_pvp") then minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch, tool_capabilities, dir, damage) - if not player or not hitter then + if not player + or not hitter then print("[MOD] Protector - on_punchplayer called with nil objects") - return false end - if not hitter:is_player() then return false end + if not hitter:is_player() then + return false + end -- no pvp at spawn area local pos = player:get_pos() diff --git a/tool.lua b/tool.lua index 541f5b9..ebaf7a4 100644 --- a/tool.lua +++ b/tool.lua @@ -1,18 +1,14 @@ -- protector placement tool (thanks to Shara for code and idea) -local S = minetest.get_translator("protector") +local S = protector.intllib -- get protection radius - local r = tonumber(minetest.settings:get("protector_radius")) or 5 -- radius limiter (minetest cannot handle node volume of more than 4096000) - if r > 30 then r = 30 end --- protector placement tool - minetest.register_craftitem("protector:tool", { description = S("Protector Placer Tool (stand near protector, face direction and use)"), inventory_image = "protector_tool.png", @@ -25,8 +21,8 @@ minetest.register_craftitem("protector:tool", { -- check for protector near player (2 block radius) local pos = user:get_pos() local pp = minetest.find_nodes_in_area( - vector.subtract(pos, 2), vector.add(pos, 2), - {"protector:protect", "protector:protect2", "protector:protect_hidden"}) + vector.subtract(pos, 2), vector.add(pos, 2), + {"protector:protect", "protector:protect2", "protector:protect_hidden"}) if #pp == 0 then return end -- none found @@ -66,26 +62,24 @@ minetest.register_craftitem("protector:tool", { if not protector.can_dig(r * 2, pos, user:get_player_name(), true, 3) then minetest.chat_send_player(name, - S("Overlaps into above players protected area")) + S("Overlaps into above players protected area")) return end -- does a protector already exist ? - if #minetest.find_nodes_in_area(vector.subtract(pos, 1), vector.add(pos, 1), - {"protector:protect", "protector:protect2", - "protector:protect_hidden"}) > 0 then + if #minetest.find_nodes_in_area( + vector.subtract(pos, 1), vector.add(pos, 1), + {"protector:protect", "protector:protect2", + "protector:protect_hidden"}) > 0 then minetest.chat_send_player(name, S("Protector already in place!")) return end - -- 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 - - minetest.chat_send_player(name, S("Out of bounds!")) - + -- do not place protector out of map bounds + if minetest.find_node_near(pos, 1, {"ignore", "mcl_core:bedrock"}) then return end @@ -120,17 +114,17 @@ minetest.register_craftitem("protector:tool", { local inv = minetest.get_inventory({type = "node", pos = pos}) if inv then - minetest.chat_send_player(name, S("Cannot place protector, container at") .. + minetest.chat_send_player(name, + S("Cannot place protector, container at") .. " " .. minetest.pos_to_string(pos)) return end -- protection check for other mods like Areas if minetest.is_protected(pos, name) then - minetest.chat_send_player(name, - S("Cannot place protector, already protected at") - .. " " .. minetest.pos_to_string(pos)) + S("Cannot place protector, already protected at") .. + " " .. minetest.pos_to_string(pos)) return end @@ -153,17 +147,18 @@ minetest.register_craftitem("protector:tool", { minetest.chat_send_player(name, S("Protector placed at") .. " " .. minetest.pos_to_string(pos)) - end + + end, }) -- tool recipe - local df = "default:steel_ingot" -if minetest.get_modpath("mcl_core") then +if not minetest.registered_items[df] then df = "mcl_core:iron_ingot" end + minetest.register_craft({ output = "protector:tool", recipe = {