johnnic431

atapi

Aug 9th, 2016
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.41 KB | None | 0 0
  1. --[[
  2. Advanced Turtle API
  3. ]]
  4.  
  5. local lclx=0
  6. local lcly=0
  7. local lclz=0;
  8. local _tf,_tu,_td,_tb,_ttl,_ttr
  9. local fx=1
  10. local fz=0
  11.  
  12. function override()
  13.     _tf=turtle.forward
  14.     turtle.forward=aForw
  15.     _tb=turtle.back
  16.     turtle.back=aBack
  17.     _tu=turtle.up
  18.     turtle.up=aUp
  19.     _td=turtle.down
  20.     turtle.down=aDown
  21.     _ttl=turtle.turnLeft
  22.     turtle.turnLeft=aTurnL
  23.     _ttr=turtle.turnRight
  24.     turtle.turnRight=aTurnR
  25. end
  26.  
  27. function unoverride()
  28.     turtle.forward=_tf
  29.     turtle.back=_tb
  30.     turtle.up=_tu
  31.     turtle.down=_td
  32.     turtle.turnLeft=_ttl
  33.     turtle.turnRight=_ttr
  34. end
  35.  
  36. function aTurnR()
  37.     _ttr()
  38.     if fx==1 then
  39.         fx=0
  40.         fz=1
  41.     elseif fx==-1 then
  42.         fx=0
  43.         fz=-1
  44.     elseif fz==1 then
  45.         fx=-1
  46.         fz=0
  47.     else
  48.         fx=1
  49.         fz=0
  50.     end
  51. end
  52.  
  53. function aTurnL()
  54.     _ttl()
  55.     if fx==1 then
  56.         fx=0
  57.         fz=-1
  58.     elseif fx==-1 then
  59.         fx=0
  60.         fz=1
  61.     elseif fz==1 then
  62.         fx=1
  63.         fz=0
  64.     else
  65.         fx=-1
  66.         fz=0
  67.     end
  68. end
  69.  
  70. function aForw()
  71.     succ=_tf()
  72.     if succ then
  73.         lclx=lclx+fx
  74.         lclz=lclz+fz
  75.     end
  76.     return succ
  77. end
  78.  
  79. function aBack()
  80.     succ=_tb()
  81.     if succ then
  82.         lclx=lclx-fx
  83.         lclz=lclz-fz
  84.     end
  85.     return succ
  86. end
  87.  
  88. function aUp()
  89.     succ=_tu()
  90.     if succ then
  91.         lcly=lcly+1
  92.     end
  93.     return succ
  94. end
  95.  
  96. function aDown()
  97.     succ=_tu()
  98.     if succ then
  99.         lcly=lcly-1
  100.     end
  101.     return succ
  102. end
  103.  
  104. function setZero()
  105.     lclx=0
  106.     lcly=0
  107.     lclz=0
  108.     fx=1
  109.     fz=0
  110. end
  111.  
  112. function saveState()
  113.    
  114. end
  115.  
  116. function localPos()
  117.     return {lclx,lcly,lclz,fx,fz}
  118. end
Add Comment
Please, Sign In to add comment