Use 6d for pipes too

This commit is contained in:
Novatux 2014-01-01 17:40:22 +01:00
parent 1dab36812a
commit 4895aa6a0c
3 changed files with 112 additions and 144 deletions

View File

@ -1,31 +1,26 @@
-- autorouting for pipes -- autorouting for pipes
local tube_table = {[0] = 1, 2, 2, 4, 2, 4, 4, 5, 2, 3, 4, 6, 4, 6, 5, 7, 2, 4, 3, 6, 4, 5, 6, 7, 4, 6, 6, 8, 5, 7, 7, 9, 2, 4, 4, 5, 3, 6, 6, 7, 4, 6, 5, 7, 6, 8, 7, 9, 4, 5, 6, 7, 6, 7, 8, 9, 5, 7, 7, 9, 7, 9, 9, 10}
local function autoroute_pipes(pos, state) local tube_table_facedirs = {[0] = 0, 0, 5, 0, 3, 4, 3, 0, 2, 0, 2, 0, 6, 4, 3, 0, 7, 12, 5, 12, 7, 4, 5, 5, 18, 20, 16, 0, 7, 4, 7, 0, 1, 8, 1, 1, 1, 13, 1, 1, 10, 8, 2, 2, 17, 4, 3, 6, 9, 9, 9, 9, 21, 13, 1, 1, 10, 10, 11, 2, 19, 4, 3, 0}
local function autoroute_pipes(pos)
local nctr = minetest.get_node(pos) local nctr = minetest.get_node(pos)
local state = "_empty"
if (string.find(nctr.name, "pipeworks:pipe_") == nil) then return end if (string.find(nctr.name, "pipeworks:pipe_") == nil) then return end
if (string.find(nctr.name, "_loaded") ~= nil) then state = "_loaded" end
local nsurround = pipeworks.scan_pipe_surroundings(pos) local nsurround = pipeworks.scan_pipe_surroundings(pos)
if nsurround == "000000" then nsurround = "110000" end if nsurround == 0 then nsurround = 9 end
minetest.add_node(pos, { name = "pipeworks:pipe_"..nsurround..state }) minetest.add_node(pos, {name = "pipeworks:pipe_"..tube_table[nsurround]..state,
param2 = tube_table_facedirs[nsurround]})
end end
function pipeworks.scan_for_pipe_objects(pos) function pipeworks.scan_for_pipe_objects(pos)
autoroute_pipes({ x=pos.x-1, y=pos.y , z=pos.z }, "_loaded") autoroute_pipes({ x=pos.x-1, y=pos.y , z=pos.z })
autoroute_pipes({ x=pos.x+1, y=pos.y , z=pos.z }, "_loaded") autoroute_pipes({ x=pos.x+1, y=pos.y , z=pos.z })
autoroute_pipes({ x=pos.x , y=pos.y-1, z=pos.z }, "_loaded") autoroute_pipes({ x=pos.x , y=pos.y-1, z=pos.z })
autoroute_pipes({ x=pos.x , y=pos.y+1, z=pos.z }, "_loaded") autoroute_pipes({ x=pos.x , y=pos.y+1, z=pos.z })
autoroute_pipes({ x=pos.x , y=pos.y , z=pos.z-1 }, "_loaded") autoroute_pipes({ x=pos.x , y=pos.y , z=pos.z-1 })
autoroute_pipes({ x=pos.x , y=pos.y , z=pos.z+1 }, "_loaded") autoroute_pipes({ x=pos.x , y=pos.y , z=pos.z+1 })
autoroute_pipes(pos, "_loaded") autoroute_pipes(pos)
autoroute_pipes({ x=pos.x-1, y=pos.y , z=pos.z }, "_empty")
autoroute_pipes({ x=pos.x+1, y=pos.y , z=pos.z }, "_empty")
autoroute_pipes({ x=pos.x , y=pos.y-1, z=pos.z }, "_empty")
autoroute_pipes({ x=pos.x , y=pos.y+1, z=pos.z }, "_empty")
autoroute_pipes({ x=pos.x , y=pos.y , z=pos.z-1 }, "_empty")
autoroute_pipes({ x=pos.x , y=pos.y , z=pos.z+1 }, "_empty")
autoroute_pipes(pos, "_empty")
end end
-- auto-rotation code for various devices the tubes attach to -- auto-rotation code for various devices the tubes attach to
@ -191,7 +186,7 @@ function pipeworks.scan_pipe_surroundings(pos)
-- end -- end
-- --
return pxm..pxp..pym..pyp..pzm..pzp return pxm+8*pxp+2*pym+16*pyp+4*pzm+32*pzp
end end
function pipeworks.look_for_stackable_tanks(pos) function pipeworks.look_for_stackable_tanks(pos)

View File

@ -81,6 +81,8 @@ pipeworks.pipe_backstub = {
{ -3/64, -8/64, 30/64, 3/64, 8/64, 32/64 } { -3/64, -8/64, 30/64, 3/64, 8/64, 32/64 }
} }
pipeworks.pipe_boxes = {pipeworks.pipe_leftstub, pipeworks.pipe_rightstub, pipeworks.pipe_bottomstub, pipeworks.pipe_topstub, pipeworks.pipe_frontstub, pipeworks.pipe_backstub}
pipeworks.pipe_selectboxes = { pipeworks.pipe_selectboxes = {
{ -32/64, -8/64, -8/64, 8/64, 8/64, 8/64 }, { -32/64, -8/64, -8/64, 8/64, 8/64, 8/64 },
{ -8/64 , -8/64, -8/64, 32/64, 8/64, 8/64 }, { -8/64 , -8/64, -8/64, 32/64, 8/64, 8/64 },

217
pipes.lua
View File

@ -2,133 +2,69 @@
local pipes_empty_nodenames = {} local pipes_empty_nodenames = {}
local pipes_full_nodenames = {} local pipes_full_nodenames = {}
local outboxes = {}
local outsel = {}
local outimgs = {}
for xm = 0, 1 do local vti = {4, 3, 2, 1, 6, 5}
for xp = 0, 1 do 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}}
for ym = 0, 1 do for index, connects in ipairs(cconnects) do
for yp = 0, 1 do local outboxes = {}
for zm = 0, 1 do local outsel = {}
for zp = 0, 1 do local outimgs = {}
outboxes = {} for i = 1, 6 do
outsel = {} outimgs[vti[i]] = "pipeworks_plain.png"
outimgs = {}
if yp==1 then
pipeworks.add_node_box(outboxes, pipeworks.pipe_topstub)
table.insert(outsel, pipeworks.pipe_selectboxes[4])
table.insert(outimgs, "pipeworks_pipe_end.png")
else
table.insert(outimgs, "pipeworks_plain.png")
end end
if ym==1 then
pipeworks.add_node_box(outboxes, pipeworks.pipe_bottomstub) local jx = 0
table.insert(outsel, pipeworks.pipe_selectboxes[3]) local jy = 0
table.insert(outimgs, "pipeworks_pipe_end.png") local jz = 0
else for _, v in ipairs(connects) do
table.insert(outimgs, "pipeworks_plain.png") if v == 1 or v == 2 then
end jx = jx + 1
if xp==1 then elseif v == 3 or v == 4 then
pipeworks.add_node_box(outboxes, pipeworks.pipe_rightstub) jy = jy + 1
table.insert(outsel, pipeworks.pipe_selectboxes[2]) else
table.insert(outimgs, "pipeworks_pipe_end.png") jz = jz + 1
else end
table.insert(outimgs, "pipeworks_plain.png") pipeworks.add_node_box(outboxes, pipeworks.pipe_boxes[v])
end table.insert(outsel, pipeworks.pipe_selectboxes[v])
if xm==1 then outimgs[vti[v]] = "pipeworks_pipe_end.png"
pipeworks.add_node_box(outboxes, pipeworks.pipe_leftstub)
table.insert(outsel, pipeworks.pipe_selectboxes[1])
table.insert(outimgs, "pipeworks_pipe_end.png")
else
table.insert(outimgs, "pipeworks_plain.png")
end
if zp==1 then
pipeworks.add_node_box(outboxes, pipeworks.pipe_backstub)
table.insert(outsel, pipeworks.pipe_selectboxes[6])
table.insert(outimgs, "pipeworks_pipe_end.png")
else
table.insert(outimgs, "pipeworks_plain.png")
end
if zm==1 then
pipeworks.add_node_box(outboxes, pipeworks.pipe_frontstub)
table.insert(outsel, pipeworks.pipe_selectboxes[5])
table.insert(outimgs, "pipeworks_pipe_end.png")
else
table.insert(outimgs, "pipeworks_plain.png")
end end
local jx = xp+xm if #connects == 1 then
local jy = yp+ym local v = connects[1]
local jz = zp+zm v = v-1 + 2*(v%2) -- Opposite side
outimgs[vti[v]] = "^pipeworks_plain.png"
if (jx+jy+jz) == 1 then
if xm == 1 then
table.remove(outimgs, 3)
table.insert(outimgs, 3, "^pipeworks_plain.png")
end
if xp == 1 then
table.remove(outimgs, 4)
table.insert(outimgs, 4, "^pipeworks_plain.png")
end
if ym == 1 then
table.remove(outimgs, 1)
table.insert(outimgs, 1, "^pipeworks_plain.png")
end
if xp == 1 then
table.remove(outimgs, 2)
table.insert(outimgs, 2, "^pipeworks_plain.png")
end
if zm == 1 then
table.remove(outimgs, 5)
table.insert(outimgs, 5, "^pipeworks_plain.png")
end
if zp == 1 then
table.remove(outimgs, 6)
table.insert(outimgs, 6, "^pipeworks_plain.png")
end
end end
if jx+jy+jz >= 2 then if #connects >= 2 then
pipeworks.add_node_box(outboxes, pipeworks.pipe_bendsphere) pipeworks.add_node_box(outboxes, pipeworks.pipe_bendsphere)
end end
if (jx==2 and jy~=2 and jz~=2) then if jx == 2 and jy ~= 2 and jz ~= 2 then
table.remove(outimgs, 5) outimgs[5] = pipeworks.liquid_texture.."^pipeworks_windowed_XXXXX.png"
table.remove(outimgs, 5) outimgs[6] = outimgs[5]
table.insert(outimgs, 5, pipeworks.liquid_texture.."^pipeworks_windowed_XXXXX.png")
table.insert(outimgs, 5, pipeworks.liquid_texture.."^pipeworks_windowed_XXXXX.png")
end end
if (jx~=2 and jy~=2 and jz==2) or (jx~=2 and jy==2 and jz~=2) then local pgroups = {snappy = 3, pipe = 1, not_in_creative_inventory = 1}
table.remove(outimgs, 3) local pipedesc = "Pipe segement".." "..dump(connects).."... You hacker, you."
table.remove(outimgs, 3)
table.insert(outimgs, 3, pipeworks.liquid_texture.."^pipeworks_windowed_XXXXX.png")
table.insert(outimgs, 3, pipeworks.liquid_texture.."^pipeworks_windowed_XXXXX.png")
end
local pname = xm..xp..ym..yp..zm..zp
local pgroups = ""
local image = nil local image = nil
local pipedesc = "Pipe segment"
local pgroups = {snappy=3, pipe=1}
if pname ~= "110000" then if #connects == 0 then
pgroups = {snappy=3, pipe=1, not_in_creative_inventory=1} pgroups = {snappy = 3, tube = 1}
pipedesc = "Pipe segment (empty, "..pname..")... You hacker, you." pipedesc = "Pipe segment"
image = "pipeworks_plain.png" image = "pipeworks_plain.png"
end end
minetest.register_node("pipeworks:pipe_"..pname.."_empty", { --table.insert(pipeworks.tubenodes, name.."_"..tname)
minetest.register_node("pipeworks:pipe_"..index.."_empty", {
description = pipedesc, description = pipedesc,
drawtype = "nodebox", drawtype = "nodebox",
tiles = pipeworks.fix_image_names(outimgs, "_empty"), tiles = pipeworks.fix_image_names(outimgs, "_empty"),
sunlight_propagates = true,
inventory_image = image, inventory_image = image,
sunlight_propagates=true,
paramtype = "light", paramtype = "light",
paramtype2 = "facedir",
selection_box = { selection_box = {
type = "fixed", type = "fixed",
fixed = outsel fixed = outsel
@ -140,22 +76,23 @@ for zp = 0, 1 do
groups = pgroups, groups = pgroups,
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
walkable = true, walkable = true,
drop = "pipeworks:pipe_110000_empty", drop = "pipeworks:pipe_1_empty",
after_place_node = function(pos) after_place_node = function(pos)
pipeworks.scan_for_pipe_objects(pos) pipeworks.scan_for_pipe_objects(pos)
end, end,
after_dig_node = function(pos) after_dig_node = function(pos)
pipeworks.scan_for_pipe_objects(pos) pipeworks.scan_for_pipe_objects(pos)
end, end
}) })
minetest.register_node("pipeworks:pipe_"..pname.."_loaded", { minetest.register_node("pipeworks:pipe_"..index.."_loaded", {
description = "Pipe segment (loaded, "..pname..")... You hacker, you.", description = pipedesc,
drawtype = "nodebox", drawtype = "nodebox",
tiles = pipeworks.fix_image_names(outimgs, "_loaded"), tiles = pipeworks.fix_image_names(outimgs, "_loaded"),
inventory_image = image,
sunlight_propagates = true, sunlight_propagates = true,
inventory_image = image,
paramtype = "light", paramtype = "light",
paramtype2 = "facedir",
selection_box = { selection_box = {
type = "fixed", type = "fixed",
fixed = outsel fixed = outsel
@ -164,10 +101,10 @@ for zp = 0, 1 do
type = "fixed", type = "fixed",
fixed = outboxes fixed = outboxes
}, },
groups = {snappy=3, pipe=1, not_in_creative_inventory=1}, groups = pgroups,
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
walkable = true, walkable = true,
drop = "pipeworks:pipe_110000_empty", drop = "pipeworks:pipe_1_empty",
after_place_node = function(pos) after_place_node = function(pos)
pipeworks.scan_for_pipe_objects(pos) pipeworks.scan_for_pipe_objects(pos)
end, end,
@ -175,13 +112,47 @@ for zp = 0, 1 do
pipeworks.scan_for_pipe_objects(pos) pipeworks.scan_for_pipe_objects(pos)
end end
}) })
table.insert(pipes_empty_nodenames,"pipeworks:pipe_"..pname.."_empty") -- for the abms
table.insert(pipes_full_nodenames,"pipeworks:pipe_"..pname.."_loaded") -- for bacon table.insert(pipes_empty_nodenames, "pipeworks:pipe_"..index.."_empty")
end table.insert(pipes_empty_nodenames, "pipeworks:pipe_"..index.."_loaded")
end
end
end
end end
if REGISTER_COMPATIBILITY then
local cempty = "pipeworks:tube_compatibility_empty"
local cloaded = "pipeworks:tube_compatibility_loaded"
minetest.register_node(cempty, {
drawtype = "airlike",
groups = {not_in_creative_inventory = 1, pipe_to_update = 1},
})
minetest.register_node(cloaded, {
drawtype = "airlike",
groups = {not_in_creative_inventory = 1, pipe_to_update = 1},
})
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 pname = xm..xp..ym..yp..zm..zp
minetest.register_alias("pipeworks_"..pname.."_empty", cempty)
minetest.register_alias("pipeworks_"..pname.."_loaded", cloaded)
end
end
end
end
end
end
minetest.register_abm({
nodenames = {"group:pipe_to_update"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
pipeworks.scan_for_pipe_objects(pos)
end
})
end end
table.insert(pipes_empty_nodenames,"pipeworks:valve_on_empty") table.insert(pipes_empty_nodenames,"pipeworks:valve_on_empty")