2013-07-14 04:39:25 +02:00
|
|
|
-- This file supplies the various kinds of pneumatic tubes
|
2013-12-15 11:46:39 +01:00
|
|
|
|
2013-12-31 10:12:25 +01:00
|
|
|
pipeworks.tubenodes = {}
|
2013-01-16 20:16:14 +01:00
|
|
|
|
2012-08-24 19:39:29 +02:00
|
|
|
minetest.register_alias("pipeworks:tube", "pipeworks:tube_000000")
|
|
|
|
|
2013-12-15 10:35:59 +01:00
|
|
|
-- now, a function to define the tubes
|
2012-08-24 19:39:29 +02:00
|
|
|
|
2013-12-31 07:36:04 +01:00
|
|
|
local REGISTER_COMPATIBILITY = true
|
2012-08-24 19:39:29 +02:00
|
|
|
|
2013-12-31 07:36:04 +01:00
|
|
|
local vti = {4, 3, 2, 1, 6, 5}
|
2013-12-15 10:35:59 +01:00
|
|
|
|
2015-01-29 22:36:16 +01:00
|
|
|
local default_textures = {
|
|
|
|
noctrs = { "pipeworks_tube_noctr.png", "pipeworks_tube_noctr.png", "pipeworks_tube_noctr.png",
|
|
|
|
"pipeworks_tube_noctr.png", "pipeworks_tube_noctr.png", "pipeworks_tube_noctr.png"},
|
|
|
|
plain = { "pipeworks_tube_plain.png", "pipeworks_tube_plain.png", "pipeworks_tube_plain.png",
|
|
|
|
"pipeworks_tube_plain.png", "pipeworks_tube_plain.png", "pipeworks_tube_plain.png"},
|
|
|
|
ends = { "pipeworks_tube_end.png", "pipeworks_tube_end.png", "pipeworks_tube_end.png",
|
|
|
|
"pipeworks_tube_end.png", "pipeworks_tube_end.png", "pipeworks_tube_end.png"},
|
|
|
|
short = "pipeworks_tube_short.png",
|
|
|
|
inv = "pipeworks_tube_inv.png",
|
|
|
|
}
|
|
|
|
|
2013-12-31 07:36:04 +01:00
|
|
|
local register_one_tube = function(name, tname, dropname, desc, plain, noctrs, ends, short, inv, special, connects, style)
|
2015-01-29 22:36:16 +01:00
|
|
|
noctrs = noctrs or default_textures.noctrs
|
|
|
|
plain = plain or default_textures.plain
|
|
|
|
ends = ends or default_textures.ends
|
|
|
|
short = short or default_textures.short
|
|
|
|
inv = inv or default_textures.inv
|
|
|
|
|
2013-12-31 07:36:04 +01:00
|
|
|
local outboxes = {}
|
|
|
|
local outsel = {}
|
|
|
|
local outimgs = {}
|
|
|
|
|
|
|
|
for i = 1, 6 do
|
|
|
|
outimgs[vti[i]] = plain[i]
|
2012-08-24 19:39:29 +02:00
|
|
|
end
|
2013-12-31 07:36:04 +01:00
|
|
|
|
2013-12-31 10:26:25 +01:00
|
|
|
for _, v in ipairs(connects) do
|
2014-08-14 16:22:03 +02:00
|
|
|
table.extend(outboxes, pipeworks.tube_boxes[v])
|
2013-12-31 07:36:04 +01:00
|
|
|
table.insert(outsel, pipeworks.tube_selectboxes[v])
|
|
|
|
outimgs[vti[v]] = noctrs[v]
|
2012-08-24 19:39:29 +02:00
|
|
|
end
|
|
|
|
|
2013-12-31 07:36:04 +01:00
|
|
|
if #connects == 1 then
|
2013-12-31 10:26:25 +01:00
|
|
|
local v = connects[1]
|
|
|
|
v = v-1 + 2*(v%2) -- Opposite side
|
2013-12-31 07:36:04 +01:00
|
|
|
outimgs[vti[v]] = ends[v]
|
2012-08-24 19:39:29 +02:00
|
|
|
end
|
|
|
|
|
2014-08-14 16:22:03 +02:00
|
|
|
local tgroups = {snappy = 3, tube = 1, tubedevice = 1, not_in_creative_inventory = 1}
|
2013-12-31 07:36:04 +01:00
|
|
|
local tubedesc = desc.." "..dump(connects).."... You hacker, you."
|
2013-12-31 10:26:25 +01:00
|
|
|
local iimg = plain[1]
|
|
|
|
local wscale = {x = 1, y = 1, z = 1}
|
2013-12-15 08:53:10 +01:00
|
|
|
|
2013-12-31 07:36:04 +01:00
|
|
|
if #connects == 0 then
|
2014-08-14 16:22:03 +02:00
|
|
|
tgroups = {snappy = 3, tube = 1, tubedevice = 1}
|
2013-01-16 20:16:14 +01:00
|
|
|
tubedesc = desc
|
2013-12-15 08:53:10 +01:00
|
|
|
iimg=inv
|
2012-08-24 19:39:29 +02:00
|
|
|
outimgs = {
|
2013-12-31 10:26:25 +01:00
|
|
|
short, short,
|
2013-12-15 08:53:10 +01:00
|
|
|
ends[3],ends[4],
|
2013-12-31 10:26:25 +01:00
|
|
|
short, short
|
2012-08-24 19:39:29 +02:00
|
|
|
}
|
|
|
|
outboxes = { -24/64, -9/64, -9/64, 24/64, 9/64, 9/64 }
|
|
|
|
outsel = { -24/64, -10/64, -10/64, 24/64, 10/64, 10/64 }
|
2013-12-31 10:26:25 +01:00
|
|
|
wscale = {x = 1, y = 1, z = 0.01}
|
2012-08-24 19:39:29 +02:00
|
|
|
end
|
|
|
|
|
2014-08-14 16:22:03 +02:00
|
|
|
local rname = name.."_"..tname
|
|
|
|
table.insert(pipeworks.tubenodes, rname)
|
2013-01-16 20:16:14 +01:00
|
|
|
|
2013-12-31 10:26:25 +01:00
|
|
|
local nodedef = {
|
2012-08-24 19:39:29 +02:00
|
|
|
description = tubedesc,
|
|
|
|
drawtype = "nodebox",
|
|
|
|
tiles = outimgs,
|
2013-12-15 08:53:10 +01:00
|
|
|
sunlight_propagates = true,
|
2013-12-31 10:26:25 +01:00
|
|
|
inventory_image = iimg,
|
|
|
|
wield_image = iimg,
|
|
|
|
wield_scale = wscale,
|
2012-08-24 19:39:29 +02:00
|
|
|
paramtype = "light",
|
|
|
|
selection_box = {
|
2014-08-14 16:22:03 +02:00
|
|
|
type = "fixed",
|
2012-08-24 19:39:29 +02:00
|
|
|
fixed = outsel
|
|
|
|
},
|
|
|
|
node_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = outboxes
|
|
|
|
},
|
|
|
|
groups = tgroups,
|
|
|
|
sounds = default.node_sound_wood_defaults(),
|
|
|
|
walkable = true,
|
|
|
|
stack_max = 99,
|
2013-12-31 07:36:04 +01:00
|
|
|
basename = name,
|
|
|
|
style = style,
|
|
|
|
drop = name.."_"..dropname,
|
2013-12-31 10:26:25 +01:00
|
|
|
tubelike = 1,
|
2014-08-14 16:22:03 +02:00
|
|
|
tube = {
|
|
|
|
connect_sides = {front = 1, back = 1, left = 1, right = 1, top = 1, bottom = 1},
|
|
|
|
priority = 50
|
|
|
|
},
|
|
|
|
--[[after_place_node = function(pos)
|
2013-12-15 08:53:10 +01:00
|
|
|
pipeworks.scan_for_tube_objects(pos)
|
2014-08-14 16:22:03 +02:00
|
|
|
if minetest.registered_nodes[rname].after_place_node_ then
|
|
|
|
minetest.registered_nodes[rname].after_place_node_(pos)
|
2013-01-16 20:16:14 +01:00
|
|
|
end
|
2012-08-24 19:39:29 +02:00
|
|
|
end,
|
|
|
|
after_dig_node = function(pos)
|
2013-12-15 08:53:10 +01:00
|
|
|
pipeworks.scan_for_tube_objects(pos)
|
2014-08-14 16:22:03 +02:00
|
|
|
if minetest.registered_nodes[rname].after_dig_node_ then
|
|
|
|
minetest.registered_nodes[rname].after_dig_node_(pos)
|
2013-01-16 20:16:14 +01:00
|
|
|
end
|
2014-08-14 16:22:03 +02:00
|
|
|
end]]
|
2013-01-16 20:16:14 +01:00
|
|
|
}
|
2013-12-31 07:36:04 +01:00
|
|
|
if style == "6d" then
|
|
|
|
nodedef.paramtype2 = "facedir"
|
|
|
|
end
|
2013-01-16 20:16:14 +01:00
|
|
|
|
2013-12-31 10:26:25 +01:00
|
|
|
if special == nil then special = {} end
|
2013-01-16 20:16:14 +01:00
|
|
|
|
2013-12-31 10:26:25 +01:00
|
|
|
for key, value in pairs(special) do
|
2014-08-14 16:22:03 +02:00
|
|
|
--if key == "after_dig_node" or key == "after_place_node" then
|
|
|
|
-- nodedef[key.."_"] = value
|
|
|
|
if key == "groups" then
|
2013-12-31 10:26:25 +01:00
|
|
|
for group, val in pairs(value) do
|
|
|
|
nodedef.groups[group] = val
|
2013-01-17 19:49:27 +01:00
|
|
|
end
|
2013-12-31 10:26:25 +01:00
|
|
|
elseif key == "tube" then
|
|
|
|
for key, val in pairs(value) do
|
|
|
|
nodedef.tube[key] = val
|
2013-07-19 07:36:55 +02:00
|
|
|
end
|
2013-01-17 19:49:27 +01:00
|
|
|
else
|
2014-08-14 16:22:03 +02:00
|
|
|
nodedef[key] = table.recursive_replace(value, "#id", tname)
|
2013-01-16 20:16:14 +01:00
|
|
|
end
|
|
|
|
end
|
2013-06-22 21:08:05 +02:00
|
|
|
|
2014-08-14 16:22:03 +02:00
|
|
|
minetest.register_node(rname, nodedef)
|
2012-08-24 19:39:29 +02:00
|
|
|
end
|
2013-12-31 07:36:04 +01:00
|
|
|
|
|
|
|
pipeworks.register_tube = function(name, desc, plain, noctrs, ends, short, inv, special, old_registration)
|
2013-12-31 09:08:18 +01:00
|
|
|
if old_registration then
|
2013-12-31 07:36:04 +01:00
|
|
|
for xm = 0, 1 do
|
|
|
|
for xp = 0, 1 do
|
|
|
|
for ym = 0, 1 do
|
|
|
|
for yp = 0, 1 do
|
|
|
|
for zm = 0, 1 do
|
|
|
|
for zp = 0, 1 do
|
2013-12-31 09:08:18 +01:00
|
|
|
local connects = {}
|
|
|
|
if xm == 1 then
|
2013-12-31 10:26:25 +01:00
|
|
|
connects[#connects+1] = 1
|
2013-12-31 09:08:18 +01:00
|
|
|
end
|
|
|
|
if xp == 1 then
|
2013-12-31 10:26:25 +01:00
|
|
|
connects[#connects+1] = 2
|
2013-12-31 09:08:18 +01:00
|
|
|
end
|
|
|
|
if ym == 1 then
|
2013-12-31 10:26:25 +01:00
|
|
|
connects[#connects+1] = 3
|
2013-12-31 09:08:18 +01:00
|
|
|
end
|
|
|
|
if yp == 1 then
|
|
|
|
connects[#connects+1] = 4
|
|
|
|
end
|
|
|
|
if zm == 1 then
|
2013-12-31 10:26:25 +01:00
|
|
|
connects[#connects+1] = 5
|
2013-12-31 09:08:18 +01:00
|
|
|
end
|
|
|
|
if zp == 1 then
|
2013-12-31 10:26:25 +01:00
|
|
|
connects[#connects+1] = 6
|
2013-12-31 09:08:18 +01:00
|
|
|
end
|
2013-12-31 07:36:04 +01:00
|
|
|
local tname = xm..xp..ym..yp..zm..zp
|
2013-12-31 09:08:18 +01:00
|
|
|
register_one_tube(name, tname, "000000", desc, plain, noctrs, ends, short, inv, special, connects, "old")
|
|
|
|
end
|
|
|
|
end
|
2013-12-31 07:36:04 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-12-31 09:08:18 +01:00
|
|
|
else
|
2013-12-31 10:32:53 +01:00
|
|
|
-- 6d tubes: uses only 10 nodes instead of 64, but the textures must be rotated
|
2013-12-31 10:26:25 +01:00
|
|
|
local cconnects = {{}, {1}, {1, 2}, {1, 3}, {1, 3, 5}, {1, 2, 3}, {1, 2, 3, 5}, {1, 2, 3, 4}, {1, 2, 3, 4, 5}, {1, 2, 3, 4, 5, 6}}
|
2013-12-31 09:08:18 +01:00
|
|
|
for index, connects in ipairs(cconnects) do
|
|
|
|
register_one_tube(name, tostring(index), "1", desc, plain, noctrs, ends, short, inv, special, connects, "6d")
|
2013-12-31 07:36:04 +01:00
|
|
|
end
|
2013-12-31 09:08:18 +01:00
|
|
|
if REGISTER_COMPATIBILITY then
|
|
|
|
local cname = name.."_compatibility"
|
|
|
|
minetest.register_node(cname, {
|
2014-01-02 05:14:27 +01:00
|
|
|
drawtype = "airlike",
|
|
|
|
style = "6d",
|
|
|
|
basename = name,
|
|
|
|
inventory_image = inv,
|
|
|
|
wield_image = inv,
|
2014-01-02 10:36:52 +01:00
|
|
|
paramtype = "light",
|
2014-01-02 05:14:27 +01:00
|
|
|
sunlight_propagates = true,
|
2014-08-14 16:22:03 +02:00
|
|
|
description = "Pneumatic tube segment (legacy)",
|
|
|
|
--[[after_place_node = function(pos)
|
2014-01-02 05:14:27 +01:00
|
|
|
pipeworks.scan_for_tube_objects(pos)
|
2014-01-02 10:36:52 +01:00
|
|
|
if minetest.registered_nodes[name.."_1"].after_place_node_ then
|
|
|
|
minetest.registered_nodes[name.."_1"].after_place_node_(pos)
|
2014-01-02 05:14:27 +01:00
|
|
|
end
|
2014-08-14 16:22:03 +02:00
|
|
|
end,]]
|
|
|
|
groups = {not_in_creative_inventory = 1, tube_to_update = 1, tube = 1},
|
2014-01-02 05:14:27 +01:00
|
|
|
tube = {connect_sides = {front = 1, back = 1, left = 1, right = 1, top = 1, bottom = 1}},
|
|
|
|
drop = name.."_1",
|
2013-12-31 09:08:18 +01:00
|
|
|
})
|
2014-08-14 16:22:03 +02:00
|
|
|
table.insert(pipeworks.tubenodes, cname)
|
2013-12-31 09:08:18 +01:00
|
|
|
for xm = 0, 1 do
|
|
|
|
for xp = 0, 1 do
|
|
|
|
for ym = 0, 1 do
|
|
|
|
for yp = 0, 1 do
|
|
|
|
for zm = 0, 1 do
|
|
|
|
for zp = 0, 1 do
|
|
|
|
local tname = xm..xp..ym..yp..zm..zp
|
|
|
|
minetest.register_alias(name.."_"..tname, cname)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-12-31 07:36:04 +01:00
|
|
|
end
|
|
|
|
end
|
2012-08-24 19:39:29 +02:00
|
|
|
end
|
2013-12-31 07:36:04 +01:00
|
|
|
|
|
|
|
if REGISTER_COMPATIBILITY then
|
|
|
|
minetest.register_abm({
|
|
|
|
nodenames = {"group:tube_to_update"},
|
|
|
|
interval = 1,
|
|
|
|
chance = 1,
|
|
|
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
2014-08-14 16:22:03 +02:00
|
|
|
local minp = vector.subtract(pos, 1)
|
|
|
|
local maxp = vector.add(pos, 1)
|
2014-01-01 18:26:33 +01:00
|
|
|
if table.getn(minetest.find_nodes_in_area(minp, maxp, "ignore")) == 0 then
|
|
|
|
pipeworks.scan_for_tube_objects(pos)
|
|
|
|
end
|
2013-12-31 07:36:04 +01:00
|
|
|
end
|
|
|
|
})
|
2013-01-16 20:16:14 +01:00
|
|
|
end
|