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
|
|
|
|
2020-05-31 23:31:18 +03:00
|
|
|
TA3/TA4 Tank, Oil Tank
|
|
|
|
|
|
|
|
]]--
|
|
|
|
|
|
|
|
local S2P = minetest.string_to_pos
|
|
|
|
local P2S = minetest.pos_to_string
|
|
|
|
local M = minetest.get_meta
|
2021-08-01 12:00:22 +03:00
|
|
|
local N = tubelib2.get_node_lvm
|
|
|
|
local LQD = function(pos) return (minetest.registered_nodes[N(pos).name] or {}).liquid end
|
2020-05-31 23:31:18 +03:00
|
|
|
local S = techage.S
|
|
|
|
local Pipe = techage.LiquidPipe
|
2021-08-01 12:00:22 +03:00
|
|
|
local liquid = networks.liquid
|
2020-05-31 23:31:18 +03:00
|
|
|
|
|
|
|
local CAPACITY = 1000
|
|
|
|
|
|
|
|
local function on_rightclick(pos, node, clicker)
|
|
|
|
local nvm = techage.get_nvm(pos)
|
|
|
|
techage.set_activeformspec(pos, clicker)
|
2021-08-01 12:00:22 +03:00
|
|
|
M(pos):set_string("formspec", techage.liquid.formspec(pos, nvm))
|
2020-05-31 23:31:18 +03:00
|
|
|
minetest.get_node_timer(pos):start(2)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function node_timer(pos, elapsed)
|
|
|
|
if techage.is_activeformspec(pos) then
|
|
|
|
local nvm = techage.get_nvm(pos)
|
2021-08-01 12:00:22 +03:00
|
|
|
M(pos):set_string("formspec", techage.liquid.formspec(pos, nvm))
|
2020-05-31 23:31:18 +03:00
|
|
|
return true
|
2022-01-04 21:43:30 +03:00
|
|
|
end
|
2020-05-31 23:31:18 +03:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
local function can_dig(pos, player)
|
|
|
|
if minetest.is_protected(pos, player:get_player_name()) then
|
|
|
|
return false
|
|
|
|
end
|
2021-08-01 12:00:22 +03:00
|
|
|
return techage.liquid.is_empty(pos)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function peek_liquid(pos, indir)
|
|
|
|
local nvm = techage.get_nvm(pos)
|
|
|
|
return liquid.srv_peek(nvm)
|
2020-05-31 23:31:18 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
local function take_liquid(pos, indir, name, amount)
|
2021-08-01 12:00:22 +03:00
|
|
|
local nvm = techage.get_nvm(pos)
|
2021-10-30 17:52:44 +03:00
|
|
|
if (M(pos):get_int("keep_assignment") or 0) == 1 then
|
|
|
|
amount = math.max(math.min(amount, ((nvm.liquid or {}).amount or 0) - 1), 0)
|
|
|
|
end
|
2021-08-01 12:00:22 +03:00
|
|
|
amount, name = liquid.srv_take(nvm, name, amount)
|
2020-05-31 23:31:18 +03:00
|
|
|
if techage.is_activeformspec(pos) then
|
2021-08-01 12:00:22 +03:00
|
|
|
M(pos):set_string("formspec", techage.liquid.formspec(pos, nvm))
|
2020-05-31 23:31:18 +03:00
|
|
|
end
|
|
|
|
return amount, name
|
|
|
|
end
|
2022-01-04 21:43:30 +03:00
|
|
|
|
2020-05-31 23:31:18 +03:00
|
|
|
local function put_liquid(pos, indir, name, amount)
|
|
|
|
-- check if it is not powder
|
|
|
|
local ndef = minetest.registered_craftitems[name] or {}
|
|
|
|
if not ndef.groups or ndef.groups.powder ~= 1 then
|
2021-08-01 12:00:22 +03:00
|
|
|
local nvm = techage.get_nvm(pos)
|
|
|
|
local leftover = liquid.srv_put(nvm, name, amount, LQD(pos).capa)
|
2020-05-31 23:31:18 +03:00
|
|
|
if techage.is_activeformspec(pos) then
|
2021-08-01 12:00:22 +03:00
|
|
|
M(pos):set_string("formspec", techage.liquid.formspec(pos, nvm))
|
2020-05-31 23:31:18 +03:00
|
|
|
end
|
|
|
|
return leftover
|
|
|
|
end
|
|
|
|
return amount
|
|
|
|
end
|
|
|
|
|
2020-09-13 14:24:06 +03:00
|
|
|
local function untake_liquid(pos, indir, name, amount)
|
2021-08-01 12:00:22 +03:00
|
|
|
local nvm = techage.get_nvm(pos)
|
|
|
|
local leftover = liquid.srv_put(nvm, name, amount, LQD(pos).capa)
|
2020-09-13 14:24:06 +03:00
|
|
|
if techage.is_activeformspec(pos) then
|
2021-08-01 12:00:22 +03:00
|
|
|
M(pos):set_string("formspec", techage.liquid.formspec(pos, nvm))
|
2020-09-13 14:24:06 +03:00
|
|
|
end
|
|
|
|
return leftover
|
|
|
|
end
|
|
|
|
|
2020-05-31 23:31:18 +03:00
|
|
|
minetest.register_node("techage:ta3_tank", {
|
|
|
|
description = S("TA3 Tank"),
|
|
|
|
tiles = {
|
|
|
|
-- up, down, right, left, back, front
|
|
|
|
"techage_filling_ta3.png^techage_frame_ta3_top.png",
|
2022-01-28 20:22:52 +03:00
|
|
|
"techage_filling_ta3.png^techage_frame_ta3_bottom.png",
|
2020-05-31 23:31:18 +03:00
|
|
|
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_tank.png",
|
|
|
|
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_tank.png",
|
|
|
|
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_tank.png",
|
|
|
|
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_tank.png",
|
|
|
|
},
|
|
|
|
after_place_node = function(pos, placer)
|
|
|
|
local meta = M(pos)
|
|
|
|
local nvm = techage.get_nvm(pos)
|
|
|
|
nvm.liquid = {}
|
|
|
|
local number = techage.add_node(pos, "techage:ta3_tank")
|
|
|
|
meta:set_string("node_number", number)
|
|
|
|
meta:set_string("owner", placer:get_player_name())
|
2021-08-01 12:00:22 +03:00
|
|
|
meta:set_string("formspec", techage.liquid.formspec(pos, nvm))
|
2020-05-31 23:31:18 +03:00
|
|
|
meta:set_string("infotext", S("TA3 Tank").." "..number)
|
|
|
|
Pipe:after_place_node(pos)
|
|
|
|
end,
|
|
|
|
on_timer = node_timer,
|
2021-08-01 12:00:22 +03:00
|
|
|
on_punch = techage.liquid.on_punch,
|
2020-05-31 23:31:18 +03:00
|
|
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
|
|
|
Pipe:after_dig_node(pos)
|
2020-06-19 00:23:53 +03:00
|
|
|
techage.remove_node(pos, oldnode, oldmetadata)
|
2020-05-31 23:31:18 +03:00
|
|
|
end,
|
|
|
|
on_rightclick = on_rightclick,
|
|
|
|
can_dig = can_dig,
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
on_rotate = screwdriver.disallow,
|
|
|
|
groups = {cracky=2},
|
|
|
|
is_ground_content = false,
|
|
|
|
sounds = default.node_sound_metal_defaults(),
|
|
|
|
})
|
|
|
|
|
2021-08-01 12:00:22 +03:00
|
|
|
liquid.register_nodes({"techage:ta3_tank"},
|
|
|
|
Pipe, "tank", nil, {
|
|
|
|
capa = CAPACITY,
|
|
|
|
peek = peek_liquid,
|
|
|
|
put = put_liquid,
|
|
|
|
take = take_liquid,
|
|
|
|
untake = untake_liquid,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2020-05-31 23:31:18 +03:00
|
|
|
minetest.register_node("techage:oiltank", {
|
|
|
|
description = S("Oil Tank"),
|
|
|
|
tiles = {
|
|
|
|
-- up, down, right, left, back, front
|
|
|
|
"techage_filling_metal.png^techage_framexl_ta3_top.png",
|
|
|
|
"techage_filling_metal.png^techage_framexl_ta3_top.png",
|
|
|
|
"techage_filling_metal.png^techage_framexl_ta3.png^techage_appl_explosive.png",
|
|
|
|
},
|
|
|
|
drawtype = "nodebox",
|
|
|
|
paramtype = "light",
|
|
|
|
node_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = {-6/8, -4/8, -6/8, 6/8, 6/8, 6/8},
|
|
|
|
},
|
|
|
|
selection_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = {-6/8, -4/8, -6/8, 6/8, 6/8, 6/8},
|
|
|
|
},
|
|
|
|
collision_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = {-6/8, -4/8, -6/8, 6/8, 6/8, 6/8},
|
|
|
|
},
|
2020-10-25 23:32:47 +03:00
|
|
|
wield_scale = {x = 0.8, y = 0.8, z = 0.8},
|
2020-05-31 23:31:18 +03:00
|
|
|
after_place_node = function(pos, placer)
|
|
|
|
local meta = M(pos)
|
|
|
|
local nvm = techage.get_nvm(pos)
|
|
|
|
nvm.liquid = {}
|
|
|
|
local number = techage.add_node(pos, "techage:oiltank")
|
|
|
|
meta:set_string("node_number", number)
|
|
|
|
meta:set_string("owner", placer:get_player_name())
|
2021-08-01 12:00:22 +03:00
|
|
|
meta:set_string("formspec", techage.liquid.formspec(pos, nvm))
|
2020-05-31 23:31:18 +03:00
|
|
|
meta:set_string("infotext", S("Oil Tank").." "..number)
|
|
|
|
Pipe:after_place_node(pos)
|
|
|
|
end,
|
|
|
|
on_timer = node_timer,
|
2021-08-01 12:00:22 +03:00
|
|
|
on_punch = techage.liquid.on_punch,
|
2020-05-31 23:31:18 +03:00
|
|
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
|
|
|
Pipe:after_dig_node(pos)
|
2020-06-19 00:23:53 +03:00
|
|
|
techage.remove_node(pos, oldnode, oldmetadata)
|
2020-05-31 23:31:18 +03:00
|
|
|
end,
|
|
|
|
on_rightclick = on_rightclick,
|
|
|
|
can_dig = can_dig,
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
on_rotate = screwdriver.disallow,
|
|
|
|
groups = {cracky=2},
|
|
|
|
is_ground_content = false,
|
|
|
|
sounds = default.node_sound_metal_defaults(),
|
|
|
|
})
|
|
|
|
|
2021-08-01 12:00:22 +03:00
|
|
|
liquid.register_nodes({"techage:oiltank"},
|
|
|
|
Pipe, "tank", nil, {
|
|
|
|
capa = CAPACITY * 4,
|
|
|
|
peek = peek_liquid,
|
|
|
|
put = put_liquid,
|
|
|
|
take = take_liquid,
|
|
|
|
untake = untake_liquid,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2020-05-31 23:31:18 +03:00
|
|
|
minetest.register_node("techage:ta4_tank", {
|
|
|
|
description = S("TA4 Tank"),
|
|
|
|
tiles = {
|
|
|
|
-- up, down, right, left, back, front
|
|
|
|
"techage_filling_ta4.png^techage_frame_ta4_top.png",
|
2022-01-28 20:22:52 +03:00
|
|
|
"techage_filling_ta4.png^techage_frame_ta4_bottom.png",
|
2020-05-31 23:31:18 +03:00
|
|
|
"techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_tank.png",
|
|
|
|
"techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_tank.png",
|
|
|
|
"techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_tank.png",
|
|
|
|
"techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_tank.png",
|
|
|
|
},
|
|
|
|
|
|
|
|
after_place_node = function(pos, placer)
|
|
|
|
local meta = M(pos)
|
|
|
|
local nvm = techage.get_nvm(pos)
|
|
|
|
nvm.liquid = {}
|
|
|
|
local number = techage.add_node(pos, "techage:ta4_tank")
|
|
|
|
meta:set_string("node_number", number)
|
|
|
|
meta:set_string("owner", placer:get_player_name())
|
2021-08-01 12:00:22 +03:00
|
|
|
meta:set_string("formspec", techage.liquid.formspec(pos, nvm))
|
2020-05-31 23:31:18 +03:00
|
|
|
meta:set_string("infotext", S("TA4 Tank").." "..number)
|
|
|
|
Pipe:after_place_node(pos)
|
|
|
|
end,
|
2020-12-11 20:07:29 +03:00
|
|
|
on_receive_fields = function(pos, formname, fields, player)
|
|
|
|
if minetest.is_protected(pos, player:get_player_name()) then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if fields.public then
|
|
|
|
M(pos):set_int("public", fields.public == "true" and 1 or 0)
|
|
|
|
end
|
2021-10-30 17:52:44 +03:00
|
|
|
if fields.keep_assignment then
|
|
|
|
M(pos):set_int("keep_assignment", fields.keep_assignment == "true" and 1 or 0)
|
|
|
|
end
|
2020-12-11 20:07:29 +03:00
|
|
|
end,
|
2020-05-31 23:31:18 +03:00
|
|
|
on_timer = node_timer,
|
2021-08-01 12:00:22 +03:00
|
|
|
on_punch = techage.liquid.on_punch,
|
2020-05-31 23:31:18 +03:00
|
|
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
|
|
|
Pipe:after_dig_node(pos)
|
2020-06-19 00:23:53 +03:00
|
|
|
techage.remove_node(pos, oldnode, oldmetadata)
|
2020-05-31 23:31:18 +03:00
|
|
|
end,
|
|
|
|
on_rightclick = on_rightclick,
|
|
|
|
can_dig = can_dig,
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
on_rotate = screwdriver.disallow,
|
|
|
|
groups = {cracky=2},
|
|
|
|
is_ground_content = false,
|
|
|
|
sounds = default.node_sound_metal_defaults(),
|
|
|
|
})
|
|
|
|
|
2021-08-01 12:00:22 +03:00
|
|
|
liquid.register_nodes({"techage:ta4_tank"},
|
|
|
|
Pipe, "tank", nil, {
|
|
|
|
capa = CAPACITY * 2,
|
|
|
|
peek = peek_liquid,
|
|
|
|
put = put_liquid,
|
|
|
|
take = take_liquid,
|
|
|
|
untake = untake_liquid,
|
|
|
|
}
|
|
|
|
)
|
2020-05-31 23:31:18 +03:00
|
|
|
|
2022-01-04 21:43:30 +03:00
|
|
|
techage.register_node({"techage:ta3_tank", "techage:ta4_tank", "techage:oiltank"}, techage.liquid.recv_message)
|
2020-05-31 23:31:18 +03:00
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "techage:ta3_tank 2",
|
|
|
|
recipe = {
|
|
|
|
{"techage:iron_ingot", "techage:ta3_barrel_empty", "group:wood"},
|
|
|
|
{"group:wood", "techage:ta3_barrel_empty", "techage:ta3_pipeS"},
|
|
|
|
{"group:wood", "techage:ta3_barrel_empty", "techage:iron_ingot"},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "techage:oiltank",
|
|
|
|
recipe = {
|
|
|
|
{"", "", ""},
|
|
|
|
{"techage:ta3_tank", "techage:iron_ingot", ""},
|
|
|
|
{"techage:iron_ingot", "techage:ta3_tank", ""},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "techage:ta4_tank",
|
|
|
|
recipe = {
|
|
|
|
{"default:tin_ingot", "dye:blue", "default:steel_ingot"},
|
|
|
|
{"", "techage:ta3_tank", ""},
|
|
|
|
{"", "", ""},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_lbm({
|
|
|
|
label = "Repair Tanks",
|
|
|
|
name = "techage:tank",
|
|
|
|
nodenames = {"techage:ta3_tank", "techage:oiltank", "techage:ta4_tank"},
|
|
|
|
run_at_every_load = true,
|
|
|
|
action = function(pos, node)
|
|
|
|
local mem = tubelib2.get_mem(pos)
|
|
|
|
if mem.liquid and mem.liquid.amount then
|
|
|
|
local nvm = techage.get_nvm(pos)
|
|
|
|
nvm.liquid = nvm.liquid or {}
|
2021-05-14 19:50:16 +03:00
|
|
|
nvm.liquid.amount = math.max(mem.liquid.amount, 0)
|
2020-05-31 23:31:18 +03:00
|
|
|
nvm.liquid.name = mem.liquid.name
|
|
|
|
--tubelib2.del_mem(pos)
|
|
|
|
end
|
|
|
|
end,
|
2022-01-03 13:59:31 +03:00
|
|
|
})
|