2019-10-07 01:09:39 +03:00
|
|
|
--[[
|
|
|
|
|
|
|
|
TechAge
|
|
|
|
=======
|
|
|
|
|
|
|
|
Copyright (C) 2019 Joachim Stolberg
|
|
|
|
|
|
|
|
GPL v3
|
|
|
|
See LICENSE.txt for more information
|
|
|
|
|
2020-01-26 01:15:44 +03:00
|
|
|
TA4 Electrolyzer v2
|
2019-10-07 01:09:39 +03:00
|
|
|
|
|
|
|
]]--
|
|
|
|
|
|
|
|
-- for lazy programmers
|
|
|
|
local M = minetest.get_meta
|
|
|
|
local S = techage.S
|
|
|
|
|
|
|
|
local Power = techage.ElectricCable
|
|
|
|
local power = techage.power
|
2020-01-26 01:15:44 +03:00
|
|
|
local Pipe = techage.LiquidPipe
|
|
|
|
local liquid = techage.liquid
|
2019-10-07 01:09:39 +03:00
|
|
|
|
|
|
|
local CYCLE_TIME = 2
|
|
|
|
local STANDBY_TICKS = 5
|
|
|
|
local PWR_NEEDED = 40
|
|
|
|
local PWR_UNITS_PER_HYDROGEN_ITEM = 320
|
2020-01-26 01:15:44 +03:00
|
|
|
local CAPACITY = 400
|
2019-10-07 01:09:39 +03:00
|
|
|
|
2020-01-31 21:55:10 +03:00
|
|
|
local function formspec(self, pos, nvm)
|
|
|
|
local update = ((nvm.countdown or 0) > 0 and nvm.countdown) or S("Update")
|
2019-10-07 01:09:39 +03:00
|
|
|
return "size[8,6.6]"..
|
|
|
|
default.gui_bg..
|
|
|
|
default.gui_bg_img..
|
|
|
|
default.gui_slots..
|
2020-01-31 21:55:10 +03:00
|
|
|
"image[0.0,0;1,2;"..power.formspec_power_bar(PWR_NEEDED, nvm.consumed).."]"..
|
2020-01-26 01:15:44 +03:00
|
|
|
"label[0.2,1.9;"..S("\\[ku\\]").."]"..
|
|
|
|
"image[2.5,0;1,1;techage_form_arrow_fg.png^[transformR270]"..
|
2020-01-31 21:55:10 +03:00
|
|
|
"image_button[3.5,1;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
|
|
|
|
"tooltip[3.5,1;1,1;"..self:get_state_tooltip(nvm).."]"..
|
2020-01-26 01:15:44 +03:00
|
|
|
"button[1.6,1;1.8,1;update;"..update.."]"..
|
2019-10-07 01:09:39 +03:00
|
|
|
"list[current_player;main;0,2.8;8,4;]" ..
|
2020-01-31 21:55:10 +03:00
|
|
|
liquid.formspec_liquid(5, 0, nvm)..
|
2019-10-07 01:09:39 +03:00
|
|
|
default.get_hotbar_bg(0, 2.8)
|
|
|
|
end
|
|
|
|
|
2020-01-31 21:55:10 +03:00
|
|
|
local function start_node(pos, nvm, state)
|
|
|
|
nvm.running = true
|
|
|
|
nvm.consumed = 0
|
|
|
|
power.secondary_start(pos, nvm, PWR_NEEDED, PWR_NEEDED)
|
2019-10-07 01:09:39 +03:00
|
|
|
end
|
|
|
|
|
2020-01-31 21:55:10 +03:00
|
|
|
local function stop_node(pos, nvm, state)
|
|
|
|
nvm.running = false
|
|
|
|
nvm.consumed = 0
|
|
|
|
power.secondary_stop(pos, nvm)
|
2019-10-07 01:09:39 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
local State = techage.NodeStates:new({
|
2020-01-26 01:15:44 +03:00
|
|
|
node_name_passive = "techage:ta4_electrolyzer2",
|
|
|
|
node_name_active = "techage:ta4_electrolyzer2_on",
|
2019-10-07 01:09:39 +03:00
|
|
|
cycle_time = CYCLE_TIME,
|
|
|
|
standby_ticks = STANDBY_TICKS,
|
|
|
|
formspec_func = formspec,
|
|
|
|
infotext_name = "TA4 Electrolyzer",
|
|
|
|
start_node = start_node,
|
|
|
|
stop_node = stop_node,
|
|
|
|
})
|
|
|
|
|
|
|
|
-- converts power into hydrogen
|
|
|
|
local function node_timer(pos, elapsed)
|
2020-01-31 21:55:10 +03:00
|
|
|
local nvm = techage.get_nvm(pos)
|
|
|
|
nvm.num_pwr_units = nvm.num_pwr_units or 0
|
|
|
|
nvm.countdown = nvm.countdown or 0
|
|
|
|
nvm.liquid = nvm.liquid or {}
|
|
|
|
nvm.liquid.amount = nvm.liquid.amount or 0
|
|
|
|
print("electrolyzer", nvm.running, nvm.consumed, nvm.num_pwr_units, nvm.liquid.amount)
|
|
|
|
if nvm.running then
|
|
|
|
if techage.needs_power(nvm) then
|
|
|
|
nvm.consumed = -power.secondary_alive(pos, nvm, 0, 1)
|
|
|
|
--print("nvm.consumed", nvm.consumed)
|
|
|
|
if nvm.consumed > 0 then
|
|
|
|
if nvm.liquid.amount < CAPACITY then
|
|
|
|
nvm.num_pwr_units = nvm.num_pwr_units + nvm.consumed
|
|
|
|
if nvm.num_pwr_units >= PWR_UNITS_PER_HYDROGEN_ITEM then
|
|
|
|
nvm.liquid.amount = nvm.liquid.amount + 1
|
|
|
|
nvm.liquid.name = "techage:hydrogen"
|
|
|
|
nvm.num_pwr_units = nvm.num_pwr_units - PWR_UNITS_PER_HYDROGEN_ITEM
|
|
|
|
State:keep_running(pos, nvm, 1, 0) -- count items
|
2019-10-07 01:09:39 +03:00
|
|
|
end
|
2020-01-26 01:15:44 +03:00
|
|
|
else
|
2020-01-31 21:55:10 +03:00
|
|
|
State:blocked(pos, nvm)
|
|
|
|
power.secondary_stop(pos, nvm)
|
2019-10-07 01:09:39 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
2020-01-31 21:55:10 +03:00
|
|
|
nvm.consumed = -power.secondary_alive(pos, nvm, 1, 1)
|
|
|
|
if nvm.liquid.amount < CAPACITY then
|
|
|
|
State:start(pos, nvm)
|
|
|
|
power.secondary_start(pos, nvm, PWR_NEEDED, PWR_NEEDED)
|
2019-10-07 01:09:39 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-01-31 21:55:10 +03:00
|
|
|
if nvm.countdown > 0 then
|
|
|
|
nvm.countdown = nvm.countdown - 1
|
|
|
|
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
2020-01-26 01:15:44 +03:00
|
|
|
end
|
2020-01-31 21:55:10 +03:00
|
|
|
return nvm.running or nvm.countdown > 0
|
2019-10-07 01:09:39 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
local function on_receive_fields(pos, formname, fields, player)
|
|
|
|
if minetest.is_protected(pos, player:get_player_name()) then
|
|
|
|
return
|
|
|
|
end
|
2020-01-31 21:55:10 +03:00
|
|
|
local nvm = techage.get_nvm(pos)
|
|
|
|
State:state_button_event(pos, nvm, fields)
|
2019-10-07 01:09:39 +03:00
|
|
|
|
2020-01-31 21:55:10 +03:00
|
|
|
nvm.countdown = 10
|
|
|
|
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
2020-01-26 01:15:44 +03:00
|
|
|
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
2019-10-07 01:09:39 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
local function allow_metadata_inventory(pos, listname, index, stack, player)
|
|
|
|
if minetest.is_protected(pos, player:get_player_name()) then
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
if stack:get_name() == "techage:hydrogen" then
|
|
|
|
return stack:get_count()
|
|
|
|
end
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
|
|
|
|
local function on_rightclick(pos)
|
2020-01-31 21:55:10 +03:00
|
|
|
local nvm = techage.get_nvm(pos)
|
|
|
|
nvm.countdown = 10
|
|
|
|
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
2020-01-26 01:15:44 +03:00
|
|
|
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
2019-10-07 01:09:39 +03:00
|
|
|
end
|
|
|
|
|
2020-01-26 01:15:44 +03:00
|
|
|
minetest.register_node("techage:ta4_electrolyzer2", {
|
2019-10-07 01:09:39 +03:00
|
|
|
description = S("TA4 Electrolyzer"),
|
|
|
|
tiles = {
|
|
|
|
-- up, down, right, left, back, front
|
|
|
|
"techage_filling_ta4.png^techage_frame_ta4_top.png^techage_appl_arrow.png",
|
|
|
|
"techage_filling_ta4.png^techage_frame_ta4.png",
|
|
|
|
"techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_outp.png",
|
|
|
|
"techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_hole_electric.png",
|
|
|
|
"techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_electrolyzer.png^techage_appl_ctrl_unit.png^[transformFX",
|
|
|
|
"techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_electrolyzer.png^techage_appl_ctrl_unit.png",
|
|
|
|
},
|
|
|
|
|
|
|
|
on_construct = function(pos)
|
2020-01-31 21:55:10 +03:00
|
|
|
local nvm = techage.get_nvm(pos)
|
2020-01-26 01:15:44 +03:00
|
|
|
local number = techage.add_node(pos, "techage:ta4_electrolyzer2")
|
2020-01-31 21:55:10 +03:00
|
|
|
nvm.running = false
|
|
|
|
nvm.num_pwr_units = 0
|
|
|
|
State:node_init(pos, nvm, number)
|
2019-10-07 01:09:39 +03:00
|
|
|
local meta = M(pos)
|
2020-01-31 21:55:10 +03:00
|
|
|
meta:set_string("formspec", formspec(State, pos, nvm))
|
2019-10-07 01:09:39 +03:00
|
|
|
local inv = meta:get_inventory()
|
2020-01-26 01:15:44 +03:00
|
|
|
inv:set_size('src', 1)
|
|
|
|
inv:set_size('dst', 1)
|
2019-10-07 01:09:39 +03:00
|
|
|
end,
|
|
|
|
|
2020-01-26 01:15:44 +03:00
|
|
|
tubelib2_on_update2 = function(pos, outdir, tlib2, node)
|
|
|
|
liquid.update_network(pos, outdir)
|
|
|
|
end,
|
|
|
|
|
2019-10-07 01:09:39 +03:00
|
|
|
can_dig = function(pos, player)
|
|
|
|
local inv = M(pos):get_inventory()
|
|
|
|
return inv:is_empty("dst")
|
|
|
|
end,
|
|
|
|
|
2020-01-26 01:15:44 +03:00
|
|
|
liquid = {
|
|
|
|
capa = CAPACITY,
|
|
|
|
peek = liquid.srv_peek,
|
|
|
|
put = function(pos, indir, name, amount)
|
|
|
|
local leftover = liquid.srv_put(pos, indir, name, amount)
|
|
|
|
local inv = M(pos):get_inventory()
|
|
|
|
if not inv:is_empty("src") and inv:is_empty("dst") then
|
|
|
|
liquid.fill_container(pos, inv)
|
|
|
|
end
|
|
|
|
return leftover
|
|
|
|
end,
|
|
|
|
take = liquid.srv_take,
|
|
|
|
},
|
|
|
|
networks = {
|
2020-01-31 21:55:10 +03:00
|
|
|
pipe2 = {
|
2020-01-26 01:15:44 +03:00
|
|
|
sides = {R = 1}, -- Pipe connection sides
|
|
|
|
ntype = "tank",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2019-10-07 01:09:39 +03:00
|
|
|
allow_metadata_inventory_put = allow_metadata_inventory,
|
|
|
|
allow_metadata_inventory_take = allow_metadata_inventory,
|
|
|
|
on_receive_fields = on_receive_fields,
|
|
|
|
on_timer = node_timer,
|
|
|
|
on_rightclick = on_rightclick,
|
|
|
|
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
groups = {cracky=2, crumbly=2, choppy=2},
|
|
|
|
on_rotate = screwdriver.disallow,
|
|
|
|
is_ground_content = false,
|
|
|
|
})
|
|
|
|
|
2020-01-26 01:15:44 +03:00
|
|
|
minetest.register_node("techage:ta4_electrolyzer2_on", {
|
2019-10-07 01:09:39 +03:00
|
|
|
description = S("TA4 Electrolyzer"),
|
|
|
|
tiles = {
|
|
|
|
-- up, down, right, left, back, front
|
|
|
|
"techage_filling_ta4.png^techage_frame_ta4_top.png^techage_appl_arrow.png",
|
|
|
|
"techage_filling_ta4.png^techage_frame_ta4.png",
|
|
|
|
"techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_outp.png",
|
|
|
|
"techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_hole_electric.png",
|
|
|
|
{
|
|
|
|
image = "techage_filling4_ta4.png^techage_frame4_ta4.png^techage_appl_electrolyzer4.png^techage_appl_ctrl_unit4.png^[transformFX",
|
|
|
|
backface_culling = false,
|
|
|
|
animation = {
|
|
|
|
type = "vertical_frames",
|
|
|
|
aspect_w = 32,
|
|
|
|
aspect_h = 32,
|
|
|
|
length = 0.8,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
image = "techage_filling4_ta4.png^techage_frame4_ta4.png^techage_appl_electrolyzer4.png^techage_appl_ctrl_unit4.png",
|
|
|
|
backface_culling = false,
|
|
|
|
animation = {
|
|
|
|
type = "vertical_frames",
|
|
|
|
aspect_w = 32,
|
|
|
|
aspect_h = 32,
|
|
|
|
length = 0.8,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2020-01-26 01:15:44 +03:00
|
|
|
tubelib2_on_update2 = function(pos, outdir, tlib2, node)
|
|
|
|
liquid.update_network(pos, outdir)
|
|
|
|
end,
|
|
|
|
|
|
|
|
liquid = {
|
|
|
|
capa = CAPACITY,
|
|
|
|
peek = liquid.srv_peek,
|
|
|
|
put = function(pos, indir, name, amount)
|
|
|
|
local leftover = liquid.srv_put(pos, indir, name, amount)
|
|
|
|
local inv = M(pos):get_inventory()
|
|
|
|
if not inv:is_empty("src") and inv:is_empty("dst") then
|
|
|
|
liquid.fill_container(pos, inv)
|
|
|
|
end
|
|
|
|
return leftover
|
|
|
|
end,
|
|
|
|
take = liquid.srv_take,
|
|
|
|
},
|
|
|
|
networks = {
|
2020-01-31 21:55:10 +03:00
|
|
|
pipe2 = {
|
2020-01-26 01:15:44 +03:00
|
|
|
sides = {R = 1}, -- Pipe connection sides
|
|
|
|
ntype = "tank",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2019-10-07 01:09:39 +03:00
|
|
|
allow_metadata_inventory_put = allow_metadata_inventory,
|
|
|
|
allow_metadata_inventory_take = allow_metadata_inventory,
|
|
|
|
on_receive_fields = on_receive_fields,
|
|
|
|
on_timer = node_timer,
|
|
|
|
on_rightclick = on_rightclick,
|
|
|
|
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
groups = {not_in_creative_inventory=1},
|
|
|
|
on_rotate = screwdriver.disallow,
|
|
|
|
is_ground_content = false,
|
|
|
|
diggable = false,
|
|
|
|
paramtype = "light",
|
|
|
|
light_source = 6,
|
|
|
|
})
|
|
|
|
|
2020-01-26 01:15:44 +03:00
|
|
|
-- Register for power
|
|
|
|
techage.power.register_node({"techage:ta4_electrolyzer2", "techage:ta4_electrolyzer2_on"}, {
|
2019-10-07 01:09:39 +03:00
|
|
|
conn_sides = {"L"},
|
|
|
|
power_network = Power,
|
|
|
|
after_place_node = function(pos)
|
|
|
|
local node = minetest.get_node(pos)
|
|
|
|
local indir = techage.side_to_indir("R", node.param2)
|
|
|
|
M(pos):set_int("in_dir", indir)
|
2020-01-26 01:15:44 +03:00
|
|
|
Pipe:after_place_node(pos)
|
2019-10-07 01:09:39 +03:00
|
|
|
end,
|
2020-01-26 01:15:44 +03:00
|
|
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
|
|
|
Pipe:after_dig_node(pos)
|
|
|
|
end,
|
2019-10-07 01:09:39 +03:00
|
|
|
})
|
|
|
|
|
2020-01-26 01:15:44 +03:00
|
|
|
-- Register for tubes
|
|
|
|
techage.register_node({"techage:ta4_electrolyzer2", "techage:ta4_electrolyzer2_on"}, liquid.tubing)
|
|
|
|
|
|
|
|
-- Register for pipes
|
|
|
|
Pipe:add_secondary_node_names({"techage:ta3_tank", "techage:ta4_tank", "techage:oiltank"})
|
2019-10-07 01:09:39 +03:00
|
|
|
|
|
|
|
minetest.register_craft({
|
2020-01-26 01:15:44 +03:00
|
|
|
output = "techage:ta4_electrolyzer2",
|
2019-10-07 01:09:39 +03:00
|
|
|
recipe = {
|
|
|
|
{'default:steel_ingot', 'dye:blue', 'default:steel_ingot'},
|
|
|
|
{'techage:electric_cableS', 'default:glass', 'techage:tubeS'},
|
|
|
|
{'default:steel_ingot', "techage:ta4_wlanchip", 'default:steel_ingot'},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|