Advertisement
Pinkishu

peat

Jan 1st, 2013
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.51 KB | None | 0 0
  1. local home = vector.new(0,0,0)
  2.  
  3. local wps = {}
  4.  
  5. an.setSandboxBoundaries(-12,-8,-5,2,3,30)
  6. an.setSandboxAction("kill")
  7.  
  8. function regWP(name,x,y,z,dir)
  9.     wps[name] = {vector.new(x,y,z),dir}
  10. end
  11.  
  12. function moveWP(wpN,moveOrder)
  13.     an.goTo(an.localDelta(an.worldToLocal(wps[wpN][1])),moveOrder)
  14.     if wps[wpN][2] ~= nil then
  15.         an.turnDir(wps[wpN][2])
  16.     end
  17. end
  18.  
  19. function goHome()
  20.     an.goTo(an.localDelta(an.worldToLocal(vector.new(0,0,0))),{"y","x","z"})
  21.     an.turnDir(1)
  22. end
  23.  
  24. function getRowOff()
  25.     return math.abs(an.getLoc().x)
  26. end
  27.  
  28. function getLayerOff()
  29.     return 0
  30. end
  31.  
  32. function blockAllowed(blockPos)
  33.     if blockPos.x > 0 then return false end
  34.     if blockPos.x < -8 then return false end
  35.     if blockPos.z < 1 then return false end
  36.     if blockPos.z > 18 then return false end
  37.     if blockPos.y > -1 then return false end
  38.     if blockPos.y < -5 then return false end
  39.  
  40.     if (math.abs(blockPos.x)-1) % 3 == 0 then
  41.         --local cP = blockPos.z - 1
  42.         if ( blockPos.z + 1 ) % 3 == 0 then
  43.             return false
  44.         end
  45.     end
  46.  
  47.     return true
  48. end
  49.  
  50. function getRowEnd(row)
  51.     local row = row or getRowOff()
  52.     local endC = 1
  53.     if row % 2 == 0 then endC = 18 end
  54.     return endC
  55. end
  56.  
  57. function isEndOfRow()
  58.     local endC = getRowEnd()
  59.  
  60.     return ( an.getLoc().z == endC )
  61.  
  62. end
  63.  
  64. function translatePos(delta)
  65.     return an.getLoc() + delta
  66. end
  67.  
  68. function tryBreak()
  69.     if blockAllowed(translatePos(an.getVecMod())) then
  70.         turtle.dig()
  71.     end
  72. end
  73.  
  74. function tryBreakDown()
  75.     if blockAllowed(translatePos(vector.new(0,-1,0))) then
  76.         turtle.digDown()
  77.     end
  78. end
  79.  
  80. function harvestRow()
  81.     local layer = getLayerOff()
  82.     local row = getRowOff()
  83.     if row % 2 == 1 then
  84.         an.turnDir(3)
  85.     else
  86.         an.turnDir(1)
  87.     end
  88.  
  89.     while not isEndOfRow() do
  90.         tryBreak()
  91.         tryBreakDown()
  92.         an.forward()
  93.         print("CURN: "..textutils.serialize(an.getLoc()))
  94.     end
  95.     tryBreak()
  96.     tryBreakDown()
  97. end
  98.  
  99. function harvest()
  100.     goHome()
  101.     an.forward()
  102.     while getRowOff() < 8 do
  103.         harvestRow()
  104.         local modX = -1
  105.         local tarZ = getRowEnd(getRowOff())
  106.         local cur = an.getLoc()
  107.         cur.x = cur.x + modX
  108.         cur.z = tarZ
  109.         print("cur: " .. textutils.serialize(an.getLoc()))
  110.         print("moving to: " ..textutils.serialize(cur))
  111.         print("-----") read()
  112.         an.goTo(an.localDelta(cur),{"y","x","z"})
  113.     end
  114.  
  115. end
  116.  
  117. an.select(1)
  118. harvest()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement