techage_modpack/techage/energy_storage/generator.lua

131 lines
3.5 KiB
Lua
Raw Normal View History

2020-05-31 23:31:18 +03:00
--[[
TechAge
=======
2021-08-01 12:00:22 +03:00
Copyright (C) 2019-2021 Joachim Stolberg
2020-05-31 23:31:18 +03:00
2020-10-25 23:32:47 +03:00
AGPL v3
2020-05-31 23:31:18 +03:00
See LICENSE.txt for more information
2022-01-04 21:43:30 +03:00
2021-08-01 12:00:22 +03:00
TA4 TES Generator (dummy)
- can be started and stopped
- provides netID of cable network
2020-05-31 23:31:18 +03:00
]]--
-- for lazy programmers
local M = minetest.get_meta
local S = techage.S
local Cable = techage.ElectricCable
2021-08-01 12:00:22 +03:00
local power = networks.power
2020-05-31 23:31:18 +03:00
2021-08-01 12:00:22 +03:00
local function swap_node(pos, name)
local node = techage.get_node_lvm(pos)
if node.name == name then
2020-05-31 23:31:18 +03:00
return
end
2021-08-01 12:00:22 +03:00
node.name = name
minetest.swap_node(pos, node)
2020-05-31 23:31:18 +03:00
end
minetest.register_node("techage:ta4_generator", {
description = S("TA4 Generator"),
tiles = {
-- up, down, right, left, back, front
"techage_filling_ta4.png^techage_frame_ta4_top.png",
"techage_filling_ta4.png^techage_frame_ta4.png",
"techage_filling_ta4.png^techage_appl_hole_electric.png^techage_frame_ta4.png",
"techage_filling_ta4.png^techage_appl_open.png^techage_frame_ta4.png",
"techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_generator.png",
"techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_generator.png^[transformFX]",
},
2022-01-04 21:43:30 +03:00
2021-08-01 12:00:22 +03:00
after_place_node = function(pos)
M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
Cable:after_place_node(pos)
end,
after_dig_node = function(pos, oldnode)
Cable:after_dig_node(pos)
techage.del_mem(pos)
end,
2020-05-31 23:31:18 +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(),
})
minetest.register_node("techage:ta4_generator_on", {
description = S("TA4 Generator"),
tiles = {
-- up, down, right, left, back, front
"techage_filling_ta4.png^techage_frame_ta4_top.png",
"techage_filling_ta4.png^techage_frame_ta4.png",
"techage_filling_ta4.png^techage_appl_hole_electric.png^techage_frame_ta4.png",
"techage_filling_ta4.png^techage_appl_open.png^techage_frame_ta4.png",
{
2023-05-09 19:41:56 +03:00
name = "techage_filling4_ta4.png^techage_appl_generator4.png^techage_frame4_ta4.png",
2020-05-31 23:31:18 +03:00
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
length = 0.3,
},
},
{
2023-05-09 19:41:56 +03:00
name = "techage_filling4_ta4.png^techage_appl_generator4.png^[transformFX]^techage_frame4_ta4.png",
2020-05-31 23:31:18 +03:00
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
length = 0.3,
},
},
},
2022-01-04 21:43:30 +03:00
2020-05-31 23:31:18 +03:00
paramtype2 = "facedir",
2021-08-01 12:00:22 +03:00
drop = "",
2020-05-31 23:31:18 +03:00
groups = {not_in_creative_inventory=1},
diggable = false,
on_rotate = screwdriver.disallow,
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
})
2021-08-01 12:00:22 +03:00
-- The generator is a dummy, it only has to network connection to check the netID
power.register_nodes({"techage:ta4_generator", "techage:ta4_generator_on"}, Cable, "con", {"R"})
2020-05-31 23:31:18 +03:00
-- controlled by the turbine
techage.register_node({"techage:ta4_generator", "techage:ta4_generator_on"}, {
on_transfer = function(pos, in_dir, topic, payload)
2021-08-01 12:00:22 +03:00
if topic == "netID" then
local outdir = M(pos):get_int("outdir")
return networks.determine_netID(pos, Cable, outdir)
elseif topic == "start" then
swap_node(pos, "techage:ta4_generator_on")
elseif topic == "stop" then
swap_node(pos, "techage:ta4_generator")
2020-05-31 23:31:18 +03:00
end
end,
on_recv_message = function(pos, src, topic, payload)
2021-08-01 12:00:22 +03:00
return "unsupported"
end,
on_node_load = function(pos)
-- remove legacy formspec
M(pos):set_string("formspec", "")
2020-05-31 23:31:18 +03:00
end,
})
minetest.register_craft({
output = "techage:ta4_generator",
recipe = {
{"", "dye:blue", ""},
{"", "techage:generator", ""},
{"", "techage:ta4_wlanchip", ""},
},
})