2019-09-08 12:54:34 -07:00
|
|
|
--[[
|
|
|
|
|
|
|
|
TechAge
|
|
|
|
=======
|
|
|
|
|
|
|
|
Copyright (C) 2019 Joachim Stolberg
|
|
|
|
|
|
|
|
GPL v3
|
|
|
|
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
|
|
|
|
local D = techage.Debug
|
|
|
|
local M = minetest.get_meta
|
|
|
|
local S = techage.S
|
|
|
|
|
|
|
|
local Pipe = techage.BiogasPipe
|
|
|
|
|
|
|
|
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",
|
|
|
|
},
|
|
|
|
|
|
|
|
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(),
|
|
|
|
})
|
|
|
|
|
|
|
|
-- for mechanical pipe connections
|
|
|
|
techage.power.register_node({"techage:ta4_pipe_inlet"}, {
|
|
|
|
conn_sides = {"F", "B"},
|
|
|
|
power_network = Pipe,
|
|
|
|
})
|
|
|
|
|
2019-09-09 13:04:16 -07: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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
local function chat(owner, text)
|
|
|
|
if owner ~= nil then
|
|
|
|
minetest.chat_send_player(owner, string.char(0x1b).."(c@#ff0000)".."[Techage] Error: "..text.."!")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function get_radius(pos, in_dir)
|
|
|
|
local dir = tubelib2.Dir6dToVector[in_dir]
|
|
|
|
local pos2 = vector.add(pos, vector.multiply(dir, 8))
|
|
|
|
local poses = minetest.find_nodes_in_area(pos, pos2, {"techage:ta4_pipe_inlet"})
|
|
|
|
if #poses == 2 then
|
|
|
|
local radius = vector.distance(poses[1], poses[2]) / 2
|
|
|
|
if radius == 2 or radius == 3 or radius == 4 then
|
|
|
|
return radius
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function check_volume(pos, in_dir, owner)
|
|
|
|
local radius = get_radius(pos, in_dir)
|
|
|
|
if radius then
|
2019-09-08 12:54:34 -07:00
|
|
|
local dir = tubelib2.Dir6dToVector[in_dir]
|
2019-09-09 13:04:16 -07: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 12:54:34 -07:00
|
|
|
{"default:gravel", "techage:ta4_pipe_inlet",
|
|
|
|
"basic_materials:concrete_block", "default:obsidian_glass",
|
|
|
|
"techage:glow_gravel"})
|
2019-09-09 13:04:16 -07:00
|
|
|
if node_tbl["default:obsidian_glass"] > 1 then
|
|
|
|
chat(owner, "one window maximum")
|
|
|
|
return false
|
|
|
|
elseif node_tbl["default:obsidian_glass"] + node_tbl["basic_materials:concrete_block"] ~= Numbers.shell[radius] then
|
2019-09-15 14:30:04 -07:00
|
|
|
chat(owner, "wrong number of shell nodes")
|
2019-09-09 13:04:16 -07:00
|
|
|
return false
|
|
|
|
elseif node_tbl["default:gravel"] + node_tbl["techage:glow_gravel"] ~= Numbers.filling[radius] then
|
2019-09-15 14:30:04 -07:00
|
|
|
chat(owner, "wrong number of gravel nodes")
|
2019-09-09 13:04:16 -07:00
|
|
|
return false
|
2019-09-08 12:54:34 -07:00
|
|
|
end
|
2019-09-09 13:04:16 -07:00
|
|
|
else
|
|
|
|
chat(owner, "wrong diameter (should be 5, 7, or 9)")
|
|
|
|
return false
|
2019-09-08 12:54:34 -07:00
|
|
|
end
|
2019-09-09 13:04:16 -07:00
|
|
|
return true
|
2019-09-08 12:54:34 -07:00
|
|
|
end
|
|
|
|
|
2019-09-13 14:01:55 -07:00
|
|
|
-- provide position behind the obsidian_glass
|
|
|
|
local function check_window(pos, in_dir)
|
|
|
|
local radius = get_radius(pos, in_dir)
|
|
|
|
if radius then
|
|
|
|
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 12:54:34 -07:00
|
|
|
-- for logical communication
|
|
|
|
techage.register_node({"techage:ta4_pipe_inlet"}, {
|
|
|
|
on_transfer = function(pos, in_dir, topic, payload)
|
2019-09-09 13:04:16 -07:00
|
|
|
if topic == "radius" then
|
|
|
|
return get_radius(pos, in_dir)
|
2019-09-08 12:54:34 -07:00
|
|
|
elseif topic == "volume" then
|
2019-09-09 13:04:16 -07:00
|
|
|
return check_volume(pos, in_dir, payload)
|
2019-09-13 14:01:55 -07:00
|
|
|
elseif topic == "window" then
|
|
|
|
return check_window(pos, in_dir)
|
2019-09-08 12:54:34 -07:00
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
type = 'shapeless',
|
|
|
|
output = "techage:ta4_pipe_inlet",
|
|
|
|
recipe = {"basic_materials:concrete_block", "techage:ta4_pipeS"},
|
|
|
|
})
|