-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes #4
- Loading branch information
Showing
8 changed files
with
135 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,4 +18,5 @@ read_globals = { | |
|
||
-- Mod Deps | ||
"player_monoids", | ||
"digilines", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
|
||
function beacon.digiline_effector(pos, _, channel, msg) | ||
if type(msg) ~= "table" then | ||
return | ||
end | ||
|
||
local meta = minetest.get_meta(pos) | ||
local set_channel = meta:get_string("channel") | ||
if channel ~= set_channel then | ||
return | ||
end | ||
|
||
if msg.command == "get" then | ||
digilines.receptor_send(pos, digilines.rules.default, set_channel, { | ||
radius = meta:get_int("range"), | ||
effect = meta:get_string("effect") | ||
}) | ||
|
||
elseif msg.command == "get_effects" then | ||
digilines.receptor_send(pos, digilines.rules.default, set_channel, beacon.sorted_effect_ids) | ||
|
||
elseif msg.command == "set" then | ||
local level = beacon.get_level(pos) | ||
|
||
if type(msg.effect) == "string" then | ||
if beacon.effects[msg.effect] and beacon.effects[msg.effect].min_level <= level then | ||
meta:set_string("effect", msg.effect) | ||
elseif msg.effect == "none" then | ||
meta:set_string("effect", "none") | ||
end | ||
end | ||
|
||
if type(msg.range) == "number" then | ||
meta:set_int("range", beacon.limit_range(msg.range, level)) | ||
elseif type(msg.radius) == "number" then | ||
meta:set_int("range", beacon.limit_range(msg.radius, level)) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
|
||
function beacon.get_node(pos) | ||
local node = minetest.get_node(pos) | ||
if node.name == "ignore" then | ||
minetest.get_voxel_manip():read_from_map(pos, pos) | ||
node = minetest.get_node(pos) | ||
end | ||
return node | ||
end | ||
|
||
function beacon.is_airlike_node(pos, name) | ||
local node = beacon.get_node(pos) | ||
if node.name == "ignore" then return false end | ||
if node.name == "air" or node.name == "vacuum:vacuum" then return true end | ||
local def = minetest.registered_nodes[node.name] | ||
if def and def.drawtype == "airlike" and def.buildable_to then return true end | ||
return false | ||
end | ||
|
||
function beacon.set_default_meta(pos) | ||
local meta = minetest.get_meta(pos) | ||
meta:set_int("range", beacon.config.effect_range_0) | ||
meta:set_string("effect", beacon.config.default_effect) | ||
meta:set_string("active", "false") | ||
meta:set_string("channel", "beacon_"..pos.x.."_"..pos.y.."_"..pos.z) | ||
meta:get_inventory():set_size("beacon_upgrades", 4) | ||
end | ||
|
||
function beacon.get_level(pos) | ||
local inv = minetest.get_meta(pos):get_inventory() | ||
local level = 0 | ||
for i = 1, inv:get_size("beacon_upgrades") do | ||
local stack = inv:get_stack("beacon_upgrades", i) | ||
if not stack:is_empty() then | ||
level = level + 1 | ||
end | ||
end | ||
return level | ||
end | ||
|
||
function beacon.get_effects_for_level(level) | ||
local names = {"None"} | ||
local ids = {"none"} | ||
for _,id in ipairs(beacon.sorted_effect_ids) do | ||
if beacon.effects[id].min_level <= level then | ||
table.insert(names, minetest.formspec_escape(beacon.effects[id].desc_name)) | ||
table.insert(ids, id) | ||
end | ||
end | ||
return names, ids | ||
end | ||
|
||
function beacon.limit_range(range, level) | ||
local max_range = beacon.config["effect_range_"..level] | ||
range = tonumber(range) | ||
if not range then return max_range end | ||
range = math.min(range, max_range) | ||
range = math.max(range, 1) | ||
return range | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
optional_depends = player_monoids, digilines |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters