Advertisement
Guest User

mine

a guest
May 30th, 2015
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.02 KB | None | 0 0
  1. -- Mine v1.7
  2.  
  3. -- API Loading :
  4. shell.run("t")
  5.  
  6. -- Vars :
  7. rednet.open("right")
  8. local mID = 63
  9.  
  10. local args = {}
  11. local facing = 0
  12. local depth = 0
  13. local fuelSlot = 16
  14. local trash = {
  15.   "minecraft:dirt",
  16.   "minecraft:stone",
  17.   "minecraft:cobblestone",
  18.   "minecraft:sand",
  19.   "minecraft:gravel",
  20.   "minecraft:grass",
  21.   "minecraft:water",
  22.   "minecraft:flowing_water",
  23.   "minecraft:lava",
  24.   "minecraft:flowing_lava",
  25.   "chisel:granite",
  26.   "chisel:andesite",
  27.   "chisel:diorite",
  28.   "chisel:limestone",
  29.   "chisel:marble"
  30. }
  31. local initialDepth = 0
  32.  
  33. args[1] = 0
  34. args = {...}
  35.  
  36. -- Functions :
  37.  
  38. function sendInfo(text)
  39.   rednet.send(
  40.     mID,
  41.     "INFO|" .. text
  42.   )
  43. end
  44.  
  45. function sendBlockInfo(name, meta)
  46.   depth = t.get().y + initialDepth
  47.   rednet.send(
  48.     mID,
  49.     "MINED|" .. depth .. "|" .. name .. "|" .. meta
  50.   )
  51. end
  52.  
  53. function printUsage()
  54.   print("usage: mine <initialDepth>")
  55. end
  56.  
  57. function isValuable(isBlock, data)
  58.   if isBlock then
  59.     for i=1, #trash do
  60.       if trash[i] == data.name then
  61.         return false
  62.       end
  63.     end
  64.   else
  65.     return false
  66.   end
  67.   sendBlockInfo(data.name, data.metadata)
  68.   return true
  69. end
  70.  
  71. function checkLayer()
  72.   for i=1, 4 do
  73.     if isValuable(turtle.inspect()) then
  74.       turtle.dig()
  75.     end
  76.     t.tR()
  77.   end
  78. end
  79.  
  80. function mine()
  81.   while turtle.getFuelLevel() < initialDepth * 2 do
  82.     t.refuel(fuelSlot)
  83.   end
  84.   sendInfo("Started mining...")
  85.   while t.getY() + initialDepth > 6 do
  86.     isValuable(turtle.inspectDown())
  87.     t.down(fuelSlot)
  88.     checkLayer()
  89.   end
  90.   sendInfo("Coming back up...")
  91.   while t.getY() < 0 do
  92.     t.up(fuelSlot)
  93.   end
  94.   sendInfo("Done")
  95. end
  96.  
  97. -- Main :
  98. if #args == 1 then
  99.   if args[1] == "help" then
  100.     printUsage()
  101.   elseif tonumber(args[1]) >= 10 then
  102.     initialDepth = tonumber(args[1])
  103.   else
  104.     print("error: initialDepth must be a number greater or equal to 10")
  105.   end
  106. else
  107.   print("error: wrong arguments")
  108.   printUsage()
  109. end
  110.  
  111. if initialDepth >= 10 then
  112.   mine()
  113. end
  114.  
  115. rednet.close("right")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement