amsarge

Mine Done

Jan 7th, 2021 (edited)
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.14 KB | None | 0 0
  1. local SLOT_COUNT = 16
  2. local d = "north"
  3. local width, depth, height = 10, 10, 1
  4. local x = 0
  5.  
  6. if (#arg == 2) then
  7.     width = tonumber(arg[1])
  8.     depth = tonumber(arg[2])
  9.   else
  10.     print('No arguments given using defaults 10 x 10') -- asks for number input
  11. end
  12.  
  13. depth = depth + 1
  14.  
  15.  
  16. DROPPED_ITEMS = { -- Gets items to drop
  17.     "minecraft:stone",
  18.     "minecraft:dirt",
  19.     "minecraft:cobblestone",
  20.     "minecraft:sand",
  21.     "minecraft:gravel",
  22.     "minecraft:redstone",
  23.     "minecraft:flint",
  24.     "railcraft:ore_metal",
  25.     "extrautils2:ingredients",
  26.     "minecraft:dye",
  27.     "thaumcraft:nugget",
  28.     "thaumcraft:crystal_essence",
  29.     "thermalfoundation:material",
  30.     "projectred-core:resource_item",
  31.     "thaumcraft:ore_cinnabar",
  32.     "deepresonance:resonating_ore",
  33.     "forestry:apatite",
  34.     "minecraft:granite",
  35.     "minecraft:diorite",
  36.     "minecraft:andesite",
  37.     "create:scoria",
  38.     "astralsorcery:marble_raw",
  39.     "quark:slate",
  40.     "quark:marble",
  41.     "#forge:cobblestone",
  42.     "#forge:stone"
  43. }
  44. function dropItems() -- drops items
  45.     print("Purging Inventory...")
  46.     for slot = 1, SLOT_COUNT, 1 do
  47.         local item = turtle.getItemDetail(slot) --gets details on item, if it's = to items to drop it will drop items
  48.         if(item ~= nil) then
  49.             for filterIndex = 1, #DROPPED_ITEMS, 1 do
  50.                 if(item["name"] == DROPPED_ITEMS[filterIndex]) then
  51.                     print("Dropping - " .. item["name"])
  52.                     turtle.select(slot)
  53.                     turtle.dropDown()
  54.                 end
  55.             end
  56.         end
  57.     end
  58. end
  59.  
  60. function manageInventory()
  61.   dropItems()
  62.   turtle.digUp()
  63.   turtle.digDown()
  64. end
  65.  
  66. function checkFuel()
  67.     turtle.select(1)
  68.  
  69.     if(turtle.getFuelLevel() < 50) then
  70.         print("Attempting Refuel...")
  71.         for slot = 1, SLOT_COUNT, 1 do
  72.             turtle.select(slot)
  73.             if(turtle.refuel(1)) then
  74.                 return true
  75.             end
  76.         end
  77.  
  78.         return false
  79.     else
  80.         return true
  81.     end
  82. end
  83.  
  84. function DigUp()
  85.     while(turtle.detectUp()) do
  86.       turtle.digUp()
  87.       turtle.digDown()
  88.       turtle.dig()
  89.  
  90.   end
  91. end
  92.  
  93. function DigDown()
  94.   while(turtle.detectDown()) do
  95.     turtle.digUp()
  96.     turtle.digDown()
  97.     turtle.dig()
  98.  
  99.   end
  100. end
  101.  
  102. function Dig()
  103.     while(turtle.detect()) do
  104.         turtle.digUp()
  105.         turtle.digDown()
  106.         turtle.dig()
  107.  
  108.     end
  109.   end
  110.  
  111.   function detectAndDig()
  112.     Dig()
  113.     DigDown()
  114.     DigUp()
  115.   end
  116.  
  117.  
  118.   function forward()
  119.     detectAndDig()
  120.     turtle.forward()
  121.   end
  122.  
  123.  
  124. function rightTurn()
  125.   turtle.turnRight()
  126.   detectAndDig()
  127.   turtle.forward()
  128.   turtle.turnRight()
  129.   detectAndDig()
  130. end
  131.  
  132.  
  133. function leftTurn()
  134.   turtle.turnLeft()
  135.   detectAndDig()
  136.   turtle.forward()
  137.   turtle.turnLeft()
  138.   detectAndDig()
  139. end
  140.  
  141. function flipDirection()
  142.     if(d == "north") then
  143.         d = "south"
  144.     elseif(d == "south") then
  145.         d = "north"
  146.     elseif(d == "west") then
  147.         d = "east"
  148.     elseif(d == "east") then
  149.         d = "west"
  150.     end
  151.  
  152. end
  153.  
  154. function turnAround(tier)
  155.     if(tier % 2 == 1) then
  156.         if(d == "north" or d == "east") then
  157.             rightTurn()
  158.         elseif(d == "south" or d == "west") then
  159.             leftTurn()
  160.         end
  161.     else
  162.         if(d == "north" or d == "east") then
  163.             leftTurn()
  164.         elseif(d == "south" or d == "west") then
  165.             rightTurn()
  166.         end
  167.     end
  168.     flipDirection()
  169. end
  170.  
  171. function start()
  172.     for tier = 1, height, 1 do
  173.         for col = 1, width, 1 do
  174.             for row = 1, depth - 1, 1 do
  175.                 if(not checkFuel()) then
  176.                     print("Turtle is out of fuel, Powering Down...")
  177.                     return
  178.                 end
  179.                 forward()
  180.                 print(string.format("Row: %d   Col: %d", row, col))
  181.             end
  182.             if(col ~= width) then
  183.                 turnAround(tier)
  184.                 x = x + 1
  185.             end
  186.               if (x % 2 == 0) then
  187.                   manageInventory()
  188.               else
  189.                   print("Not Purging")
  190.             end
  191.  
  192.         end
  193.  
  194.     end
  195. end
  196.  
  197. start()
  198.  
Add Comment
Please, Sign In to add comment