MuffinGOD

Turtle V1.1

Nov 26th, 2020 (edited)
766
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local SLOT_COUNT = 16
  2. local d = "north"
  3. local width, depth, height = 10, 10, 2
  4.  
  5. arg = {...}
  6.  
  7. if (select('#', arg) == 3) then
  8.     width = tonumber(arg[1])
  9.     depth = tonumber(arg[2])
  10.     height = tonumber(arg[3])
  11. else
  12.     print('None or Malformed Size Given, Defaulting to 10x10x2 up')
  13. end
  14.  
  15. IGNORE_ITEMS = {
  16.   "minecraft:stone",
  17.   "minecraft:cobblestone",
  18.   "minecraft:sand",
  19.   "minecraft:gravel",
  20.   "minecraft:flint",
  21.   "minecraft:dirt",
  22.   "rustic:slate",
  23.   "quark:jasper",
  24.   "chisel:limestone2",
  25.   "chisel:marble2",
  26. }
  27.  
  28. function dropItems()
  29.   print("Purging inventory...")
  30.   for slot=1, SLOT_COUNT, 1 do
  31.     local item = turtle.getItemDetail(slot)
  32.     if(item ~= nil) then
  33.       for filterIndex = 1, #IGNORE_ITEMS, 1 do
  34.         if(item["name"] == IGNORE_ITEMS[filterIndex]) then
  35.           print("Dropping - " .. item["name"])
  36.           turtle.select(slot)
  37.           turtle.dropDown()
  38.         end
  39.       end
  40.     end
  41.   end
  42. end
  43.  
  44. function manageInventory()
  45.   dropItems()
  46. end
  47.  
  48. function checkFuel()
  49.     turtle.select(1)
  50.  
  51.     if(turtle.getFuelLevel() < 50) then
  52.         print("Attempting Refuel...")
  53.         for slot = 1, SLOT_COUNT, 1 do
  54.             turtle.select(slot)
  55.             if(turtle.refuel(1)) then
  56.                 return true
  57.             end
  58.         end
  59.  
  60.         return false
  61.     else
  62.         return true
  63.     end
  64. end
  65.  
  66.  
  67. function detectAndDig()
  68.     while(turtle.detect() or turtle.detectUp() or turtle.detectDown()) do
  69.         turtle.dig()
  70.         turtle.digUp()
  71.         turtle.digDown()
  72.     end
  73. end
  74.  
  75. function forward()
  76.     detectAndDig()
  77.     turtle.forward()
  78. end
  79.  
  80. function leftTurn()
  81.     turtle.turnLeft()
  82.     detectAndDig()
  83.     turtle.forward()
  84.     turtle.turnLeft()
  85.     detectAndDig()
  86. end
  87.  
  88.  
  89. function rightTurn()
  90.     turtle.turnRight()
  91.     detectAndDig()
  92.     turtle.forward()
  93.     turtle.turnRight()
  94.     detectAndDig()
  95. end
  96.  
  97. function flipDirection()
  98.     if(d == "north") then
  99.         d = "south"
  100.     elseif(d == "south") then
  101.         d = "north"
  102.     elseif(d == "west") then
  103.         d = "east"
  104.     elseif(d == "east") then
  105.         d = "west"
  106.     end
  107.  
  108. end
  109.  
  110. function turnAround(tier)
  111.     if(tier % 2 == 1) then
  112.         if(d == "north" or d == "east") then
  113.             rightTurn()
  114.         elseif(d == "south" or d == "west") then
  115.             leftTurn()
  116.         end
  117.     else
  118.         if(d == "north" or d == "east") then
  119.             leftTurn()
  120.         elseif(d == "south" or d == "west") then
  121.             rightTurn()
  122.         end
  123.     end
  124.     flipDirection()
  125. end
  126.  
  127.  
  128. function riseTier()
  129.     turtle.turnRight()
  130.     turtle.turnRight()
  131.     flipDirection()
  132.     turtle.digUp()
  133.     turtle.up()
  134.     turtle.digUp()
  135.     turtle.up()
  136.     turtle.digUp()
  137.     turtle.up()
  138. end
  139.  
  140.  
  141. function start()
  142.     for tier = 1, height, 1 do
  143.         for col = 1, width, 1 do
  144.             for row = 1, depth - 1, 1 do
  145.                 if(not checkFuel()) then
  146.                     print("Turtle is out of fuel, Powering Down...")
  147.                     return
  148.                 end
  149.                 forward()
  150.                 print(string.format("Row: %d   Col: %d", row, col))
  151.             end
  152.             if(col ~= width) then
  153.                 turnAround(tier)
  154.             end
  155.             manageInventory()
  156.         end
  157.         riseTier()
  158.     end
  159. end
  160.  
  161. start()
RAW Paste Data