2019-03-02 03:24:48 -08:00
|
|
|
--[[
|
|
|
|
|
|
|
|
TechAge
|
|
|
|
=======
|
|
|
|
|
2020-01-25 14:15:44 -08:00
|
|
|
Copyright (C) 2019-2020 Joachim Stolberg
|
2019-03-02 03:24:48 -08:00
|
|
|
|
2020-10-19 10:09:17 -07:00
|
|
|
AGPL v3
|
2019-03-02 03:24:48 -08:00
|
|
|
See LICENSE.txt for more information
|
2022-01-03 12:40:31 -08:00
|
|
|
|
2019-03-02 03:24:48 -08:00
|
|
|
TA2 Steam Engine Cylinder
|
|
|
|
|
|
|
|
]]--
|
|
|
|
|
|
|
|
-- for lazy programmers
|
|
|
|
local M = minetest.get_meta
|
2019-07-02 12:33:12 -07:00
|
|
|
local S = techage.S
|
2019-03-02 03:24:48 -08:00
|
|
|
|
2019-03-08 12:18:55 -08:00
|
|
|
local Pipe = techage.SteamPipe
|
2019-03-02 03:24:48 -08:00
|
|
|
|
2020-01-25 14:15:44 -08:00
|
|
|
local function transfer_flywheel(pos, topic, payload)
|
2022-01-03 12:40:31 -08:00
|
|
|
return techage.transfer(pos, "R", topic, payload, nil,
|
2020-01-25 14:15:44 -08:00
|
|
|
{"techage:flywheel", "techage:flywheel_on"})
|
|
|
|
end
|
|
|
|
|
2019-03-02 03:24:48 -08:00
|
|
|
local function swap_node(pos, name)
|
2019-10-06 15:09:39 -07:00
|
|
|
local node = techage.get_node_lvm(pos)
|
2019-03-02 03:24:48 -08:00
|
|
|
if node.name == name then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
node.name = name
|
|
|
|
minetest.swap_node(pos, node)
|
|
|
|
end
|
|
|
|
|
2020-01-25 14:15:44 -08:00
|
|
|
local function play_sound(pos)
|
|
|
|
local mem = techage.get_mem(pos)
|
2020-02-01 13:00:58 -08:00
|
|
|
if not mem.handle or mem.handle == -1 then
|
|
|
|
mem.handle = minetest.sound_play("techage_steamengine", {
|
2022-01-03 12:40:31 -08:00
|
|
|
pos = pos,
|
2020-02-01 13:00:58 -08:00
|
|
|
gain = 0.5,
|
2020-02-24 11:59:26 -08:00
|
|
|
max_hear_distance = 8,
|
2020-02-01 13:00:58 -08:00
|
|
|
loop = true})
|
|
|
|
if mem.handle == -1 then
|
|
|
|
minetest.after(1, play_sound, pos)
|
|
|
|
end
|
2020-01-25 14:15:44 -08:00
|
|
|
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
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
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 12:40:31 -08:00
|
|
|
local function tubelib2_on_update2(pos, outdir, tlib2, node)
|
2020-01-25 14:15:44 -08:00
|
|
|
swap_node(pos, "techage:cylinder")
|
|
|
|
stop_sound(pos)
|
|
|
|
end
|
|
|
|
|
2019-03-02 03:24:48 -08:00
|
|
|
minetest.register_node("techage:cylinder", {
|
2019-07-02 12:33:12 -07:00
|
|
|
description = S("TA2 Cylinder"),
|
2019-03-02 03:24:48 -08:00
|
|
|
tiles = {
|
|
|
|
-- up, down, right, left, back, front
|
|
|
|
"techage_filling_ta2.png^techage_frame_ta2.png",
|
|
|
|
"techage_filling_ta2.png^techage_frame_ta2.png",
|
2019-03-02 11:51:16 -08:00
|
|
|
"techage_filling_ta2.png^techage_appl_open.png^techage_frame_ta2.png",
|
|
|
|
"techage_filling_ta2.png^techage_frame_ta2.png^techage_steam_hole.png",
|
2019-03-02 03:24:48 -08:00
|
|
|
"techage_filling_ta2.png^techage_cylinder.png^techage_frame_ta2.png",
|
|
|
|
"techage_filling_ta2.png^techage_cylinder.png^techage_frame_ta2.png",
|
|
|
|
},
|
2022-01-03 12:40:31 -08:00
|
|
|
|
2020-01-25 14:15:44 -08:00
|
|
|
after_place_node = after_place_node,
|
|
|
|
after_dig_node = after_dig_node,
|
|
|
|
tubelib2_on_update2 = tubelib2_on_update2,
|
2022-01-03 12:40:31 -08:00
|
|
|
|
2019-03-02 03:24:48 -08:00
|
|
|
paramtype2 = "facedir",
|
|
|
|
groups = {cracky=2, crumbly=2, choppy=2},
|
|
|
|
on_rotate = screwdriver.disallow,
|
|
|
|
is_ground_content = false,
|
|
|
|
sounds = default.node_sound_wood_defaults(),
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_node("techage:cylinder_on", {
|
2019-07-02 12:33:12 -07:00
|
|
|
description = S("TA2 Cylinder"),
|
2019-03-02 03:24:48 -08:00
|
|
|
tiles = {
|
|
|
|
-- up, down, right, left, back, front
|
|
|
|
"techage_filling_ta2.png^techage_frame_ta2.png",
|
|
|
|
"techage_filling_ta2.png^techage_frame_ta2.png",
|
2019-03-02 11:51:16 -08:00
|
|
|
"techage_filling_ta2.png^techage_appl_open.png^techage_frame_ta2.png",
|
|
|
|
"techage_filling_ta2.png^techage_frame_ta2.png^techage_steam_hole.png",
|
2019-03-02 03:24:48 -08:00
|
|
|
{
|
|
|
|
image = "techage_filling4_ta2.png^techage_cylinder4.png^techage_frame4_ta2.png",
|
|
|
|
backface_culling = false,
|
|
|
|
animation = {
|
|
|
|
type = "vertical_frames",
|
|
|
|
aspect_w = 32,
|
|
|
|
aspect_h = 32,
|
|
|
|
length = 0.4,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
image = "techage_filling4_ta2.png^techage_cylinder4.png^techage_frame4_ta2.png",
|
|
|
|
backface_culling = false,
|
|
|
|
animation = {
|
|
|
|
type = "vertical_frames",
|
|
|
|
aspect_w = 32,
|
|
|
|
aspect_h = 32,
|
|
|
|
length = 0.4,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-01-03 12:40:31 -08:00
|
|
|
|
2020-01-25 14:15:44 -08:00
|
|
|
tubelib2_on_update2 = tubelib2_on_update2,
|
2022-01-03 12:40:31 -08:00
|
|
|
|
2019-03-02 03:24:48 -08:00
|
|
|
paramtype2 = "facedir",
|
2019-03-02 11:51:16 -08:00
|
|
|
groups = {not_in_creative_inventory=1},
|
|
|
|
diggable = false,
|
2019-03-02 03:24:48 -08:00
|
|
|
on_rotate = screwdriver.disallow,
|
|
|
|
is_ground_content = false,
|
2019-03-02 11:51:16 -08:00
|
|
|
sounds = default.node_sound_wood_defaults(),
|
2019-03-02 03:24:48 -08:00
|
|
|
})
|
|
|
|
|
2020-01-25 14:15:44 -08:00
|
|
|
Pipe:add_secondary_node_names({"techage:cylinder", "techage:cylinder_on"})
|
2019-05-20 15:05:53 -07:00
|
|
|
|
2019-06-08 13:57:01 -07:00
|
|
|
techage.register_node({"techage:cylinder", "techage:cylinder_on"}, {
|
|
|
|
on_transfer = function(pos, in_dir, topic, payload)
|
2020-01-25 14:15:44 -08:00
|
|
|
local nvm = techage.get_nvm(pos)
|
|
|
|
if topic == "trigger" then -- used by firebox
|
|
|
|
local power = transfer_flywheel(pos, topic, payload)
|
|
|
|
if not power or power <= 0 and nvm.running then
|
2019-06-16 12:06:16 -07:00
|
|
|
swap_node(pos, "techage:cylinder")
|
2020-01-25 14:15:44 -08:00
|
|
|
stop_sound(pos)
|
|
|
|
nvm.running = false
|
2019-06-16 12:06:16 -07:00
|
|
|
return 0
|
|
|
|
end
|
2020-01-25 14:15:44 -08:00
|
|
|
return power
|
|
|
|
elseif topic == "start" then -- used by flywheel
|
|
|
|
swap_node(pos, "techage:cylinder_on")
|
|
|
|
play_sound(pos)
|
|
|
|
nvm.running = true
|
|
|
|
return true
|
|
|
|
elseif topic == "stop" then -- used by flywheel
|
2019-06-16 12:06:16 -07:00
|
|
|
swap_node(pos, "techage:cylinder")
|
2020-01-25 14:15:44 -08:00
|
|
|
stop_sound(pos)
|
|
|
|
nvm.running = false
|
|
|
|
return true
|
2019-06-08 13:57:01 -07:00
|
|
|
end
|
2020-01-25 14:15:44 -08:00
|
|
|
end,
|
|
|
|
on_node_load = function(pos, node)
|
|
|
|
--print("on_node_load", node.name)
|
|
|
|
if node.name == "techage:cylinder_on" then
|
|
|
|
play_sound(pos)
|
2022-01-03 12:40:31 -08:00
|
|
|
end
|
2020-01-25 14:15:44 -08:00
|
|
|
end,
|
2019-06-08 13:57:01 -07:00
|
|
|
})
|
|
|
|
|
2019-04-28 07:04:45 -07:00
|
|
|
minetest.register_craft({
|
|
|
|
output = "techage:cylinder",
|
|
|
|
recipe = {
|
|
|
|
{"basic_materials:steel_bar", "techage:iron_ingot", "default:wood"},
|
|
|
|
{"techage:steam_pipeS", "basic_materials:gear_steel", ""},
|
|
|
|
{"default:wood", "techage:iron_ingot", "basic_materials:steel_bar"},
|
|
|
|
},
|
|
|
|
})
|