MigasRocha

Quarry Nova

Feb 19th, 2021 (edited)
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.54 KB | None | 0 0
  1. local SLOT_COUNT = 16
  2. local d = "north"
  3. local width, depth, height = 10, 10, 2
  4.  
  5. if (#arg == 3) then
  6.     width = tonumber(arg[1])
  7.     depth = tonumber(arg[2])
  8.     height = tonumber(arg[3])
  9. else
  10.     print('None or Malformed Size Given, Defaulting to 10x10x2 up')
  11. end
  12.  
  13.  
  14. DROPPED_ITEMS = {
  15.     "minecraft:stone",
  16.     "minecraft:dirt",
  17.     "minecraft:cobblestone",
  18.     "minecraft:sand",
  19.     "minecraft:gravel",
  20.     "minecraft:redstone",
  21.     "minecraft:flint",
  22.     "railcraft:ore_metal",
  23.     "extrautils2:ingredients",
  24.     "minecraft:dye",
  25.     "thaumcraft:nugget",
  26.     "thaumcraft:crystal_essence",
  27.     "thermalfoundation:material",
  28.     "projectred-core:resource_item",
  29.     "thaumcraft:ore_cinnabar",
  30.     "deepresonance:resonating_ore",
  31.     "forestry:apatite"
  32. }
  33. function dropItems()
  34.     print("Purging Inventory...")
  35.     for slot = 1, SLOT_COUNT, 1 do
  36.         local item = turtle.getItemDetail(slot)
  37.         if(item ~= nil) then
  38.             for filterIndex = 1, #DROPPED_ITEMS, 1 do
  39.                 if(item["name"] == DROPPED_ITEMS[filterIndex]) then
  40.                     print("Dropping - " .. item["name"])
  41.                     turtle.select(slot)
  42.                     turtle.dropDown()
  43.                 end
  44.             end
  45.         end
  46.     end
  47. end
  48.  
  49.  
  50. function getEnderIndex()
  51.     for slot = 1, SLOT_COUNT, 1 do
  52.         local item = turtle.getItemDetail(slot)
  53.         if(item ~= nil) then
  54.             if(item["name"] == "enderstorage:ender_chest") then
  55.                 return slot
  56.             end
  57.         end
  58.     end
  59.     return nil
  60. end
  61.  
  62. function manageInventory()
  63.     dropItems()
  64.     index = getEnderIndex()
  65.     if(index ~= nil) then
  66.         turtle.select(index)
  67.         turtle.digUp()      
  68.         turtle.placeUp()  
  69.     end
  70.     -- Chest is now deployed
  71.     for slot = 1, SLOT_COUNT, 1 do
  72.         local item = turtle.getItemDetail(slot)
  73.         if(item ~= nil) then
  74.             if(item["name"] ~= "minecraft:coal_block" and item["name"] ~= "minecraft:coal") then
  75.                 turtle.select(slot)
  76.                 turtle.dropUp()
  77.             end
  78.         end
  79.     end
  80.     -- Items are now stored
  81.  
  82.     turtle.digUp()
  83. end
  84.  
  85. function checkFuel()
  86.     turtle.select(1)
  87.  
  88.     if(turtle.getFuelLevel() < 50) then
  89.         print("Attempting Refuel...")
  90.         turtle.select(16)
  91.         turtle.placeUp()
  92.         turtle.suckUp()
  93.         for slot = 1, SLOT_COUNT, 1 do
  94.             turtle.select(slot)
  95.             if(turtle.refuel(1)) then
  96.             turtle.select(16)
  97.             turtle.digUp()
  98.             turtle.dropUp()
  99.             turtle.digUp()
  100.                 return true
  101.             end
  102.         end
  103.  
  104.         return false
  105.     else
  106.         return true
  107.     end
  108. end
  109.  
  110.  
  111. function detectAndDig()
  112.     while(turtle.detect()) do
  113.         turtle.dig()
  114.         turtle.digUp()
  115.         turtle.digDown()
  116.     end
  117. end
  118.  
  119. function forward()
  120.     detectAndDig()
  121.     turtle.forward()
  122. end
  123.  
  124. function leftTurn()
  125.     turtle.turnLeft()
  126.     detectAndDig()
  127.     turtle.forward()
  128.     turtle.turnLeft()
  129.     detectAndDig()
  130. end
  131.  
  132.  
  133. function rightTurn()
  134.     turtle.turnRight()
  135.     detectAndDig()
  136.     turtle.forward()
  137.     turtle.turnRight()
  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.  
  172. function riseTier()
  173.     turtle.turnRight()
  174.     turtle.turnRight()
  175.     flipDirection()
  176.     turtle.digUp()
  177.     turtle.up()
  178. end
  179.  
  180.  
  181. function start()
  182.     for tier = 1, height, 1 do
  183.         for col = 1, width, 1 do
  184.             for row = 1, depth - 1, 1 do
  185.                 if(not checkFuel()) then
  186.                     print("Turtle is out of fuel, Powering Down...")
  187.                     return
  188.                 end
  189.                 forward()
  190.                 print(string.format("Row: %d   Col: %d", row, col))
  191.             end
  192.             if(col ~= width) then
  193.                 turnAround(tier)
  194.             end
  195.             manageInventory()
  196.         end
  197.         riseTier()
  198.     end
  199. end
  200.  
  201. start()
Add Comment
Please, Sign In to add comment