Feldherren

miner v1.1

May 5th, 2019
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.43 KB | None | 0 0
  1. local function find(itemName)
  2.     print("Searching for",itemName)
  3.     for curSlot = 1,16 do
  4.         if turtle.getItemCount(curSlot) >= 1 then
  5.             local data = turtle.getItemDetail(curSlot)
  6.             if data.name == itemName then
  7.                 print("Found",itemName,"in slot",curSlot)
  8.                 return curSlot
  9.             end
  10.         end
  11.     end
  12.     print("Could not find",itemName)
  13.     return false
  14. end
  15.  
  16. local tArgs = { ... }
  17. if #tArgs ~= 1 then
  18.     print( "Usage: miner <distance>" )
  19.     return
  20. end
  21.  
  22. local maxDist = tonumber( tArgs[1] )
  23. if maxDist < 1 then
  24.     print( "Distance must be positive" )
  25.     return
  26. end
  27.  
  28. local function digAround()
  29.     while turtle.detectUp() do
  30.         turtle.digUp()
  31.     end
  32.     if turtle.detectDown() then
  33.         local success, data = turtle.inspectDown()
  34.         if success then
  35.             if not (data.name == "minecraft:cobblestone") and not (data.name == "minecraft:stone") and not (data.name == "minecraft:sand") and not (data.name == "minecraft:dirt") and not (data.name == "minecraft:gravel") and not (data.name == "chisel:marble2") and not (data.name == "chisel:limestone2") then
  36.                 turtle.digDown()
  37.             end
  38.         end
  39.        
  40.     end
  41.     if find("minecraft:cobblestone") then
  42.         turtle.select(find("minecraft:cobblestone"))
  43.         turtle.placeDown()
  44.     elseif find("minecraft:stone") then
  45.         turtle.select(find("minecraft:stone"))
  46.         turtle.placeDown()
  47.     end
  48. end
  49.  
  50. local function checkFuel(level)
  51.     if (turtle.getFuelLevel() <= level) and (find("minecraft:coal")) then
  52.         turtle.select(find("minecraft:coal"))
  53.         turtle.refuel(1)
  54.     end
  55. end
  56.  
  57. for curDist=0,maxDist do
  58.     checkFuel(10)
  59.     digAround()
  60.     turtle.turnLeft()
  61.     while not turtle.forward() do
  62.         turtle.dig()
  63.     end
  64.     digAround()
  65.     turtle.turnRight()
  66.     turtle.turnRight()
  67.     turtle.forward()
  68.     while not turtle.forward() do
  69.         turtle.dig()
  70.     end
  71.     digAround()
  72.     turtle.turnLeft()
  73.     turtle.turnLeft()
  74.     turtle.forward()
  75.     if (curDist % 7 == 0) and (find("minecraft:torch")) then
  76.         turtle.select(find("minecraft:torch"))
  77.         turtle.place()
  78.     end
  79.     turtle.turnRight()
  80.     if curDist ~= maxDist then
  81.         while not turtle.forward() do
  82.             turtle.dig()
  83.         end
  84.     end
  85. end
  86.  
  87. turtle.turnLeft()
  88. turtle.turnLeft()
  89. for curDist=0,maxDist do
  90.     local success, data = turtle.inspect()
  91.     if success then
  92.         if data.name ~= "minecraft:chest" then
  93.             while not turtle.forward() do
  94.                 turtle.dig()
  95.             end
  96.         end
  97.     else
  98.         while not turtle.forward() do
  99.             turtle.dig()
  100.         end
  101.     end
  102. end
  103.  
  104. for curSlot = 1,16 do
  105.     turtle.select(curSlot)
  106.     turtle.drop()
  107. end
  108. turtle.turnLeft()
  109. turtle.turnLeft()
Advertisement
Add Comment
Please, Sign In to add comment