techage/liquids/waterinlet.lua

109 lines
2.6 KiB
Lua
Raw Permalink Normal View History

--[[
TechAge
=======
Copyright (C) 2019-2021 Joachim Stolberg
AGPL v3
See LICENSE.txt for more information
2022-01-03 23:40:31 +03:00
TA4 Water Inlet (replacement for the water pump)
2022-01-03 23:40:31 +03:00
]]--
-- for lazy programmers
local M = minetest.get_meta
local S = techage.S
local Pipe = techage.LiquidPipe
2021-07-18 17:25:03 +03:00
local liquid = networks.liquid
local function is_ocean(pos)
2022-01-03 23:40:31 +03:00
if pos.y > 1 then
M(pos):set_string("infotext", S("Error: Not on sea level!"))
2022-01-03 23:40:31 +03:00
return false
end
local node = techage.get_node_lvm({x = pos.x, y = pos.y - 1, z = pos.z})
2022-01-03 23:40:31 +03:00
if node.name ~= "default:water_source" then
M(pos):set_string("infotext", S("Error: No water available!"))
2022-01-03 23:40:31 +03:00
return false
end
2022-01-03 23:40:31 +03:00
if node.param2 == 1 then
M(pos):set_string("infotext", S("Error: No natural water!"))
return false
end
2021-07-18 17:25:03 +03:00
M(pos):set_string("infotext", S("Operational"))
return true
end
2021-07-18 17:25:03 +03:00
local function peek_liquid(pos)
local mem = techage.get_mem(pos)
if is_ocean(pos) then
2021-07-18 17:25:03 +03:00
mem.liquid_name = "techage:water"
mem.liquid_amount = 1
else
2021-07-18 17:25:03 +03:00
mem.liquid_name = "techage:water"
mem.liquid_amount = 0
end
2021-07-18 17:25:03 +03:00
return mem.liquid_name
end
local function take_liquid(pos, indir, name, amount)
2021-07-18 17:25:03 +03:00
local mem = techage.get_mem(pos)
if not mem.liquid_name then
peek_liquid(pos)
end
return mem.liquid_amount or 0, mem.liquid_name
end
2022-01-03 23:40:31 +03:00
2021-07-18 17:25:03 +03:00
local function untake_liquid(pos, indir, name, amount)
return 0
end
minetest.register_node("techage:ta4_waterinlet", {
description = S("TA4 Water Inlet"),
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_filling_ta4.png^techage_frame_waterpump.png",
"techage_filling_ta4.png^techage_frame_waterpump.png",
},
after_place_node = function(pos, placer)
local meta = M(pos)
Pipe:after_place_node(pos)
2021-07-18 17:25:03 +03:00
is_ocean(pos)
end,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
Pipe:after_dig_node(pos)
techage.remove_node(pos, oldnode, oldmetadata)
end,
paramtype2 = "facedir",
on_rotate = screwdriver.disallow,
groups = {cracky=2},
is_ground_content = false,
sounds = default.node_sound_metal_defaults(),
})
2021-07-18 17:25:03 +03:00
liquid.register_nodes({"techage:ta4_waterinlet"},
Pipe, "tank", {"U"}, {
capa = 1,
peek = peek_liquid,
take = take_liquid,
untake = untake_liquid,
}
)
minetest.register_craft({
output = "techage:ta4_waterinlet",
recipe = {
{"techage:ta4_carbon_fiber", "techage:ta3_pipeS", "techage:ta4_carbon_fiber"},
{"techage:iron_ingot", "techage:ta3_barrel_empty", "techage:iron_ingot"},
},
})