Advertisement
joacber

dig_test

Nov 30th, 2020 (edited)
748
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.20 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.     "extrautils2:ingredients",
  19.     "thaumcraft:nugget",
  20.     "thaumcraft:crystal_essence",
  21.     "thaumcraft:ore_cinnabar",
  22.     "forestry:apatite"
  23. }
  24. function dropItems()
  25.     print("Purging Inventory...")
  26.     for slot = 1, SLOT_COUNT, 1 do
  27.         local item = turtle.getItemDetail(slot)
  28.         if(item ~= nil) then
  29.             for filterIndex = 1, #DROPPED_ITEMS, 1 do
  30.                 if(item["name"] == DROPPED_ITEMS[filterIndex]) then
  31.                     print("Dropping - " .. item["name"])
  32.                     turtle.select(slot)
  33.                     turtle.dropDown()
  34.                 end
  35.             end
  36.         end
  37.     end
  38. end
  39.  
  40.  
  41. function getEnderIndex()
  42.     for slot = 1, SLOT_COUNT, 1 do
  43.         local item = turtle.getItemDetail(slot)
  44.         if(item ~= nil) then
  45.             if(item["name"] == "enderstorage:ender_storage") then
  46.                 return slot
  47.             end
  48.         end
  49.     end
  50.     return nil
  51. end
  52.  
  53. function manageInventory()
  54.     dropItems()
  55.     index = getEnderIndex()
  56.     if(index ~= nil) then
  57.         turtle.select(index)
  58.         turtle.digUp()      
  59.         turtle.placeUp()  
  60.     end
  61.     -- Chest is now deployed
  62.     for slot = 2, SLOT_COUNT, 1 do
  63.         local item = turtle.getItemDetail(slot)
  64.         if(item ~= nil) then
  65.             --if(item["name"] ~= "minecraft:coal_block" and item["name"] ~= "minecraft:coal") then
  66.             turtle.select(slot)
  67.             turtle.dropUp()
  68.             --end
  69.         end
  70.     end
  71.     -- Items are now stored
  72.  
  73.     turtle.digUp()
  74. end
  75.  
  76. function checkFuel()
  77.     turtle.select(1)
  78.    
  79.     if(turtle.getFuelLevel() < 50) then
  80.         print("Attempting Refuel...")
  81.         for slot = 1, SLOT_COUNT, 1 do
  82.             turtle.select(slot)
  83.             if(turtle.refuel(1)) then
  84.                 return true
  85.             end
  86.         end
  87.  
  88.         return false
  89.     else
  90.         return true
  91.     end
  92. end
  93.  
  94.  
  95. function detectAndDig()
  96.     while(turtle.detect() or turtle.detectUp() or turtle.detectDown() ) do
  97.         turtle.dig()
  98.         turtle.digUp()
  99.         turtle.digDown()
  100.     end
  101. end
  102.  
  103. function forward()
  104.     detectAndDig()
  105.     turtle.forward()
  106. end
  107.  
  108. function leftTurn()
  109.     turtle.turnLeft()
  110.     detectAndDig()
  111.     turtle.forward()
  112.     turtle.turnLeft()
  113.     detectAndDig()
  114. end
  115.  
  116.  
  117. function rightTurn()
  118.     turtle.turnRight()
  119.     detectAndDig()
  120.     turtle.forward()
  121.     turtle.turnRight()
  122.     detectAndDig()
  123. end
  124.  
  125. function flipDirection()
  126.     if(d == "north") then
  127.         d = "south"
  128.     elseif(d == "south") then
  129.         d = "north"
  130.     elseif(d == "west") then
  131.         d = "east"
  132.     elseif(d == "east") then
  133.         d = "west"
  134.     end
  135.    
  136. end
  137.  
  138. function turnAround(tier)
  139.     if(tier % 2 == 1) then
  140.         if(d == "north" or d == "east") then
  141.             rightTurn()
  142.         elseif(d == "south" or d == "west") then
  143.             leftTurn()
  144.         end
  145.     else
  146.         if(d == "north" or d == "east") then
  147.             leftTurn()
  148.         elseif(d == "south" or d == "west") then
  149.             rightTurn()
  150.         end
  151.     end
  152.     flipDirection()
  153. end
  154.  
  155.  
  156. function riseTier()
  157.     turtle.turnRight()
  158.     turtle.turnRight()
  159.     flipDirection()
  160.     turtle.digUp()
  161.     turtle.up()
  162.     turtle.digUp()
  163.     turtle.up()
  164.     turtle.digUp()
  165.     turtle.up()
  166. end
  167.  
  168.  
  169. function start()
  170.     for tier = 1, height, 1 do
  171.         for col = 1, width, 1 do
  172.             for row = 1, depth - 1, 1 do
  173.                 if(not checkFuel()) then
  174.                     print("Turtle is out of fuel, Powering Down...")
  175.                     return
  176.                 end
  177.                 forward()
  178.                 print(string.format("Row: %d   Col: %d", row, col))
  179.             end
  180.             if(col ~= width) then
  181.                 turnAround(tier)
  182.             end
  183.             manageInventory()
  184.         end
  185.         riseTier()
  186.     end
  187. end
  188.  
  189. start()
  190.  
  191.  
  192.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement