Advertisement
Guest User

mine

a guest
Feb 19th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.55 KB | None | 0 0
  1. tArgs = {...}
  2.  
  3. file = fs.open("Choords", "r")
  4. c = textutils.unserialize(file.readAll())
  5. file.close()
  6.  
  7. digging = true
  8.  
  9. blacklist = {"minecraft:grass", "minecraft:cobblestone", "minecraft:stone", "minecraft:dirt", "minecraft:gravel", "minecraft:sand"}
  10.  
  11. zDiff = {-1, 0, 1, 0}
  12. xDiff = {0, 1, 0, -1}
  13.  
  14. function saveChoords()
  15.   file = fs.open("Choords", "w")
  16.   file.write(textutils.serialize(c))
  17.   file.close()
  18. end
  19.  
  20. function down()
  21.   tryes = 0
  22.  
  23.   while not turtle.down() do
  24.     turtle.digDown()
  25.    
  26.     tryes = tryes + 1
  27.    
  28.     if tryes > 5 then
  29.       digging = false
  30.       exitHole()
  31.     end
  32.   end
  33.  
  34.   c.y = c.y - 1
  35.  
  36.   saveChoords()
  37. end
  38.  
  39. function forward()
  40.   while not turtle.forward() do
  41.     turtle.dig()
  42.   end
  43.  
  44.   c.x = c.x + xDiff[c.o]
  45.   c.z = c.z + zDiff[c.o]
  46.  
  47.   saveChoords()
  48. end
  49.  
  50. function right()
  51.   turtle.turnRight()
  52.  
  53.   c.o = c.o + 1
  54.  
  55.   if c.o > 4 then
  56.     c.o = 1
  57.   end
  58.  
  59.   saveChoords()
  60. end
  61.  
  62. function left()
  63.   turtle.turnLeft()
  64.  
  65.   c.o = c.o - 1
  66.  
  67.   if c.o < 1 then
  68.     c.o = 4
  69.   end
  70.  
  71.   saveChoords()
  72. end
  73.  
  74. function up()
  75.   while not turtle.up() do
  76.     turtle.digUp()
  77.   end
  78.  
  79.   c.y = c.y + 1
  80.  
  81.   saveChoords()
  82. end
  83.  
  84. function checkBlock()
  85.   f, block = turtle.inspect()
  86.  
  87.   if block ~= nil then
  88.     mine = true
  89.  
  90.     for i = 1,#blacklist do
  91.       if block.name == blacklist[i] then
  92.         mine = false
  93.       end
  94.     end
  95.  
  96.     if mine then
  97.       turtle.dig()
  98.     end
  99.   end
  100. end
  101.  
  102. function digLayer()
  103.   down()
  104.    
  105.   checkBlock()
  106.  
  107.   for i = 1,3 do
  108.     right()
  109.     checkBlock()  
  110.   end  
  111. end
  112.  
  113. function look(o)
  114.   while c.o ~= o do
  115.     right()
  116.   end
  117. end
  118.  
  119. function exitHole()
  120.   while c.y < 65 do
  121.     up()
  122.   end
  123.  
  124.   for i = 1,16 do
  125.     turtle.select(i)
  126.    
  127.     item = turtle.getItemDetail(i)
  128.  
  129.     if item ~= nil then
  130.       drop = false
  131.      
  132.       for i = 1,#blacklist do
  133.         if item.name == blacklist[i] then
  134.           drop = true  
  135.         end
  136.       end
  137.      
  138.       if drop then
  139.         turtle.dropDown()
  140.       end
  141.     end  
  142.   end
  143.  
  144.   look(1)
  145.  
  146.   forward()
  147.   forward()
  148.   left()
  149.   forward()  
  150.  
  151.   c.pos = c.pos - 1
  152.  
  153.   if c.pos < 0 then
  154.     look(2)
  155.    
  156.     for i = 1,c.maxPos+2 do
  157.       forward()
  158.     end
  159.    
  160.     left()
  161.    
  162.     for i = 1,c.maxPos/2+1 do
  163.       forward()
  164.     end
  165.    
  166.     c.pos = c.maxPos
  167.   end
  168.  
  169.   saveChoords()
  170. end
  171.  
  172. function hole()
  173.   digging = true
  174.  
  175.   while digging do
  176.     digLayer()
  177.   end
  178. end
  179.  
  180. if tArgs ~= nil then
  181.   for i = 1,tArgs[1] do
  182.     hole()
  183.   end
  184. else
  185.   hole()
  186. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement