2019-09-08 22:54:34 +03:00
|
|
|
--[[
|
|
|
|
|
|
|
|
TechAge
|
|
|
|
=======
|
|
|
|
|
2021-06-19 16:06:08 +03:00
|
|
|
Copyright (C) 2019-2021 Joachim Stolberg
|
2019-09-08 22:54:34 +03:00
|
|
|
|
2020-10-19 20:09:17 +03:00
|
|
|
AGPL v3
|
2019-09-08 22:54:34 +03:00
|
|
|
See LICENSE.txt for more information
|
|
|
|
|
|
|
|
TA4 Pipe Inlet
|
|
|
|
|
|
|
|
]]--
|
|
|
|
|
|
|
|
-- for lazy programmers
|
|
|
|
local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end
|
|
|
|
local S2P = minetest.string_to_pos
|
2020-02-02 18:46:06 +03:00
|
|
|
local M = minetest.get_meta
|
2019-09-08 22:54:34 +03:00
|
|
|
local M = minetest.get_meta
|
|
|
|
local S = techage.S
|
|
|
|
|
2020-01-31 21:55:10 +03:00
|
|
|
local Pipe = techage.LiquidPipe
|
2019-09-08 22:54:34 +03:00
|
|
|
|
2020-02-06 22:51:30 +03:00
|
|
|
local function after_place_node(pos, placer, itemstack)
|
|
|
|
Pipe:after_place_node(pos)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function after_dig_node(pos, oldnode, oldmetadata, digger)
|
|
|
|
Pipe:after_dig_node(pos)
|
|
|
|
end
|
|
|
|
|
2019-09-08 22:54:34 +03:00
|
|
|
minetest.register_node("techage:ta4_pipe_inlet", {
|
|
|
|
description = S("TA4 Pipe Inlet"),
|
|
|
|
tiles = {
|
|
|
|
-- up, down, right, left, back, front
|
|
|
|
"basic_materials_concrete_block.png",
|
|
|
|
"basic_materials_concrete_block.png",
|
|
|
|
"basic_materials_concrete_block.png",
|
|
|
|
"basic_materials_concrete_block.png",
|
|
|
|
"basic_materials_concrete_block.png^techage_tes_inlet.png",
|
|
|
|
"basic_materials_concrete_block.png^techage_tes_inlet.png",
|
|
|
|
},
|
|
|
|
|
2020-02-06 22:51:30 +03:00
|
|
|
after_place_node = after_place_node,
|
|
|
|
after_dig_node = after_dig_node,
|
|
|
|
|
2021-06-19 16:06:08 +03:00
|
|
|
networks = {
|
|
|
|
pipe2 = {},
|
|
|
|
},
|
2019-09-08 22:54:34 +03:00
|
|
|
paramtype2 = "facedir", -- important!
|
|
|
|
on_rotate = screwdriver.disallow, -- important!
|
|
|
|
groups = {crumbly = 2, cracky = 2, snappy = 2},
|
|
|
|
is_ground_content = false,
|
|
|
|
sounds = default.node_sound_metal_defaults(),
|
|
|
|
})
|
|
|
|
|
2020-02-06 22:51:30 +03:00
|
|
|
Pipe:add_secondary_node_names({"techage:ta4_pipe_inlet"})
|
2019-09-08 22:54:34 +03:00
|
|
|
|
2019-09-09 23:04:16 +03:00
|
|
|
local Numbers = {
|
|
|
|
shell = {
|
|
|
|
[2] = 96, -- 5x5x2 + 3x5x2 + 3x3x2 - 2
|
|
|
|
[3] = 216, -- 7x7x2 + 5x7x2 + 5x5x2 - 2
|
|
|
|
[4] = 384, -- 9x9x2 + 7x9x2 + 7x7x2 - 2
|
|
|
|
},
|
|
|
|
filling = {
|
|
|
|
[2] = 27, -- 3x3x3
|
|
|
|
[3] = 125, -- 5x5x5
|
|
|
|
[4] = 343, -- 7x7x7
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-02 01:20:41 +03:00
|
|
|
local function get_diameter(pos, in_dir)
|
2019-09-09 23:04:16 +03:00
|
|
|
local dir = tubelib2.Dir6dToVector[in_dir]
|
2021-02-02 01:20:41 +03:00
|
|
|
local pos2, node
|
|
|
|
|
|
|
|
pos2 = vector.add(pos, vector.multiply(dir, 4))
|
|
|
|
node = minetest.get_node(pos2)
|
|
|
|
if node.name == "techage:ta3_pipe_wall_entry" then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if node.name == "techage:ta4_pipe_inlet" then
|
|
|
|
return 5
|
|
|
|
end
|
|
|
|
|
|
|
|
pos2 = vector.add(pos, vector.multiply(dir, 6))
|
|
|
|
node = minetest.get_node(pos2)
|
|
|
|
if node.name == "techage:ta3_pipe_wall_entry" then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if node.name == "techage:ta4_pipe_inlet" then
|
|
|
|
return 7
|
|
|
|
end
|
|
|
|
|
|
|
|
pos2 = vector.add(pos, vector.multiply(dir, 8))
|
|
|
|
node = minetest.get_node(pos2)
|
|
|
|
if node.name == "techage:ta3_pipe_wall_entry" then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if node.name == "techage:ta4_pipe_inlet" then
|
|
|
|
return 9
|
|
|
|
end
|
|
|
|
|
|
|
|
pos2 = vector.add(pos, vector.multiply(dir, 10))
|
2019-09-09 23:04:16 +03:00
|
|
|
local poses = minetest.find_nodes_in_area(pos, pos2, {"techage:ta4_pipe_inlet"})
|
2021-02-02 01:20:41 +03:00
|
|
|
if #poses > 1 then
|
|
|
|
return vector.distance(pos, poses[2]) + 1
|
2019-09-09 23:04:16 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function check_volume(pos, in_dir, owner)
|
2021-03-13 23:27:39 +03:00
|
|
|
local diameter = get_diameter(pos, in_dir)
|
|
|
|
if diameter then
|
|
|
|
local radius = (diameter - 1) / 2
|
2019-09-08 22:54:34 +03:00
|
|
|
local dir = tubelib2.Dir6dToVector[in_dir]
|
2019-09-09 23:04:16 +03:00
|
|
|
local cpos = vector.add(pos, vector.multiply(dir, radius))
|
|
|
|
-- calculate size
|
|
|
|
local pos1 = {x = cpos.x - radius, y = cpos.y - radius, z = cpos.z - radius}
|
|
|
|
local pos2 = {x = cpos.x + radius, y = cpos.y + radius, z = cpos.z + radius}
|
|
|
|
local _, node_tbl = minetest.find_nodes_in_area(pos1, pos2,
|
2019-09-08 22:54:34 +03:00
|
|
|
{"default:gravel", "techage:ta4_pipe_inlet",
|
|
|
|
"basic_materials:concrete_block", "default:obsidian_glass",
|
|
|
|
"techage:glow_gravel"})
|
2019-09-09 23:04:16 +03:00
|
|
|
if node_tbl["default:obsidian_glass"] > 1 then
|
2021-06-19 16:06:08 +03:00
|
|
|
return S("one window maximum")
|
2019-09-09 23:04:16 +03:00
|
|
|
elseif node_tbl["default:obsidian_glass"] + node_tbl["basic_materials:concrete_block"] ~= Numbers.shell[radius] then
|
2021-06-19 16:06:08 +03:00
|
|
|
return S("wrong number of shell nodes")
|
2019-09-09 23:04:16 +03:00
|
|
|
elseif node_tbl["default:gravel"] + node_tbl["techage:glow_gravel"] ~= Numbers.filling[radius] then
|
2021-06-19 16:06:08 +03:00
|
|
|
return S("wrong number of gravel nodes")
|
2019-09-08 22:54:34 +03:00
|
|
|
end
|
2019-09-09 23:04:16 +03:00
|
|
|
else
|
2021-06-19 16:06:08 +03:00
|
|
|
return S("wrong diameter (should be 5, 7, or 9)")
|
2019-09-08 22:54:34 +03:00
|
|
|
end
|
2019-09-09 23:04:16 +03:00
|
|
|
return true
|
2019-09-08 22:54:34 +03:00
|
|
|
end
|
|
|
|
|
2019-09-14 00:01:55 +03:00
|
|
|
-- provide position behind the obsidian_glass
|
|
|
|
local function check_window(pos, in_dir)
|
2021-03-13 23:27:39 +03:00
|
|
|
local diameter = get_diameter(pos, in_dir)
|
|
|
|
if diameter then
|
|
|
|
local radius = (diameter - 1) / 2
|
2019-09-14 00:01:55 +03:00
|
|
|
local dir = tubelib2.Dir6dToVector[in_dir]
|
|
|
|
local cpos = vector.add(pos, vector.multiply(dir, radius))
|
|
|
|
-- calculate size
|
|
|
|
local pos1 = {x = cpos.x - radius, y = cpos.y - radius, z = cpos.z - radius}
|
|
|
|
local pos2 = {x = cpos.x + radius, y = cpos.y + radius, z = cpos.z + radius}
|
|
|
|
local poses,_ = minetest.find_nodes_in_area(pos1, pos2, {"default:obsidian_glass"})
|
|
|
|
if #poses == 1 then
|
|
|
|
local ndir = vector.direction(poses[1], cpos)
|
|
|
|
ndir = vector.normalize(ndir)
|
|
|
|
local npos = vector.add(poses[1], ndir)
|
|
|
|
return npos
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-08 22:54:34 +03:00
|
|
|
-- for logical communication
|
|
|
|
techage.register_node({"techage:ta4_pipe_inlet"}, {
|
|
|
|
on_transfer = function(pos, in_dir, topic, payload)
|
2019-10-05 20:19:18 +03:00
|
|
|
if topic == "diameter" then
|
2021-02-02 01:20:41 +03:00
|
|
|
return get_diameter(pos, in_dir)
|
2019-09-08 22:54:34 +03:00
|
|
|
elseif topic == "volume" then
|
2019-09-09 23:04:16 +03:00
|
|
|
return check_volume(pos, in_dir, payload)
|
2019-09-14 00:01:55 +03:00
|
|
|
elseif topic == "window" then
|
|
|
|
return check_window(pos, in_dir)
|
2019-09-08 22:54:34 +03:00
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
type = 'shapeless',
|
|
|
|
output = "techage:ta4_pipe_inlet",
|
|
|
|
recipe = {"basic_materials:concrete_block", "techage:ta4_pipeS"},
|
|
|
|
})
|