Advertisement
DonnyKerstens

MineProgram

Nov 25th, 2020 (edited)
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.16 KB | None | 0 0
  1. local SLOT_COUNT = 16
  2. local d = "north"
  3. local width, depth, height = 10, 10, 1
  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 10x10x1 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_storage") then
  55.                 return slot
  56.             end
  57.         end
  58.     end
  59.     return nil
  60. end
  61.  
  62.  
  63. function getTorchIndex()
  64.     for slot = 1, SLOT_COUNT, 1 do
  65.         local item = turtle.getItemDetail(slot)
  66.         if(item ~= nil) then
  67.             if(item["name"] == "minecraft:torch") then
  68.                 return slot
  69.             end
  70.         end
  71.     end
  72.     return nil
  73. end
  74.  
  75.  
  76. function manageInventory()
  77.     dropItems()
  78.     index = getEnderIndex()
  79.     if(index ~= nil) then
  80.         turtle.select(index)
  81.         turtle.digUp()      
  82.         turtle.placeUp()  
  83.     end
  84.     -- Chest is now deployed
  85.     for slot = 1, SLOT_COUNT, 1 do
  86.         local item = turtle.getItemDetail(slot)
  87.         if(item ~= nil) then
  88.             if(item["name"] ~= "minecraft:coal_block" and item["name"] ~= "minecraft:coal" and item["name"] ~= "minecraft:torch") then
  89.                 turtle.select(slot)
  90.                 turtle.dropUp()
  91.             end
  92.         end
  93.     end
  94.     -- Items are now stored
  95.  
  96.     turtle.digUp()
  97. end
  98.  
  99. function checkFuel()
  100.     turtle.select(1)
  101.    
  102.     if(turtle.getFuelLevel() < 50) then
  103.         print("Attempting Refuel...")
  104.         for slot = 1, SLOT_COUNT, 1 do
  105.             turtle.select(slot)
  106.             if(turtle.refuel(1)) then
  107.                 return true
  108.             end
  109.         end
  110.         return false
  111.     else
  112.         return true
  113.     end
  114. end
  115.  
  116.  
  117. function detectAndDig()
  118.     while(turtle.detect()) do
  119.         turtle.dig()
  120.         turtle.digUp()
  121.         turtle.digDown()
  122.     end
  123. end
  124.  
  125. function forward()
  126.     detectAndDig()
  127.     turtle.forward()
  128. end
  129.  
  130. function leftTurn()
  131.     turtle.turnLeft()
  132.     detectAndDig()
  133.     turtle.forward()
  134.     turtle.turnLeft()
  135. end
  136.  
  137.  
  138. function rightTurn()
  139.     turtle.turnRight()
  140.     detectAndDig()
  141.     turtle.forward()
  142.     turtle.turnRight()
  143. end
  144.  
  145. function flipDirection()
  146.     if(d == "north") then
  147.         d = "south"
  148.     elseif(d == "south") then
  149.         d = "north"
  150.     elseif(d == "west") then
  151.         d = "east"
  152.     elseif(d == "east") then
  153.         d = "west"
  154.     end
  155.    
  156. end
  157.  
  158. function turnAround(tier)
  159.     if(tier % 2 == 1) then
  160.         if(d == "north" or d == "east") then
  161.             rightTurn()
  162.         elseif(d == "south" or d == "west") then
  163.             leftTurn()
  164.         end
  165.     else
  166.         if(d == "north" or d == "east") then
  167.             leftTurn()
  168.         elseif(d == "south" or d == "west") then
  169.             rightTurn()
  170.         end
  171.     end
  172.     flipDirection()
  173. end
  174.  
  175.  
  176. function riseTier()
  177.     turtle.turnRight()
  178.     turtle.turnRight()
  179.     flipDirection()
  180.     turtle.digUp()
  181.     turtle.up()
  182.    
  183. end
  184.  
  185.  
  186. function start()
  187.     for tier = 1, height, 1 do
  188.         for col = 1, width, 1 do
  189.             for row = 1, depth - 1, 1 do
  190.                 if(not checkFuel()) then
  191.                     print("Turtle is out of fuel, Powering Down...")
  192.                     return
  193.                 end
  194.                 detectAndDig()
  195.                 if(col == 1 or col == (width-1) or ((col % 6) == 0)) then
  196.                     if(row == 1 or row == (depth- 1) or ((row % 6) == 0)) then
  197.                         local torchIndex = getTorchIndex()
  198.                         if(torchIndex ~= nil) then
  199.                             turtle.select(torchIndex)
  200.                             turtle.digDown()  
  201.                             turtle.placeDown()
  202.                         end
  203.                     end
  204.                 end
  205.                 turtle.forward()
  206.                 print(string.format("Row: %d   Col: %d", row, col))
  207.             end
  208.             if(col ~= width) then
  209.                 turnAround(tier)
  210.             end
  211.             manageInventory()
  212.         end
  213.         --riseTier()
  214.     end
  215. end
  216.  
  217. start()
  218.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement