Advertisement
amsarge

mine4

Apr 30th, 2021 (edited)
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.87 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. }
  35. function dropItems() -- drops items
  36.     print("Purging Inventory...")
  37.     for slot = 1, SLOT_COUNT, 1 do
  38.         local item = turtle.getItemDetail(slot) --gets details on item, if it's = to items to drop it will drop items
  39.         if(item ~= nil) then
  40.             for filterIndex = 1, #DROPPED_ITEMS, 1 do
  41.                 if(item["name"] ~= "minecraft:coal") then
  42.                     print("Dropping - " .. item["name"])
  43.                     turtle.select(slot)
  44.                     turtle.dropDown()
  45.                 end
  46.             end
  47.         end
  48.     end
  49. end
  50.  
  51. function getEnderIndex()
  52.     for slot = 1, SLOT_COUNT, 1 do
  53.         local item = turtle.getItemDetail(slot)
  54.         if(item ~= nil) then
  55.             if(item["name"] == "enderstorage:ender_storage") then
  56.                 return slot
  57.             end
  58.         end
  59.     end
  60.     return nil
  61. end
  62.  
  63. function manageInventory()
  64.     --dropItems()
  65.     index = getEnderIndex()
  66.     if(index ~= nil) then
  67.         turtle.select(index)
  68.         turtle.digUp()
  69.         turtle.placeUp()
  70.     end
  71.     -- Chest is now deployed
  72.     for slot = 1, SLOT_COUNT, 1 do
  73.         local item = turtle.getItemDetail(slot)
  74.         if(item ~= nil) then
  75.             if(item["name"] ~= "minecraft:blaze_rod") then
  76.                 turtle.select(slot)
  77.                 turtle.dropUp()
  78.             end
  79.         end
  80.     end
  81.     -- Items are now stored
  82.  
  83.     turtle.digUp()
  84. end
  85.  
  86. function reFuel()
  87.   index = getEnderIndex()
  88.   if(index ~= nil)then
  89.     turtle.select(index)
  90.     turtle.digUp()
  91.     turtle.placeUp()
  92.   end
  93.   turtle.select(1)
  94.   turtle.suckUp()
  95.   turtle.digUp()
  96. end
  97.  
  98. function checkFuel()
  99.     turtle.select(1)
  100.  
  101.     if(turtle.getFuelLevel() < 50) then
  102.         print("Attempting Refuel...")
  103.         for slot = 1, SLOT_COUNT, 1 do
  104.             turtle.select(slot)
  105.             if(turtle.refuel(1)) then
  106.                 return true
  107.             else
  108.               reFuel()
  109.               return true
  110.           end
  111.         end
  112.         return false
  113.       else
  114.         return true
  115.       end
  116.  
  117.     end
  118.  
  119.  
  120. function DigUp()
  121.     while(turtle.detectUp()) do
  122.       turtle.digUp()
  123.       turtle.digDown()
  124.       turtle.dig()
  125.  
  126.   end
  127. end
  128.  
  129. function DigDown()
  130.   while(turtle.detectDown()) do
  131.     turtle.digUp()
  132.     turtle.digDown()
  133.     turtle.dig()
  134.  
  135.   end
  136. end
  137.  
  138. function Dig()
  139.     while(turtle.detect()) do
  140.         turtle.digUp()
  141.         turtle.digDown()
  142.         turtle.dig()
  143.  
  144.     end
  145.   end
  146.  
  147.   function detectAndDig()
  148.     Dig()
  149.     DigDown()
  150.     DigUp()
  151.   end
  152.  
  153.  
  154.   function forward()
  155.     detectAndDig()
  156.     turtle.forward()
  157.   end
  158.  
  159.  
  160. function rightTurn()
  161.   turtle.turnRight()
  162.   detectAndDig()
  163.   turtle.forward()
  164.   turtle.turnRight()
  165.   detectAndDig()
  166. end
  167.  
  168.  
  169. function leftTurn()
  170.   turtle.turnLeft()
  171.   detectAndDig()
  172.   turtle.forward()
  173.   turtle.turnLeft()
  174.   detectAndDig()
  175. end
  176.  
  177. function flipDirection()
  178.     if(d == "north") then
  179.         d = "south"
  180.     elseif(d == "south") then
  181.         d = "north"
  182.     elseif(d == "west") then
  183.         d = "east"
  184.     elseif(d == "east") then
  185.         d = "west"
  186.     end
  187.  
  188. end
  189.  
  190. function turnAround(tier)
  191.     if(tier % 2 == 1) then
  192.         if(d == "north" or d == "east") then
  193.             rightTurn()
  194.         elseif(d == "south" or d == "west") then
  195.             leftTurn()
  196.         end
  197.     else
  198.         if(d == "north" or d == "east") then
  199.             leftTurn()
  200.         elseif(d == "south" or d == "west") then
  201.             rightTurn()
  202.         end
  203.     end
  204.     flipDirection()
  205. end
  206.  
  207. function start()
  208.     for tier = 1, height, 1 do
  209.         for col = 1, width, 1 do
  210.             for row = 1, depth - 1, 1 do
  211.                 if(not checkFuel()) then
  212.                     print("Turtle is out of fuel, Powering Down...")
  213.                     return
  214.                 end
  215.                 forward()
  216.                 print(string.format("Row: %d   Col: %d", row, col))
  217.             end
  218.             if(col ~= width) then
  219.                 turnAround(tier)
  220.             end
  221.                   manageInventory()
  222.             end
  223.  
  224.         end
  225.  
  226.     end
  227.  
  228.  
  229. start()
  230.  
  231. manageInventory()
  232.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement