Advertisement
guitarplayer616

cc_notebook

Jan 12th, 2022
854
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.19 KB | None | 0 0
  1. require("turtle")
  2. facing = "east"
  3.  
  4. rightTurnsFromTo = {
  5.       north = {north=0, east=1, south=2, west=3},
  6.       east = {north=3, east=0,  south=1, west=2},
  7.       south = {north=2, east=3, south=0, west=1},
  8.       west = {north=1, east=2, south=3, west=0},
  9.     }
  10.  
  11. function tprint(tbl)
  12.   for i,v in pairs(tbl) do
  13.     print(i, v)
  14.   end
  15. end
  16.  
  17. function block1()
  18.   --scan and mine all blocks around
  19.   --use gps
  20.   if turtle.getFuelLevel() < 100 then
  21.     error("needs more fuel")
  22.   end
  23.   turtle.select(16)
  24.   turtle.digDown()
  25.   turtle.placeDown()
  26.   sleep(3)
  27.   tprint(peripheral.getNames())
  28.   tprint(peripheral.getMethods("bottom"))
  29.   scanner = peripheral.wrap("bottom")
  30.   if not scanner then
  31.     error("peripheral wrap bottom failed")
  32.   end
  33.   blocks = scanner.scan(8)
  34.   if not blocks then
  35.     error("scanner failed to scan")
  36.   end
  37.  
  38.   turtle.select(16)
  39.   turtle.digDown()  
  40. end
  41.  
  42. function block2()
  43.   function filter(blocks, needle)
  44.     output = {}
  45.     for i,v in pairs(blocks) do
  46.       if v.name:find(needle) then
  47.         output[#output+1] = v
  48.       end
  49.     end
  50.     return output  
  51.   end
  52.  
  53.   ores = filter(blocks,"dirt")
  54.   for i,v in pairs(ores) do
  55.     print(v.name, v.x, v.y, v.z)
  56.   end
  57. end
  58.  
  59. function block3()
  60.   function digToXZ(dT, dirIfGt0, dirIfLt0)
  61.     rightTurns = 0
  62.     if dT > 0 then
  63.       rightTurns = rightTurnsFromTo[facing][dirIfGt0]
  64.       temp = dirIfLt0
  65.     elseif dT < 0 then
  66.       rightTurns = rightTurnsFromTo[facing][dirIfLt0]
  67.       temp = dirIfGt0
  68.     end
  69.    
  70.     for i=1,rightTurns do
  71.       turtle.turnRight()
  72.     end
  73.     facing = temp
  74.    
  75.     for i=1,math.abs(dT) do
  76.       turtle.dig()
  77.       turtle.forward()
  78.     end
  79.   end
  80.  
  81.   function digToY(dy)
  82.     if dy > 0 then
  83.       for i=1,dy do
  84.         turtle.up()
  85.       end
  86.     elseif dy < 0 then
  87.       for i=1,math.abs(dy) do
  88.         turtle.down()
  89.       end
  90.     end
  91.   end
  92.  
  93.   function digTo(dx,dy,dz,dir)
  94.     digToXZ(dx, "east", "west")
  95.     digToXZ(dz, "south", "north")
  96.     digToY(dy)
  97.   end
  98.   for i,block in pairs(ores) do
  99.     x,y,z = gps.locate()
  100.     dx = x + block.x
  101.     dy = y + block.y
  102.     dz = z + block.z
  103.     digTo(dx,dy,dz,facing)
  104.   end
  105.  
  106. end
  107.  
  108. block1()
  109. block2()
  110. block3()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement