added support for 6d facedir for all tube components, changed autoplace.lua to follow tubes.connect_sides rather than having each component coded individually, and added support for placing deployers and node breakers facing vertically

This commit is contained in:
hdastwb
2013-07-19 01:36:55 -04:00
committed by Vanessa Ezekowitz
parent 3862070bfd
commit ec416df794
7 changed files with 530 additions and 333 deletions

View File

@ -2,6 +2,99 @@ modpath=minetest.get_modpath("pipeworks")
dofile(modpath.."/compat.lua")
--define the functions from https://github.com/minetest/minetest/pull/834 while waiting for the devs to notice it
local function dir_to_facedir(dir, is6d)
--account for y if requested
if is6d and math.abs(dir.y) > math.abs(dir.x) and math.abs(dir.y) > math.abs(dir.z) then
--from above
if dir.y < 0 then
if math.abs(dir.x) > math.abs(dir.z) then
if dir.x < 0 then
return 19
else
return 13
end
else
if dir.z < 0 then
return 10
else
return 4
end
end
--from below
else
if math.abs(dir.x) > math.abs(dir.z) then
if dir.x < 0 then
return 15
else
return 17
end
else
if dir.z < 0 then
return 6
else
return 8
end
end
end
--otherwise, place horizontally
elseif math.abs(dir.x) > math.abs(dir.z) then
if dir.x < 0 then
return 3
else
return 1
end
else
if dir.z < 0 then
return 2
else
return 0
end
end
end
local function facedir_to_dir(facedir)
--a table of possible dirs
return ({{x=0, y=0, z=1},
{x=1, y=0, z=0},
{x=0, y=0, z=-1},
{x=-1, y=0, z=0},
{x=0, y=-1, z=0},
{x=0, y=1, z=0}})
--indexed into by a table of correlating facedirs
[({[0]=1, 2, 3, 4,
5, 2, 6, 4,
6, 2, 5, 4,
1, 5, 3, 6,
1, 6, 3, 5,
1, 4, 3, 2})
--indexed into by the facedir in question
[facedir]]
end
--and an extra function for getting the right-facing vector
local function facedir_to_right_dir(facedir)
--find the other directions
local backdir = facedir_to_dir(facedir)
local topdir = ({[0]={x=0, y=1, z=0},
{x=0, y=0, z=1},
{x=0, y=0, z=-1},
{x=1, y=0, z=0},
{x=-1, y=0, z=0},
{x=0, y=-1, z=0}})[math.floor(facedir/4)]
--return a cross product
return {x=topdir.y*backdir.z - backdir.y*topdir.z,
y=topdir.z*backdir.x - backdir.z*topdir.x,
z=topdir.x*backdir.y - backdir.x*topdir.y}
end
minetest.register_craftitem("pipeworks:filter", {
description = "Filter",
stack_max = 99,
@ -39,24 +132,12 @@ minetest.register_node("pipeworks:filter", {
mesecons={effector={action_on=function(pos,node)
minetest.registered_nodes[node.name].on_punch(pos,node,nil)
end}},
tube={connect_sides={right=1}},
on_punch = function (pos, node, puncher)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
local frompos
local dir
if node.param2==0 then
frompos={x=pos.x-1,y=pos.y,z=pos.z}
dir={x=1,y=0,z=0}
elseif node.param2==1 then
frompos={x=pos.x,y=pos.y,z=pos.z+1}
dir={x=0,y=0,z=-1}
elseif node.param2==2 then
frompos={x=pos.x+1,y=pos.y,z=pos.z}
dir={x=-1,y=0,z=0}
else
frompos={x=pos.x,y=pos.y,z=pos.z-1}
dir={x=0,y=0,z=1}
end
local dir = facedir_to_right_dir(node.param2)
local frompos = {x=pos.x - dir.x, y=pos.y - dir.y, z=pos.z - dir.z}
local fromnode=minetest.get_node(frompos)
local frominv
if (not fromnode) or (not minetest.registered_nodes[fromnode.name]) or (not (minetest.registered_nodes[fromnode.name].tube and
@ -137,24 +218,12 @@ minetest.register_node("pipeworks:mese_filter", {
mesecons={effector={action_on=function(pos,node)
minetest.registered_nodes[node.name].on_punch(pos,node,nil)
end}},
tube={connect_sides={right=1}},
on_punch = function (pos, node, puncher)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
local frompos
local dir
if node.param2==0 then
frompos={x=pos.x-1,y=pos.y,z=pos.z}
dir={x=1,y=0,z=0}
elseif node.param2==1 then
frompos={x=pos.x,y=pos.y,z=pos.z+1}
dir={x=0,y=0,z=-1}
elseif node.param2==2 then
frompos={x=pos.x+1,y=pos.y,z=pos.z}
dir={x=-1,y=0,z=0}
else
frompos={x=pos.x,y=pos.y,z=pos.z-1}
dir={x=0,y=0,z=1}
end
local dir = facedir_to_right_dir(node.param2)
local frompos = {x=pos.x - dir.x, y=pos.y - dir.y, z=pos.z - dir.z}
local fromnode=minetest.get_node(frompos)
local frominv
if not (minetest.registered_nodes[fromnode.name].tube and