Advertisement
Guest User

pokey.lua

a guest
Feb 27th, 2020
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.92 KB | None | 0 0
  1. local args = {...}
  2. local rightTurn
  3. local top
  4. local pos
  5. local x
  6. local y
  7. local z
  8.  
  9. local chunkStartLoc = args[1]
  10.  
  11. function pokeHole()
  12.  
  13. end
  14.  
  15. function digIfShould()
  16.     if shouldIDigHere() then
  17.         turtle.digDown()
  18.         pokeHole()
  19.     end
  20. end
  21.  
  22. function shouldIDigHere()
  23.     pos = vector.new(gps.locate(5))
  24.     truncateVectorComsToXYZ(pos)
  25.     if isint(x/5) and isint(z/5) then
  26.         return true
  27.     else
  28.         if isint((x-2)/5) and isint((z-1)/5) then
  29.             return true
  30.         else
  31.             if isint((x+1)/5) and isint((z-2)/5) then
  32.                 return true
  33.             else
  34.                 if isint((x-1)/5) and isint((z+2)/5) then
  35.                     return true
  36.                 else
  37.                     if isint((x+2)/5) and isint((z+1)/5) then
  38.                         return true
  39.                     else
  40.                       return false
  41.                     end
  42.                 end
  43.             end
  44.         end
  45.     end
  46. end
  47.  
  48. function truncateVectorComsToXYZ(vec)
  49.     x = math.modf(vec.x)
  50.     y = math.modf(vec.y)
  51.     z = math.modf(vec.z)
  52. end
  53.  
  54. function isint(num)
  55.     return num==math.floor(num)
  56. end
  57.  
  58. function turn21()
  59.     digIfShould()
  60.     if rightTurn then
  61.         turtle.turnRight()
  62.         turtle.forward()
  63.         turtle.turnRight()
  64.         rightTurn = false
  65.     else
  66.         turtle.turnLeft()
  67.         turtle.forward()
  68.         turtle.turnLeft()
  69.         rightTurn = true
  70.     end
  71. end
  72.  
  73. function main()
  74.     if not args[1] then
  75.         print("ERROR: Need turtle start location!")
  76.         exit()
  77.     end
  78.  
  79.     if chunkStartLoc == "left" then
  80.         rightTurn = true
  81.     else
  82.         rightTurn = false
  83.     end
  84.  
  85.     for i=1, 15 do
  86.         for j=1, 15 do
  87.             digIfShould()
  88.             turtle.forward()
  89.         end
  90.         turn21()
  91.     end
  92.     for i=1, 15 do
  93.         digIfShould()
  94.         turtle.forward()
  95.     end
  96.     digIfShould()
  97. end
  98.  
  99. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement