From 15da72bab8ced5ef3960f40a5f995b68d4d9f1eb Mon Sep 17 00:00:00 2001 From: OgelGames Date: Tue, 13 Oct 2020 00:25:50 +1100 Subject: [PATCH] add area shielding Protected areas will block unwanted effects from beacons placed by other players. Fixes #11 --- .luacheckrc | 1 + README.md | 1 + effects.lua | 7 +++++-- helpers.lua | 7 +++++++ init.lua | 3 +++ mod.conf | 2 +- settingtypes.txt | 1 + 7 files changed, 19 insertions(+), 3 deletions(-) diff --git a/.luacheckrc b/.luacheckrc index 229f1e1..3ab1883 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -19,4 +19,5 @@ read_globals = { -- Mod Deps "player_monoids", "digilines", + "areas", } diff --git a/README.md b/README.md index d12a817..22a489b 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ Other mods can register additional beacon effects, or change or remove existing - [`player_monoids`](https://github.com/minetest-mods/player_monoids) (recommended) - [`digilines`](https://github.com/minetest-mods/digilines) +- [`areas`](https://github.com/minetest-mods/areas) ## Installation diff --git a/effects.lua b/effects.lua index ebb13f7..1e1b556 100644 --- a/effects.lua +++ b/effects.lua @@ -12,8 +12,11 @@ local function get_useable_effects(name, pos) if distance <= range + 0.5 then local effect = meta:get_string("effect") if effect ~= "" and effect ~= "none" and beacon.effects[effect] then - useable_effects[effect] = true - useable = true + local owner = meta:get_string("owner") + if owner == "" or beacon.can_effect(pos, owner) then + useable_effects[effect] = true + useable = true + end end end end diff --git a/helpers.lua b/helpers.lua index 074fb0a..416641d 100644 --- a/helpers.lua +++ b/helpers.lua @@ -59,3 +59,10 @@ function beacon.limit_range(range, level) range = math.max(range, 1) return range end + +function beacon.can_effect(pos, beacon_owner) + if beacon.has_areas and beacon.config.area_shielding then + return areas:canInteract(pos, beacon_owner) + end + return true +end diff --git a/init.lua b/init.lua index 18d0ef2..44c1822 100644 --- a/init.lua +++ b/init.lua @@ -19,6 +19,7 @@ beacon.config = { effect_range_3 = tonumber(minetest.settings:get("beacon_effect_range_4")) or 40, effect_range_4 = tonumber(minetest.settings:get("beacon_effect_range_5")) or 50, upgrade_item = minetest.settings:get("beacon_upgrade_item") or "default:diamondblock", + area_shielding = minetest.settings:get("beacon_area_shielding") or true, } beacon.colors = { @@ -81,6 +82,8 @@ beacon.has_player_monoids = minetest.global_exists("player_monoids") beacon.has_digilines = minetest.global_exists("digilines") +beacon.has_areas = minetest.global_exists("areas") + beacon.modpath = minetest.get_modpath(minetest.get_current_modname()) dofile(beacon.modpath.."/api.lua") diff --git a/mod.conf b/mod.conf index e1532a0..99a721f 100644 --- a/mod.conf +++ b/mod.conf @@ -1,4 +1,4 @@ name = beacon description = Adds colored beacons that can grant effects to players depends = default, dye -optional_depends = player_monoids, digilines +optional_depends = player_monoids, digilines, areas diff --git a/settingtypes.txt b/settingtypes.txt index cf02029..4958c64 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -8,3 +8,4 @@ beacon_effect_range_2 (Level 2 beacon effect range) int 30 beacon_effect_range_3 (Level 3 beacon effect range) int 40 beacon_effect_range_4 (Level 4 beacon effect range) int 50 beacon_upgrade_item (Beacon upgrade item) string default:diamondblock +beacon_area_shielding (Protected areas block effects) bool false