2020-01-25 14:15:44 -08:00
|
|
|
--[[
|
|
|
|
|
|
|
|
TechAge
|
|
|
|
=======
|
|
|
|
|
2021-06-09 13:09:59 -07:00
|
|
|
Copyright (C) 2019-2021 Joachim Stolberg
|
2020-01-25 14:15:44 -08:00
|
|
|
|
|
|
|
GPL v3
|
|
|
|
See LICENSE.txt for more information
|
2022-01-03 12:40:31 -08:00
|
|
|
|
2020-01-25 14:15:44 -08:00
|
|
|
Demo for a electrical power consuming node
|
|
|
|
|
|
|
|
]]--
|
|
|
|
|
2019-06-15 07:14:46 -07:00
|
|
|
-- for lazy programmers
|
2020-01-25 14:15:44 -08:00
|
|
|
local P2S = minetest.pos_to_string
|
2019-06-15 07:14:46 -07:00
|
|
|
local M = minetest.get_meta
|
2020-01-25 14:15:44 -08:00
|
|
|
local S = techage.S
|
2019-06-15 07:14:46 -07:00
|
|
|
|
2019-08-08 05:43:45 -07:00
|
|
|
local PWR_NEEDED = 5
|
2020-01-25 14:15:44 -08:00
|
|
|
local CYCLE_TIME = 2
|
2019-06-15 07:14:46 -07:00
|
|
|
|
|
|
|
local Cable = techage.ElectricCable
|
2021-06-05 02:42:30 -07:00
|
|
|
--local Cable = techage.Axle
|
|
|
|
local power = networks.power
|
2019-06-15 07:14:46 -07:00
|
|
|
|
|
|
|
local function swap_node(pos, name)
|
2019-10-06 15:09:39 -07:00
|
|
|
local node = techage.get_node_lvm(pos)
|
2019-06-15 07:14:46 -07:00
|
|
|
if node.name == name then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
node.name = name
|
|
|
|
minetest.swap_node(pos, node)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function on_rightclick(pos, node, clicker)
|
2020-01-25 14:15:44 -08:00
|
|
|
local nvm = techage.get_nvm(pos)
|
|
|
|
if not nvm.running and power.power_available(pos, Cable) then
|
|
|
|
nvm.running = true
|
2021-06-05 02:42:30 -07:00
|
|
|
swap_node(pos, "techage:sink_on")
|
|
|
|
M(pos):set_string("infotext", "on")
|
2020-01-25 14:15:44 -08:00
|
|
|
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
2019-06-15 07:14:46 -07:00
|
|
|
else
|
2020-01-25 14:15:44 -08:00
|
|
|
nvm.running = false
|
2019-06-15 07:14:46 -07:00
|
|
|
swap_node(pos, "techage:sink")
|
2019-08-15 08:06:58 -07:00
|
|
|
M(pos):set_string("infotext", "off")
|
2021-06-05 02:42:30 -07:00
|
|
|
minetest.get_node_timer(pos):stop()
|
2019-06-15 07:14:46 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-10-05 11:53:08 -07:00
|
|
|
local function after_place_node(pos)
|
2020-01-25 14:15:44 -08:00
|
|
|
local nvm = techage.get_nvm(pos)
|
2019-10-05 11:53:08 -07:00
|
|
|
M(pos):set_string("infotext", "off")
|
2020-01-25 14:15:44 -08:00
|
|
|
Cable:after_place_node(pos)
|
2019-10-05 11:53:08 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
local function after_dig_node(pos, oldnode)
|
2020-01-25 14:15:44 -08:00
|
|
|
Cable:after_dig_node(pos)
|
|
|
|
techage.del_mem(pos)
|
2019-10-05 11:53:08 -07:00
|
|
|
end
|
|
|
|
|
2019-06-15 07:14:46 -07:00
|
|
|
minetest.register_node("techage:sink", {
|
|
|
|
description = "Sink",
|
2021-06-05 11:18:04 -07:00
|
|
|
tiles = {'techage_electric_button.png^[colorize:#000000:50'},
|
2022-01-03 12:40:31 -08:00
|
|
|
|
2021-06-05 02:42:30 -07:00
|
|
|
on_timer = function(pos, elapsed)
|
|
|
|
local consumed = power.consume_power(pos, Cable, nil, PWR_NEEDED)
|
|
|
|
if consumed == PWR_NEEDED then
|
|
|
|
swap_node(pos, "techage:sink_on")
|
|
|
|
M(pos):set_string("infotext", "on")
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end,
|
2019-06-15 07:14:46 -07:00
|
|
|
on_rightclick = on_rightclick,
|
2019-10-05 11:53:08 -07:00
|
|
|
after_place_node = after_place_node,
|
|
|
|
after_dig_node = after_dig_node,
|
2019-06-15 07:14:46 -07:00
|
|
|
|
|
|
|
paramtype = "light",
|
2022-01-03 12:40:31 -08:00
|
|
|
light_source = 0,
|
2019-06-15 07:14:46 -07:00
|
|
|
paramtype2 = "facedir",
|
2020-01-25 14:15:44 -08:00
|
|
|
groups = {choppy = 2, cracky = 2, crumbly = 2},
|
2019-06-15 07:14:46 -07:00
|
|
|
is_ground_content = false,
|
|
|
|
sounds = default.node_sound_wood_defaults(),
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_node("techage:sink_on", {
|
|
|
|
description = "Sink",
|
|
|
|
tiles = {'techage_electric_button.png'},
|
2019-10-05 11:53:08 -07:00
|
|
|
|
2021-06-05 02:42:30 -07:00
|
|
|
on_timer = function(pos, elapsed)
|
|
|
|
local consumed = power.consume_power(pos, Cable, nil, PWR_NEEDED)
|
|
|
|
if consumed < PWR_NEEDED then
|
|
|
|
swap_node(pos, "techage:sink")
|
|
|
|
M(pos):set_string("infotext", "off")
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end,
|
2019-06-15 07:14:46 -07:00
|
|
|
on_rightclick = on_rightclick,
|
2019-10-05 11:53:08 -07:00
|
|
|
after_place_node = after_place_node,
|
|
|
|
after_dig_node = after_dig_node,
|
2019-06-15 07:14:46 -07:00
|
|
|
|
|
|
|
paramtype = "light",
|
2022-01-03 12:40:31 -08:00
|
|
|
light_source = minetest.LIGHT_MAX,
|
2019-06-15 07:14:46 -07:00
|
|
|
paramtype2 = "facedir",
|
|
|
|
diggable = false,
|
|
|
|
drop = "",
|
2020-01-25 14:15:44 -08:00
|
|
|
groups = {not_in_creative_inventory = 1},
|
2019-06-15 07:14:46 -07:00
|
|
|
is_ground_content = false,
|
|
|
|
sounds = default.node_sound_wood_defaults(),
|
|
|
|
})
|
|
|
|
|
2022-01-03 12:40:31 -08:00
|
|
|
power.register_nodes({"techage:sink", "techage:sink_on"}, Cable, "con")
|