techage/coal_power_station/turbine.lua

183 lines
4.6 KiB
Lua
Raw Permalink Normal View History

--[[
TechAge
=======
2020-01-26 01:15:44 +03:00
Copyright (C) 2019-2020 Joachim Stolberg
2020-10-19 20:09:17 +03:00
AGPL v3
See LICENSE.txt for more information
2022-01-03 23:40:31 +03:00
2019-05-05 23:29:00 +03:00
TA3 Power Station Turbine
]]--
-- for lazy programmers
local M = minetest.get_meta
local S = techage.S
2019-06-08 23:57:01 +03:00
local Pipe = techage.SteamPipe
2019-06-16 22:06:16 +03:00
local function transfer_cooler(pos, topic, payload)
2022-01-03 23:40:31 +03:00
return techage.transfer(pos, 6, topic, payload, Pipe,
2020-01-26 01:15:44 +03:00
{"techage:cooler", "techage:cooler_on"})
2019-06-16 22:06:16 +03:00
end
local function transfer_generator(pos, topic, payload)
2022-01-03 23:40:31 +03:00
return techage.transfer(pos, "R", topic, payload, nil,
2020-01-26 01:15:44 +03:00
{"techage:generator", "techage:generator_on"})
2019-06-16 22:06:16 +03:00
end
local function swap_node(pos, name)
local node = techage.get_node_lvm(pos)
if node.name == name then
return
end
node.name = name
minetest.swap_node(pos, node)
end
2019-11-11 23:25:20 +03:00
local function play_sound(pos)
2020-01-26 01:15:44 +03:00
local mem = techage.get_mem(pos)
2020-02-02 00:00:58 +03:00
if not mem.handle or mem.handle == -1 then
mem.handle = minetest.sound_play("techage_turbine", {
2022-01-03 23:40:31 +03:00
pos = pos,
2020-02-02 00:00:58 +03:00
gain = 1,
max_hear_distance = 15,
loop = true})
if mem.handle == -1 then
minetest.after(1, play_sound, pos)
end
2019-05-07 20:55:07 +03:00
end
end
2019-05-07 20:55:07 +03:00
local function stop_sound(pos)
2020-01-26 01:15:44 +03:00
local mem = techage.get_mem(pos)
if mem.handle then
2019-05-07 20:55:07 +03:00
minetest.sound_stop(mem.handle)
mem.handle = nil
end
end
2020-01-26 01:15:44 +03:00
local function after_place_node(pos)
Pipe:after_place_node(pos)
end
local function after_dig_node(pos, oldnode)
stop_sound(pos)
Pipe:after_dig_node(pos)
techage.del_mem(pos)
end
2022-01-03 23:40:31 +03:00
local function tubelib2_on_update2(pos, outdir, tlib2, node)
2020-01-26 01:15:44 +03:00
swap_node(pos, "techage:turbine")
stop_sound(pos)
end
2019-05-05 23:29:00 +03:00
minetest.register_node("techage:turbine", {
description = S("TA3 Turbine"),
tiles = {
-- up, down, right, left, back, front
2019-05-05 23:29:00 +03:00
"techage_filling_ta3.png^techage_frame_ta3.png^techage_steam_hole.png",
"techage_filling_ta3.png^techage_frame_ta3.png",
"techage_filling_ta3.png^techage_appl_open.png^techage_frame_ta3.png",
"techage_filling_ta3.png^techage_frame_ta3.png^techage_steam_hole.png",
2023-02-08 20:33:54 +03:00
"techage_filling_ta3.png^techage_appl_turbine.png^techage_frame_ta3.png^[transformFX",
2019-05-05 23:29:00 +03:00
"techage_filling_ta3.png^techage_appl_turbine.png^techage_frame_ta3.png",
},
2022-01-03 23:40:31 +03:00
2020-01-26 01:15:44 +03:00
after_place_node = after_place_node,
after_dig_node = after_dig_node,
tubelib2_on_update2 = tubelib2_on_update2,
2022-01-03 23:40:31 +03:00
paramtype2 = "facedir",
groups = {cracky=2, crumbly=2, choppy=2},
on_rotate = screwdriver.disallow,
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
})
2019-05-05 23:29:00 +03:00
minetest.register_node("techage:turbine_on", {
tiles = {
-- up, down, right, left, back, front
2019-05-05 23:29:00 +03:00
"techage_filling_ta3.png^techage_frame_ta3.png^techage_steam_hole.png",
"techage_filling_ta3.png^techage_frame_ta3.png",
"techage_filling_ta3.png^techage_appl_open.png^techage_frame_ta3.png",
"techage_filling_ta3.png^techage_frame_ta3.png^techage_steam_hole.png",
{
name = "techage_filling4_ta3.png^techage_appl_turbine4.png^techage_frame4_ta3.png^[transformFX",
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
length = 0.4,
},
},
{
name = "techage_filling4_ta3.png^techage_appl_turbine4.png^techage_frame4_ta3.png",
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
length = 0.4,
},
},
},
2022-01-03 23:40:31 +03:00
2020-01-26 01:15:44 +03:00
tubelib2_on_update2 = tubelib2_on_update2,
2022-01-03 23:40:31 +03:00
paramtype2 = "facedir",
groups = {not_in_creative_inventory=1},
diggable = false,
on_rotate = screwdriver.disallow,
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
})
2020-01-26 01:15:44 +03:00
Pipe:add_secondary_node_names({"techage:turbine", "techage:turbine_on"})
2019-06-08 23:57:01 +03:00
techage.register_node({"techage:turbine", "techage:turbine_on"}, {
on_transfer = function(pos, in_dir, topic, payload)
2020-01-26 01:15:44 +03:00
local nvm = techage.get_nvm(pos)
if topic == "trigger" then -- used by boiler
2019-06-16 22:06:16 +03:00
if not transfer_cooler(pos, topic, payload) then
2020-01-26 01:15:44 +03:00
return 0
end
local power = transfer_generator(pos, topic, payload)
if not power or power <= 0 and nvm.running then
2020-02-24 22:59:26 +03:00
swap_node(pos, "techage:turbine")
2019-06-16 22:06:16 +03:00
stop_sound(pos)
2020-01-26 01:15:44 +03:00
nvm.running = false
return 0
2019-06-16 22:06:16 +03:00
end
2020-01-26 01:15:44 +03:00
return power
elseif topic == "start" then -- used by generator
swap_node(pos, "techage:turbine_on")
play_sound(pos)
nvm.running = true
2019-06-16 22:06:16 +03:00
return true
2020-01-26 01:15:44 +03:00
elseif topic == "stop" then -- used by generator
2019-06-08 23:57:01 +03:00
swap_node(pos, "techage:turbine")
stop_sound(pos)
2020-01-26 01:15:44 +03:00
nvm.running = false
2019-06-16 22:06:16 +03:00
return true
2019-06-08 23:57:01 +03:00
end
2020-01-26 01:15:44 +03:00
end,
on_node_load = function(pos, node)
if node.name == "techage:turbine_on" then
play_sound(pos)
2022-01-03 23:40:31 +03:00
end
2020-01-26 01:15:44 +03:00
end,
2019-05-21 17:37:05 +03:00
})
2019-05-05 23:29:00 +03:00
minetest.register_craft({
output = "techage:turbine",
recipe = {
2019-06-08 23:57:01 +03:00
{"basic_materials:steel_bar", "techage:steam_pipeS", "default:wood"},
2019-05-05 23:29:00 +03:00
{"techage:steam_pipeS", "basic_materials:gear_steel", ""},
{"default:wood", "techage:iron_ingot", "basic_materials:steel_bar"},
},
})