2020-05-31 23:31:18 +03:00
|
|
|
--[[
|
|
|
|
|
|
|
|
TechAge
|
|
|
|
=======
|
|
|
|
|
|
|
|
Copyright (C) 2019-2020 Joachim Stolberg
|
|
|
|
|
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
|
|
|
|
2020-05-31 23:31:18 +03:00
|
|
|
TA4 Water Pump
|
2022-01-04 21:43:30 +03:00
|
|
|
|
2020-05-31 23:31:18 +03:00
|
|
|
]]--
|
|
|
|
|
|
|
|
-- for lazy programmers
|
|
|
|
local M = minetest.get_meta
|
|
|
|
local S = techage.S
|
|
|
|
|
|
|
|
local Cable = techage.ElectricCable
|
|
|
|
local Pipe = techage.LiquidPipe
|
2021-08-01 12:00:22 +03:00
|
|
|
local power = networks.power
|
|
|
|
local liquid = networks.liquid
|
2020-05-31 23:31:18 +03:00
|
|
|
|
2021-08-01 12:00:22 +03:00
|
|
|
local CYCLE_TIME = 2
|
2020-05-31 23:31:18 +03:00
|
|
|
local STANDBY_TICKS = 3
|
|
|
|
local COUNTDOWN_TICKS = 3
|
|
|
|
local PWR_NEEDED = 4
|
|
|
|
|
|
|
|
local function formspec(self, pos, nvm)
|
|
|
|
return "size[3,2]"..
|
|
|
|
default.gui_bg..
|
|
|
|
default.gui_bg_img..
|
|
|
|
default.gui_slots..
|
|
|
|
"box[0,-0.1;2.8,0.5;#c6e8ff]"..
|
|
|
|
"label[0.5,-0.1;"..minetest.colorize( "#000000", S("Water Pump")).."]"..
|
|
|
|
"image_button[1,1;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
|
|
|
|
"tooltip[1,1;1,1;"..self:get_state_tooltip(nvm).."]"
|
|
|
|
end
|
|
|
|
|
|
|
|
local function can_start(pos, nvm, state)
|
|
|
|
local outdir = M(pos):get_int("waterdir")
|
|
|
|
local pos1 = vector.add(pos, tubelib2.Dir6dToVector[outdir or 0])
|
|
|
|
if not techage.is_ocean(pos1) then
|
|
|
|
return S("no usable water")
|
|
|
|
end
|
|
|
|
if not power.power_available(pos, Cable) then
|
|
|
|
return S("no power")
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
local function start_node(pos, nvm, state)
|
2021-08-01 12:00:22 +03:00
|
|
|
nvm.running = true
|
2020-05-31 23:31:18 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
local function stop_node(pos, nvm, state)
|
|
|
|
nvm.running = false
|
|
|
|
end
|
|
|
|
|
|
|
|
local State = techage.NodeStates:new({
|
|
|
|
node_name_passive = "techage:t4_waterpump",
|
|
|
|
infotext_name = S("TA4 Water Pump"),
|
|
|
|
cycle_time = CYCLE_TIME,
|
|
|
|
standby_ticks = STANDBY_TICKS,
|
|
|
|
formspec_func = formspec,
|
|
|
|
can_start = can_start,
|
|
|
|
start_node = start_node,
|
|
|
|
stop_node = stop_node,
|
|
|
|
})
|
|
|
|
|
2021-08-01 12:00:22 +03:00
|
|
|
local function has_power(pos, nvm)
|
|
|
|
local outdir = networks.Flip[M(pos):get_int("waterdir")]
|
|
|
|
local taken = power.consume_power(pos, Cable, outdir, PWR_NEEDED)
|
|
|
|
if techage.is_running(nvm) then
|
|
|
|
if taken < PWR_NEEDED then
|
|
|
|
State:nopower(pos, nvm)
|
|
|
|
else
|
|
|
|
return true -- keep running
|
|
|
|
end
|
|
|
|
elseif taken == PWR_NEEDED then
|
|
|
|
State:start(pos, nvm)
|
|
|
|
end
|
2020-05-31 23:31:18 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
local function pumping(pos, nvm)
|
2021-08-01 12:00:22 +03:00
|
|
|
if has_power(pos, nvm) then
|
|
|
|
nvm.ticks = (nvm.ticks or 0) + 1
|
|
|
|
if nvm.ticks % 4 == 0 then
|
|
|
|
local leftover = liquid.put(pos, Pipe, 6, "techage:water", 1)
|
|
|
|
if leftover and leftover > 0 then
|
|
|
|
State:blocked(pos, nvm)
|
|
|
|
return
|
|
|
|
end
|
2020-05-31 23:31:18 +03:00
|
|
|
end
|
2021-08-01 12:00:22 +03:00
|
|
|
State:keep_running(pos, nvm, 1)
|
2020-05-31 23:31:18 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- converts power into hydrogen
|
|
|
|
local function node_timer(pos, elapsed)
|
|
|
|
local nvm = techage.get_nvm(pos)
|
|
|
|
pumping(pos, nvm)
|
|
|
|
return State:is_active(nvm)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function on_receive_fields(pos, formname, fields, player)
|
|
|
|
if minetest.is_protected(pos, player:get_player_name()) then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local nvm = techage.get_nvm(pos)
|
|
|
|
State:state_button_event(pos, nvm, fields)
|
|
|
|
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
|
|
|
end
|
|
|
|
|
|
|
|
local function after_place_node(pos)
|
|
|
|
local nvm = techage.get_nvm(pos)
|
|
|
|
nvm.running = false
|
|
|
|
local number = techage.add_node(pos, "techage:t4_waterpump")
|
|
|
|
State:node_init(pos, nvm, number)
|
|
|
|
M(pos):set_int("waterdir", networks.side_to_outdir(pos, "R"))
|
|
|
|
Pipe:after_place_node(pos)
|
|
|
|
Cable:after_place_node(pos)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function after_dig_node(pos, oldnode, oldmetadata, digger)
|
|
|
|
Pipe:after_dig_node(pos)
|
|
|
|
Cable:after_dig_node(pos)
|
|
|
|
techage.del_mem(pos)
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_node("techage:t4_waterpump", {
|
|
|
|
description = S("TA4 Water Pump"),
|
|
|
|
tiles = {
|
|
|
|
-- up, down, right, left, back, front
|
|
|
|
"techage_filling_ta4.png^techage_frame_waterpump_top.png^techage_appl_hole_pipe.png",
|
|
|
|
"techage_filling_ta4.png^techage_frame_ta4.png",
|
|
|
|
"techage_filling_ta4.png^techage_frame_waterpump.png",
|
|
|
|
"techage_filling_ta4.png^techage_frame_waterpump.png^techage_appl_hole_electric.png",
|
|
|
|
"techage_filling_ta4.png^techage_frame_waterpump.png",
|
|
|
|
"techage_filling_ta4.png^techage_frame_waterpump.png",
|
|
|
|
},
|
|
|
|
|
|
|
|
after_place_node = after_place_node,
|
|
|
|
after_dig_node = after_dig_node,
|
|
|
|
on_receive_fields = on_receive_fields,
|
|
|
|
on_timer = node_timer,
|
2022-01-04 21:43:30 +03:00
|
|
|
|
2020-05-31 23:31:18 +03:00
|
|
|
paramtype2 = "facedir",
|
2021-05-14 19:50:16 +03:00
|
|
|
groups = {cracky=2, crumbly=2, choppy=2, not_in_creative_inventory = 1},
|
2020-05-31 23:31:18 +03:00
|
|
|
on_rotate = screwdriver.disallow,
|
|
|
|
is_ground_content = false,
|
|
|
|
})
|
|
|
|
|
2021-08-01 12:00:22 +03:00
|
|
|
power.register_nodes({"techage:t4_waterpump"}, Cable, "con", {"L"})
|
|
|
|
liquid.register_nodes({"techage:t4_waterpump"}, Pipe, "pump", {"U"}, {})
|
2020-05-31 23:31:18 +03:00
|
|
|
|
|
|
|
techage.register_node({"techage:t4_waterpump"}, {
|
|
|
|
on_recv_message = function(pos, src, topic, payload)
|
|
|
|
return State:on_receive_message(pos, topic, payload)
|
|
|
|
end,
|
2022-01-04 21:43:30 +03:00
|
|
|
})
|