forked from Mirrorlandia_minetest/mesecons
Add mesecons delayer
This commit is contained in:
parent
d069275d09
commit
ce87414f6b
@ -72,6 +72,7 @@ dofile(minetest.get_modpath("mesecons").."/settings.lua")
|
||||
mesecon={} -- contains all functions and all global variables
|
||||
mesecon.actions_on={} -- Saves registered function callbacks for mesecon on
|
||||
mesecon.actions_off={} -- Saves registered function callbacks for mesecon off
|
||||
mesecon.actions_change={} -- Saves registered function callbacks for mesecon change
|
||||
mesecon.pwr_srcs={}
|
||||
mesecon.pwr_srcs_off={}
|
||||
mesecon.rules={}
|
||||
@ -140,6 +141,7 @@ function mesecon:turnon(p, x, y, z, firstcall, rules)
|
||||
lpos.y=p.y+y
|
||||
lpos.z=p.z+z
|
||||
|
||||
mesecon:changesignal(lpos)
|
||||
mesecon:activate(lpos)
|
||||
|
||||
local node = minetest.env:get_node(lpos)
|
||||
@ -170,6 +172,8 @@ function mesecon:turnoff(pos, x, y, z, firstcall, rules)
|
||||
local connected = 0
|
||||
local checked = {}
|
||||
|
||||
--Send Signals to effectors:
|
||||
mesecon:changesignal(lpos)
|
||||
if not mesecon:check_if_turnon(lpos) then
|
||||
mesecon:deactivate(lpos)
|
||||
end
|
||||
@ -278,6 +282,7 @@ minetest.register_on_placenode(function(pos, newnode, placer)
|
||||
if newnode.name == "mesecons:mesecon_off" then
|
||||
mesecon:turnon(pos, 0, 0, 0)
|
||||
else
|
||||
mesecon:changesignal(pos)
|
||||
mesecon:activate(pos)
|
||||
end
|
||||
end
|
||||
@ -349,6 +354,15 @@ function mesecon:register_on_signal_off(action)
|
||||
mesecon.actions_off[i]=action
|
||||
end
|
||||
|
||||
function mesecon:register_on_signal_change(action)
|
||||
local i = 1
|
||||
repeat
|
||||
i=i+1
|
||||
if mesecon.actions_change[i]==nil then break end
|
||||
until false
|
||||
mesecon.actions_change[i]=action
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- INTERNAL API
|
||||
@ -427,7 +441,6 @@ end
|
||||
function mesecon:deactivate(pos)
|
||||
local node = minetest.env:get_node(pos)
|
||||
local i = 1
|
||||
local checked={}
|
||||
repeat
|
||||
i=i+1
|
||||
if mesecon.actions_off[i]~=nil then mesecon.actions_off[i](pos, node)
|
||||
@ -436,6 +449,17 @@ function mesecon:deactivate(pos)
|
||||
until false
|
||||
end
|
||||
|
||||
function mesecon:changesignal(pos)
|
||||
local node = minetest.env:get_node(pos)
|
||||
local i = 1
|
||||
repeat
|
||||
i=i+1
|
||||
if mesecon.actions_change[i]~=nil then mesecon.actions_change[i](pos, node)
|
||||
else break
|
||||
end
|
||||
until false
|
||||
end
|
||||
|
||||
|
||||
mesecon:register_on_signal_on(function(pos, node)
|
||||
if node.name=="mesecons:meselamp_off" then
|
||||
|
207
mesecons_delayer/init.lua
Normal file
207
mesecons_delayer/init.lua
Normal file
@ -0,0 +1,207 @@
|
||||
minetest.register_node("mesecons_delayer:delayer_off_1", {
|
||||
description = "Delayer",
|
||||
drawtype = "raillike",
|
||||
tile_images = {"mesecons_delayer_off_1.png"},
|
||||
inventory_image = "mesecons_delayer_off_1.png",
|
||||
walkable = false,
|
||||
selection_box = {type = "fixed",},
|
||||
groups = {bendy=2,snappy=1,dig_immediate=2},
|
||||
paramtype = "light",
|
||||
drop = 'mesecons_delayer:delayer_off_1',
|
||||
})
|
||||
|
||||
minetest.register_node("mesecons_delayer:delayer_off_2", {
|
||||
description = "Delayer",
|
||||
drawtype = "raillike",
|
||||
tile_images = {"mesecons_delayer_off_2.png"},
|
||||
inventory_image = "mesecons_delayer_off_2.png",
|
||||
walkable = false,
|
||||
selection_box = {type = "fixed",},
|
||||
groups = {bendy=2,snappy=1,dig_immediate=2},
|
||||
paramtype = "light",
|
||||
drop = 'mesecons_delayer:delayer_off_1',
|
||||
})
|
||||
|
||||
minetest.register_node("mesecons_delayer:delayer_off_3", {
|
||||
description = "Delayer",
|
||||
drawtype = "raillike",
|
||||
tile_images = {"mesecons_delayer_off_3.png"},
|
||||
inventory_image = "mesecons_delayer_off_3.png",
|
||||
walkable = false,
|
||||
selection_box = {type = "fixed",},
|
||||
groups = {bendy=2,snappy=1,dig_immediate=2},
|
||||
paramtype = "light",
|
||||
drop = 'mesecons_delayer:delayer_off_1',
|
||||
})
|
||||
|
||||
minetest.register_node("mesecons_delayer:delayer_off_4", {
|
||||
description = "Delayer",
|
||||
drawtype = "raillike",
|
||||
tile_images = {"mesecons_delayer_off_4.png"},
|
||||
inventory_image = "mesecons_delayer_off_4.png",
|
||||
walkable = false,
|
||||
selection_box = {type = "fixed",},
|
||||
groups = {bendy=2,snappy=1,dig_immediate=2},
|
||||
paramtype = "light",
|
||||
drop = 'mesecons_delayer:delayer_off_1',
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
minetest.register_node("mesecons_delayer:delayer_on_1", {
|
||||
description = "Delayer",
|
||||
drawtype = "raillike",
|
||||
tile_images = {"mesecons_delayer_on_1.png"},
|
||||
inventory_image = "mesecons_delayer_on_1.png",
|
||||
walkable = false,
|
||||
selection_box = {type = "fixed",},
|
||||
groups = {bendy=2,snappy=1,dig_immediate=2},
|
||||
paramtype = "light",
|
||||
drop = 'mesecons_delayer:delayer_off_1',
|
||||
})
|
||||
|
||||
minetest.register_node("mesecons_delayer:delayer_on_2", {
|
||||
description = "Delayer",
|
||||
drawtype = "raillike",
|
||||
tile_images = {"mesecons_delayer_on_2.png"},
|
||||
inventory_image = "mesecons_delayer_on_2.png",
|
||||
walkable = false,
|
||||
selection_box = {type = "fixed",},
|
||||
groups = {bendy=2,snappy=1,dig_immediate=2},
|
||||
paramtype = "light",
|
||||
drop = 'mesecons_delayer:delayer_off_1',
|
||||
})
|
||||
|
||||
minetest.register_node("mesecons_delayer:delayer_on_3", {
|
||||
description = "Delayer",
|
||||
drawtype = "raillike",
|
||||
tile_images = {"mesecons_delayer_on_3.png"},
|
||||
inventory_image = "mesecons_delayer_on_3.png",
|
||||
walkable = false,
|
||||
selection_box = {type = "fixed",},
|
||||
groups = {bendy=2,snappy=1,dig_immediate=2},
|
||||
paramtype = "light",
|
||||
drop = 'mesecons_delayer:delayer_off_1',
|
||||
})
|
||||
|
||||
minetest.register_node("mesecons_delayer:delayer_on_4", {
|
||||
description = "Delayer",
|
||||
drawtype = "raillike",
|
||||
tile_images = {"mesecons_delayer_on_4.png"},
|
||||
inventory_image = "mesecons_delayer_on_4.png",
|
||||
walkable = false,
|
||||
selection_box = {type = "fixed",},
|
||||
groups = {bendy=2,snappy=1,dig_immediate=2},
|
||||
paramtype = "light",
|
||||
drop = 'mesecons_delayer:delayer_off_1',
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
minetest.register_on_punchnode(function (pos, node)
|
||||
if node.name=="mesecons_delayer:delayer_off_1" then
|
||||
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_2"})
|
||||
end
|
||||
if node.name=="mesecons_delayer:delayer_off_2" then
|
||||
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_3"})
|
||||
end
|
||||
if node.name=="mesecons_delayer:delayer_off_3" then
|
||||
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_4"})
|
||||
end
|
||||
if node.name=="mesecons_delayer:delayer_off_4" then
|
||||
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_1"})
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_on_punchnode(function (pos, node)
|
||||
if node.name=="mesecons_delayer:delayer_on_1" then
|
||||
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_2"})
|
||||
end
|
||||
if node.name=="mesecons_delayer:delayer_on_2" then
|
||||
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_3"})
|
||||
end
|
||||
if node.name=="mesecons_delayer:delayer_on_3" then
|
||||
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_4"})
|
||||
end
|
||||
if node.name=="mesecons_delayer:delayer_on_4" then
|
||||
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_1"})
|
||||
end
|
||||
end)
|
||||
|
||||
mesecon.delayer_signal_change = function(pos, node)
|
||||
print "CHANGE"
|
||||
if string.find(node.name, "mesecons_delayer:delayer_off")~=nil then
|
||||
np={x=pos.x-1, y=pos.y, z=pos.z}
|
||||
nn=minetest.env:get_node(np)
|
||||
if nn.name=="mesecons:mesecon_on" or mesecon:is_receptor_node(nn.name, np, pos) then
|
||||
local time
|
||||
if node.name=="mesecons_delayer:delayer_off_1" then
|
||||
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_1"})
|
||||
time=0.5
|
||||
end
|
||||
if node.name=="mesecons_delayer:delayer_off_2" then
|
||||
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_2"})
|
||||
time=1
|
||||
end
|
||||
if node.name=="mesecons_delayer:delayer_off_3" then
|
||||
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_3"})
|
||||
time=1.5
|
||||
end
|
||||
if node.name=="mesecons_delayer:delayer_off_4" then
|
||||
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_4"})
|
||||
time=2
|
||||
end
|
||||
minetest.after(time, mesecon.delayer_turnon, {pos=pos})
|
||||
|
||||
end
|
||||
end
|
||||
if string.find(node.name, "mesecons_delayer:delayer_on")~=nil then
|
||||
np={x=pos.x-1, y=pos.y, z=pos.z}
|
||||
nn=minetest.env:get_node(np)
|
||||
if nn.name=="mesecons:mesecon_off" or mesecon:is_receptor_node_off(nn.name, np, pos) or nn.name=="air" then
|
||||
local time
|
||||
if node.name=="mesecons_delayer:delayer_on_1" then
|
||||
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_1"})
|
||||
time=0.5
|
||||
end
|
||||
if node.name=="mesecons_delayer:delayer_on_2" then
|
||||
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_2"})
|
||||
time=1
|
||||
end
|
||||
if node.name=="mesecons_delayer:delayer_on_3" then
|
||||
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_3"})
|
||||
time=1.5
|
||||
end
|
||||
if node.name=="mesecons_delayer:delayer_on_4" then
|
||||
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_4"})
|
||||
time=2
|
||||
end
|
||||
minetest.after(time, mesecon.delayer_turnoff, {pos=pos})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
mesecon:register_on_signal_change(mesecon.delayer_signal_change)
|
||||
|
||||
mesecon.delayer_turnon=function(params)
|
||||
mesecon:receptor_on(params.pos, mesecon:get_rules("delayer"))
|
||||
end
|
||||
|
||||
mesecon.delayer_turnoff=function(params)
|
||||
mesecon:receptor_off(params.pos, mesecon:get_rules("delayer"))
|
||||
end
|
||||
|
||||
mesecon:add_rules("delayer", {{x=1, y=0, z=0}})
|
||||
|
||||
mesecon:add_receptor_node("mesecons_delayer:delayer_on_1", mesecon:get_rules("delayer"))
|
||||
mesecon:add_receptor_node("mesecons_delayer:delayer_on_2", mesecon:get_rules("delayer"))
|
||||
mesecon:add_receptor_node("mesecons_delayer:delayer_on_3", mesecon:get_rules("delayer"))
|
||||
mesecon:add_receptor_node("mesecons_delayer:delayer_on_4", mesecon:get_rules("delayer"))
|
||||
|
||||
mesecon:add_receptor_node_off("mesecons_delayer:delayer_off_1", mesecon:get_rules("delayer"))
|
||||
mesecon:add_receptor_node_off("mesecons_delayer:delayer_off_2", mesecon:get_rules("delayer"))
|
||||
mesecon:add_receptor_node_off("mesecons_delayer:delayer_off_3", mesecon:get_rules("delayer"))
|
||||
mesecon:add_receptor_node_off("mesecons_delayer:delayer_off_4", mesecon:get_rules("delayer"))
|
Loading…
Reference in New Issue
Block a user