techage/chemistry/ta4_stand.lua

210 lines
5.4 KiB
Lua
Raw Permalink Normal View History

2019-11-11 23:25:20 +03:00
--[[
TechAge
=======
Copyright (C) 2019-2021 Joachim Stolberg
2019-11-11 23:25:20 +03:00
2020-10-19 20:09:17 +03:00
AGPL v3
2019-11-11 23:25:20 +03:00
See LICENSE.txt for more information
2022-01-03 23:40:31 +03:00
2019-11-11 23:25:20 +03:00
TA4 Reactor Stand and Base
]]--
local S = techage.S
local M = minetest.get_meta
local Cable = techage.ElectricCable
local Pipe = techage.LiquidPipe
local power = networks.power
local liquid = networks.liquid
2019-11-11 23:25:20 +03:00
local PWR_NEEDED = 8
local CYCLE_TIME = 2
2019-11-11 23:25:20 +03:00
local function play_sound(pos)
local mem = techage.get_mem(pos)
if not mem.handle or mem.handle == -1 then
mem.handle = minetest.sound_play("techage_reactor", {
2022-01-03 23:40:31 +03:00
pos = pos,
gain = 0.5,
max_hear_distance = 10,
loop = true})
if mem.handle == -1 then
minetest.after(1, play_sound, pos)
end
end
end
local function stop_sound(pos)
local mem = techage.get_mem(pos)
if mem.handle then
minetest.sound_stop(mem.handle)
mem.handle = nil
2019-11-11 23:25:20 +03:00
end
end
local function on_power(pos)
M(pos):set_string("infotext", S("on"))
play_sound(pos)
local nvm = techage.get_nvm(pos)
nvm.running = true
end
local function on_nopower(pos)
2019-11-11 23:25:20 +03:00
M(pos):set_string("infotext", S("no power"))
stop_sound(pos)
local nvm = techage.get_nvm(pos)
nvm.running = false
2019-11-11 23:25:20 +03:00
end
2022-01-03 23:40:31 +03:00
local function is_running(pos, nvm)
return nvm.running
end
2019-11-11 23:25:20 +03:00
minetest.register_node("techage:ta4_reactor_stand", {
description = S("TA4 Reactor Stand"),
2019-11-11 23:25:20 +03:00
tiles = {
-- up, down, right, left, back, front
"techage_reactor_stand_top.png^[transformR90",
"techage_reactor_stand_bottom.png^[transformFY^[transformR270",
"techage_reactor_stand_front.png",
"techage_reactor_stand_back.png",
"techage_reactor_stand_side.png^[transformFX",
"techage_reactor_stand_side.png",
},
drawtype = "nodebox",
node_box = {
type = "fixed",
2022-01-03 23:40:31 +03:00
fixed = {
2019-11-11 23:25:20 +03:00
{ -8/16, 2/16, -8/16, 8/16, 4/16, 8/16 },
2022-01-03 23:40:31 +03:00
2019-11-11 23:25:20 +03:00
{ -8/16, -8/16, -8/16, -6/16, 8/16, -6/16 },
{ 6/16, -8/16, -8/16, 8/16, 8/16, -6/16 },
{ -8/16, -8/16, 6/16, -6/16, 8/16, 8/16 },
{ 6/16, -8/16, 6/16, 8/16, 8/16, 8/16 },
2022-01-03 23:40:31 +03:00
2019-11-11 23:25:20 +03:00
{-1/8, -4/8, -1/8, 1/8, 4/8, 1/8},
{-4/8, -1/8, -1/8, 4/8, 1/8, 1/8},
{-4/8, -1/8, -3/8, -3/8, 1/8, 3/8},
{ 3/8, -1/8, -3/8, 4/8, 1/8, 3/8},
},
},
selection_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, 1/2, 1/2},
},
2022-01-03 23:40:31 +03:00
2019-11-11 23:25:20 +03:00
after_place_node = function(pos, placer)
2020-01-31 21:55:10 +03:00
local nvm = techage.get_nvm(pos)
2019-11-11 23:25:20 +03:00
M(pos):set_string("infotext", S("off"))
M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
Pipe:after_place_node(pos)
Cable:after_place_node(pos)
2019-11-11 23:25:20 +03:00
end,
on_timer = function(pos, elapsed)
local nvm = techage.get_nvm(pos)
local consumed = power.consume_power(pos, Cable, nil, PWR_NEEDED)
if not nvm.running and consumed == PWR_NEEDED then
on_power(pos)
elseif nvm.running and consumed < PWR_NEEDED then
on_nopower(pos)
end
return true
2019-11-11 23:25:20 +03:00
end,
after_dig_node = function(pos, oldnode)
Pipe:after_dig_node(pos)
Cable:after_dig_node(pos)
2020-01-31 21:55:10 +03:00
techage.del_mem(pos)
2019-11-11 23:25:20 +03:00
end,
2022-01-03 23:40:31 +03:00
2019-11-11 23:25:20 +03:00
paramtype = "light",
use_texture_alpha = techage.CLIP,
2019-11-11 23:25:20 +03:00
paramtype2 = "facedir",
on_rotate = screwdriver.disallow,
groups = {cracky=2},
is_ground_content = false,
sounds = default.node_sound_metal_defaults(),
})
-- controlled by the fillerpipe
techage.register_node({"techage:ta4_reactor_stand"}, {
on_transfer = function(pos, in_dir, topic, payload)
2020-01-31 21:55:10 +03:00
local nvm = techage.get_nvm(pos)
2019-11-11 23:25:20 +03:00
if topic == "power" then
return nvm.running or power.power_available(pos, Cable)
2019-11-11 23:25:20 +03:00
elseif topic == "output" then
local outdir = M(pos):get_int("outdir")
2021-06-09 23:09:59 +03:00
return liquid.put(pos, Pipe, outdir, payload.name, payload.amount, payload.player_name)
2019-11-11 23:25:20 +03:00
elseif topic == "can_start" then
2020-01-31 21:55:10 +03:00
return power.power_available(pos, Cable)
elseif topic == "start" then
nvm.running = false
minetest.get_node_timer(pos):start(CYCLE_TIME)
2019-11-11 23:25:20 +03:00
M(pos):set_string("infotext", "...")
return true
elseif topic == "stop" then
2020-01-31 21:55:10 +03:00
nvm.has_power = false
stop_sound(pos)
2019-11-11 23:25:20 +03:00
minetest.get_node_timer(pos):stop()
M(pos):set_string("infotext", S("off"))
return true
end
end,
on_node_load = function(pos, node)
local nvm = techage.get_nvm(pos)
if nvm.has_power then
play_sound(pos)
2022-01-03 23:40:31 +03:00
end
end,
2019-11-11 23:25:20 +03:00
})
minetest.register_node("techage:ta4_reactor_base", {
description = S("TA4 Reactor Base"),
tiles = {
-- up, down, right, left, back, front
"techage_concrete.png^techage_appl_arrowXL.png^techage_appl_hole_pipe.png^[transformR270",
"techage_concrete.png",
"techage_concrete.png^techage_appl_hole_pipe.png",
"techage_concrete.png",
"techage_concrete.png",
"techage_concrete.png",
},
2022-01-03 23:40:31 +03:00
2019-11-11 23:25:20 +03:00
after_place_node = function(pos, placer)
M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
Pipe:after_place_node(pos)
end,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
Pipe:after_dig_node(pos)
end,
2022-01-03 23:40:31 +03:00
2019-11-11 23:25:20 +03:00
paramtype2 = "facedir",
on_rotate = screwdriver.disallow,
groups = {cracky=2},
is_ground_content = false,
sounds = default.node_sound_stone_defaults(),
})
liquid.register_nodes({"techage:ta4_reactor_base"}, Pipe, "pump", {"R"}, {})
liquid.register_nodes({"techage:ta4_reactor_stand"}, Pipe, "pump", {"R"}, {})
power.register_nodes({"techage:ta4_reactor_stand"}, Cable, "con", {"L"})
minetest.register_craft({
output = 'techage:ta4_reactor_stand',
recipe = {
{'', 'dye:blue', ''},
{'basic_materials:steel_bar', 'techage:ta3_pipeS', 'basic_materials:steel_bar'},
{'basic_materials:steel_bar', '', 'basic_materials:steel_bar'},
}
})
minetest.register_craft({
output = 'techage:ta4_reactor_base',
recipe = {
{'basic_materials:concrete_block', '', ''},
{'techage:ta3_pipeS', '', ''},
{'', '', ''},
}
})