local activator_table = {} -- this holds the translation data of activator tables (activator functions)
local capacitor_table = {}
+local player_detection_table = {}
-- redstone class
redstone = {}
+redstone.player_detector_add = function(pos)
+ player_detection_table[minetest.serialize(pos)] = pos
+end
+
+redstone.player_detector_remove = function(pos)
+ player_detection_table[minetest.serialize(pos)] = nil
+end
+
+
-- enables mods to create data functions
function redstone.register_activator(data)
activator_table[data.name] = {
dofile(path.."/craft.lua")
--dofile(path.."/ore.lua")
dofile(path.."/inverter.lua")
---dofile(path.."/player_detector.lua")
+dofile(path.."/player_detector.lua")
dofile(path.."/space_maker.lua")
--dofile(path.."/pressure_plate.lua")
dofile(path.."/capacitors.lua")
calculate(pos,is_capacitor)
end
+
+local level
+local pos2
+local power
+local max
+local function player_detector_calculation()
+ for _,pos in pairs(player_detection_table) do
+ level = pool[pos.x][pos.y][pos.z].torch
+ max = 0
+ for _,player in ipairs(minetest.get_connected_players()) do
+ pos2 = player:get_pos()
+ power = floor(10-vector_distance(pos2,pos))
+ if power > 9 then
+ power = 9
+ elseif power < 0 then
+ power = 0
+ end
+
+ if power > max then
+ max = power
+ end
+ end
+
+ if max ~= level then
+ swap_node(pos,{name="redstone:player_detector_"..max})
+ redstone.inject(pos,{
+ name = "redstone:player_detector_"..max,
+ torch = max,
+ })
+ redstone.update(pos)
+ end
+ end
+end
+
minetest.register_globalstep(function()
+ player_detector_calculation()
recursion_check = {}
end)
-local minetest,ipairs,math = minetest,ipairs,math
+local
+minetest,ipairs,math
+=
+minetest,ipairs,math
+
--detects players and outputs accordingly
for i = 0,9 do
+
minetest.register_node("redstone:player_detector_"..i, {
description = "Redstone Player Detector",
- --inventory_image = "redstone_torch.png",
- --wield_image = "redstone_torch.png",
- --wield_scale = {x = 1, y = 1, z = 1 + 2/16},
drawtype = "normal",
tiles = {"player_detector.png"},
paramtype = "light",
paramtype2 = "none",
- power = 9,
- --sunlight_propagates = true,
drop = "redstone:player_detector_0",
- --walkable = false,
- light_source = i,
groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4, torch=1,redstone=1,redstone_torch=1,redstone_power=i, redstone_player_detection = 1},
legacy_wallmounted = true,
on_construct = function(pos)
- redstone.collect_info(pos)
+ redstone.inject(pos,{
+ name = "redstone:player_detector_"..i,
+ torch = i,
+ })
+ redstone.player_detector_add(pos)
+ redstone.update(pos)
end,
- after_destruct = function(pos, oldnode)
- redstone.collect_info(pos)
+ on_destruct = function(pos, oldnode)
+ redstone.player_detector_remove(pos)
+ redstone.inject(pos,nil)
+ redstone.update(pos)
end,
sounds = main.stoneSound(),
})
+
+minetest.register_lbm({
+ name = "redstone:player_detector_"..i,
+ nodenames = {"redstone:player_detector_"..i},
+ run_at_every_load = true,
+ action = function(pos)
+ redstone.inject(pos,{
+ name = "redstone:player_detector_"..i,
+ torch = i,
+ })
+ redstone.player_detector_add(pos)
+ end,
+})
+
end
+--[[
+
minetest.register_abm{
label = "Redstone Player Detection",
nodenames = {"group:redstone_player_detection"},
end
end
if found_player == false then
- minetest.set_node(pos,{name="redstone:player_detector_0"})
+ minetest.swap_node(pos,{name="redstone:player_detector_0"})
redstone.collect_info(pos)
end
end,
}
+]]--
\ No newline at end of file