Advertisement
Guest User

mine

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