dveth

stripMine

Nov 23rd, 2020 (edited)
1,099
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local SLOT_COUNT = 16
  2.  
  3. local minecount = 0
  4.  
  5. local args = { ... }
  6. if #args == 0 then
  7.     print("Usage:stripmine <tunnel length> <number of tunnels>")
  8.     error()
  9. end
  10.  
  11. local length = args[1]
  12. local tunnels = 1
  13. if #args == 2 then
  14.     tunnels = args[2]
  15. end
  16.  
  17. function turnAround()
  18.     turtle.turnRight()
  19.     turtle.turnRight()
  20. end
  21.  
  22. function getItemIndex(itemName)
  23.     for slot = 1, SLOT_COUNT, 1 do
  24.         local item = turtle.getItemDetail(slot)
  25.         if(item ~= nil) then
  26.             if(item["name"] == itemName) then
  27.                 return slot
  28.             end
  29.         end
  30.     end
  31. end
  32.  
  33. function checkFuel()
  34.     while(turtle.getFuelLevel() < 500) do
  35.         print("Refuelling...")
  36.         fuelIndex = getItemIndex("minecraft:coal")
  37.         if(fuelIndex ~= nil) then
  38.             turtle.select(fuelIndex)
  39.             turtle.refuel()
  40.             print("Fuel level: "..turtle.getFuelLevel())
  41.         end
  42.     end
  43. end
  44.  
  45. function storeInventory()
  46.     if getItemIndex("enderstorage:ender_storage") then
  47.         chestIndex = getItemIndex("enderstorage:ender_storage")
  48.         turtle.select(chestIndex)
  49.         turtle.placeUp()
  50.         for slot = 1, SLOT_COUNT do
  51.             local item = turtle.getItemDetail(slot)
  52.             turtle.select(slot)
  53.             if(item ~= nil) then
  54.                 local itemname = item["name"]
  55.                 if(itemname ~= "minecraft:torch" and itemname ~= "minecraft:coal") then
  56.                     turtle.dropUp()
  57.                 end
  58.             end
  59.         end
  60.         turtle.digUp()
  61.     end
  62. end
  63.  
  64. function digAndMove()
  65.     while turtle.detect() do
  66.         turtle.dig()
  67.     end
  68.     turtle.forward()
  69.     turtle.digDown()
  70.     turtle.digUp()
  71.     minecount = minecount + 1
  72.     if(minecount == 30) then
  73.         print("Storing inventory")
  74.         storeInventory()
  75.         minecount = 0
  76.     end
  77. end
  78.  
  79. function placeTorch()
  80.     if getItemIndex("minecraft:torch") then
  81.         local torchIndex = getItemIndex("minecraft:torch")
  82.         turnAround()
  83.         turtle.select(torchIndex)
  84.         turtle.down()
  85.         turtle.place()
  86.         turtle.up()
  87.         turnAround()
  88.     end
  89. end
  90.  
  91. function nextTunnel()
  92.     turtle.turnLeft()
  93.     for i = 1, 4 do
  94.         digAndMove()
  95.         turtle.digUp()
  96.     end
  97.     turtle.turnRight()
  98. end
  99.  
  100. function digTunnel()
  101.     local tunnelsteps = 1
  102.     for i = 1, length do
  103.         digAndMove()
  104.         if tunnelsteps % 7 == 0 then
  105.             placeTorch()
  106.             tunnelsteps = 0
  107.         end
  108.         tunnelsteps = tunnelsteps + 1
  109.     end
  110.     turtle.turnRight()
  111.     digAndMove()
  112.     turtle.turnRight()
  113.     for i = 1, length do
  114.         digAndMove()
  115.     end
  116.  
  117.     --Return to starting position
  118.     turtle.turnRight()
  119.     turtle.forward()
  120.     turtle.turnRight()
  121. end
  122.  
  123. for i = 1, tunnels do
  124.     digTunnel()
  125.     nextTunnel()
  126.     checkFuel()
  127. end
RAW Paste Data