Skip to content

Commit

Permalink
add area shielding
Browse files Browse the repository at this point in the history
Protected areas will block unwanted effects from beacons placed by other players.

Fixes #11
  • Loading branch information
OgelGames committed Oct 12, 2020
1 parent 13a499a commit 15da72b
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ read_globals = {
-- Mod Deps
"player_monoids",
"digilines",
"areas",
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 5 additions & 2 deletions effects.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion mod.conf
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions settingtypes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 15da72b

Please sign in to comment.