Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- names={"South","West","North","East","Up","Down"}
- local fM={nil,3,1,2,4}
- offsets={{0,0,1},{-1,0,0},{0,0,-1},{1,0,0},{0,1,0},{0,-1,0}}
- opposite={3,4,1,2,6,5}
- function addDir(dir,x,y,z,t)
- t=t or 1
- if not offsets[dir] then error("invalid dir",2) end
- if not (x and y and z) then error("must provide x,y,z",2) end
- local px,py,pz=unpack(offsets[dir])
- --print("x=",x," px=",px," y=",y," py=",py," z=",z," pz=",pz," t=",t)
- return x+px*t,y+py*t,z+pz*t
- end
- function fromMeta(meta)
- return fM[meta]
- end
- function rotL(dir)
- if dir<1 or dir>6 then error("invalid dir",2) end
- if dir>=5 then
- return dir
- end
- if dir == 1 then return 4 end
- return dir-1
- end
- function rotR(dir)
- if dir<1 or dir>6 then error("invalid dir",2) end
- if dir>=5 then
- return dir
- end
- if dir ==4 then return 1 end
- return dir+1
- end
- function bound(dir,x,y,z,width,height,depth)
- if not names[dir] then error("invalid dir",2) end
- if not (x and y and z and width and height and depth) then error("must provide 7 args to bound",2) end
- if depth>0 then depth=depth-1 else depth=depth+1 end
- if height>0 then height=height-1 else height=height+1 end
- if width>0 then width=width-1 else width=width+1 end
- local x2,_,z2=addDir(dir,x,y,z,depth)
- local x3,_,z3=addDir(rotR(dir),x,y,z,width)
- if x2==x then
- x=x3
- z=z2
- else
- x=x2
- z=z3
- end
- return x,y+height,z
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement