techage/.test/switch.lua

47 lines
1.2 KiB
Lua
Raw Normal View History

2019-06-15 17:14:46 +03:00
-- for lazy programmers
local S = function(pos) if pos then return minetest.pos_to_string(pos) end end
local P = minetest.string_to_pos
local M = minetest.get_meta
local Cable = techage.ElectricCable
2019-08-08 15:43:45 +03:00
local power_switched = techage.power.power_switched
2019-06-15 17:14:46 +03:00
local function on_rightclick(pos, node, clicker)
local mem = tubelib2.get_mem(pos)
mem.interrupted_dirs = mem.interrupted_dirs or {}
mem.interrupted = not mem.interrupted
2019-08-08 15:43:45 +03:00
--print("switch", mem.interrupted)
2019-06-15 17:14:46 +03:00
if mem.interrupted then
mem.interrupted_dirs = {true, true, true, true, true, true}
for dir,_ in pairs(mem.connections) do
mem.interrupted_dirs[dir] = false
power_switched(pos)
mem.interrupted_dirs[dir] = true
end
else
mem.interrupted_dirs = {}
power_switched(pos)
end
end
minetest.register_node("techage:switch", {
description = "Switch",
tiles = {'techage_appl_switch_inv.png'},
2019-08-08 15:43:45 +03:00
--on_timer = node_timer,
2019-06-15 17:14:46 +03:00
on_rightclick = on_rightclick,
paramtype = "light",
light_source = 0,
sunlight_propagates = true,
paramtype2 = "facedir",
groups = {choppy=2, cracky=2, crumbly=2},
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
})
techage.power2.register_node({"techage:switch"}, {
power_network = Cable,
})