LivioBrunner

Logger

Nov 6th, 2013
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.88 KB | None | 0 0
  1. local actx = 0
  2. local acty = 0
  3. local actz = 0
  4. local actyaw = 0
  5. local lastx = 0
  6. local lasty = 0
  7. local lastz = 0
  8. local lastyaw = 0
  9. local anwser = false
  10. forwardcounter = 0
  11. function items()
  12.   for i = 1, 16 do
  13.     actitem = turtle.getItemCount(i)
  14.     allitems = allitems + actitem
  15.   end
  16.   return allitems
  17. end
  18. function createterm()
  19.   term.setCursorPos(1,6)
  20.   term.clearLine()
  21.   print("------X Blocks left until end------")
  22.   print("------X Fuellevel------")
  23. end
  24. function writeterm(msg,cursorlevel)
  25.   cursorlevel = 6 + cursorlevel
  26.   term.setCursorPos(1,cursorlevel)
  27.   term.clearLine()
  28.   print("------"..msg.."------")
  29. end
  30. function clearInv()
  31.   for i = 1,16 do
  32.     turtle.select(i)
  33.     turtle.drop(turtle.getItemCount(i))
  34.   end
  35.   turtle.select(1)
  36. end
  37. function clearterm()
  38.   term.clear()
  39.   term.setCursorPos(1,1)
  40. end
  41. function usefuel(slotnum)
  42.   turtle.select(slotnum)
  43.   turtle.refuel(1)
  44. end
  45. function setPositionVars()
  46.   lastx = actx
  47.   lasty = acty
  48.   lastz = actz
  49.   lastyaw = actyaw
  50. end
  51. function turtledig()
  52.    forwardcounter = forwardcounter + 1
  53.    writeterm(turtle.getFuelLevel().." Fuellevel", 1)
  54.    blocksleft = 0
  55.    turtle.dig()
  56.    if turtle.getItemCount(16) > 0 then
  57.     setPositionVars()
  58.     findBack(0,0,0,0,true)
  59.  
  60.    end
  61. end
  62. function turtledigup()
  63.    forwardcounter = forwardcounter + 1
  64.    writeterm(turtle.getFuelLevel().." Fuellevel", 1)
  65.    blocksleft = 0
  66.    turtle.digUp()
  67. end
  68. function turtledigdown()
  69.    forwardcounter = forwardcounter + 1
  70.    writeterm(turtle.getFuelLevel().." Fuellevel", 1)
  71.    blocksleft = 0
  72.    turtle.digDown()
  73.   if turtle.getItemCount(16) > 0 then
  74.     setPositionVars()
  75.     findBack(0,0,0,0,true)
  76.    end
  77. end
  78. function turtleup()
  79.   if turtle.up() == false then
  80.       while turtle.up() == false do
  81.          turtledigup()
  82.       end
  83.   end
  84.   acty = acty + 1
  85.   writeterm("x : ".. actx .. ", y : ".. acty .. ", z : ".. actz .. ", yaw : ".. actyaw, 2)
  86. end
  87. function turtledown()
  88.   if turtle.down() == false then
  89.       while turtle.down() == false do
  90.          turtledigdown()
  91.       end
  92.   end
  93.   acty = acty - 1
  94. end
  95. function goforward()
  96.   if turtle.forward() == false then
  97.       while turtle.forward() == false do
  98.          turtledig()
  99.       end
  100.   end
  101.   if actyaw == 0 then
  102.     actx = actx + 1
  103.   elseif actyaw == 1 then
  104.     actz = actz - 1
  105.   elseif actyaw == 2 then
  106.     actx = actx - 1
  107.   elseif actyaw == 3 then
  108.     actz = actz + 1
  109.   end
  110.   writeterm("x : ".. actx .. ", y : ".. acty .. ", z : ".. actz .. ", yaw : ".. actyaw, 2)
  111. end
  112. function findBack(x, y, z, yaw, anwser)
  113.   if anwser ~= true then
  114.     anwser = false
  115.   end
  116.   if x < actx then
  117.     while actyaw ~= 2 do
  118.       turtleleft()
  119.     end
  120.   elseif x > actx then
  121.     while actyaw ~= 0 do
  122.       turtleleft()
  123.     end
  124.   end
  125.   while actx ~= x do
  126.     goforward()
  127.   end
  128.   if z > actz then
  129.     while actyaw ~= 3 do
  130.       turtleleft()
  131.     end
  132.   elseif z < actz then
  133.     while actyaw ~= 1 do
  134.       turtleleft()
  135.     end
  136.   end
  137.   while actz ~= z do
  138.     goforward()
  139.   end
  140.   if y < acty then
  141.     while acty ~= y do
  142.       turtledown()
  143.     end
  144.   elseif y > acty then
  145.     while acty ~= y do
  146.       turtleup()
  147.     end
  148.   end
  149.   while actyaw ~= yaw do
  150.       turtleleft()
  151.     end
  152.   if anwser == true then
  153.     turtleleft()
  154.     turtleleft()
  155.     clearInv()
  156.     turtleleft()
  157.     turtleleft()
  158.     findBack(lastx, lasty, lastz, lastyaw, false)
  159.   end
  160. end
  161. function turtleright()
  162.   turtle.turnRight()
  163.   actyaw = actyaw + 1
  164.   if actyaw > 3 then
  165.     actyaw = 0
  166.   end
  167.   writeterm("x : ".. actx .. ", y : ".. acty .. ", z : ".. actz .. ", yaw : ".. actyaw, 2)
  168. end
  169. function turtleleft()
  170.   turtle.turnLeft()
  171.   actyaw = actyaw - 1
  172.   if actyaw < 0 then
  173.     actyaw = 3
  174.   end
  175.   writeterm("x : ".. actx .. ", y : ".. acty .. ", z : ".. actz .. ", yaw : ".. actyaw, 2)
  176. end
  177. findBack(2,0,0,0,false)
  178. findBack(2,5,0,0,false)
  179. findBack(0,0,0,0,false)
  180. turtle.select(1)
  181. termclear()
Advertisement
Add Comment
Please, Sign In to add comment