Advertisement
Aixler

MineCompare

Feb 17th, 2013
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.26 KB | None | 0 0
  1. --TODO continue after chunk reload
  2.  
  3. function printUsage()
  4.     print( "Usage:" )
  5.     print( "Mine <forward> <right> <down>" )
  6. end
  7.  
  8. tArgs = { ... }
  9. if #tArgs ~= 3 then
  10.     printUsage()
  11.     return
  12. elseif tonumber(tArgs[1]) == nil or tonumber(tArgs[2]) == nil or tonumber(tArgs[3]) == nil then
  13.     printUsage()
  14.     return
  15. end
  16.  
  17. dropped = 0
  18. attacked = 0
  19. turn = 0
  20. mined = 0
  21. deep = 3
  22. compared = 0 --added
  23. slot = 5 -- was 1
  24. turtle.select(slot)
  25. A = tonumber(tArgs[1])
  26. B = tonumber(tArgs[2])
  27. C = tonumber(tArgs[3])
  28.  
  29. if A < 1 or A > 256 then
  30.     print("forward must be between 1 and 256")
  31.     error()
  32. elseif B < 1 or B > 256 then
  33.     print("right must be between 1 and 256")
  34.     error()
  35. elseif C < 1 or C > 256 then
  36.     print("down must be between 1 and 256")
  37.     error()
  38. end
  39.  
  40. forward = A - 1
  41. right = B - 1
  42. down = math.floor(C / 3) - 1
  43. downRemaining = math.fmod(C,3)
  44.  
  45. if down < 0 then
  46.     down = 0
  47.     downRemaining = 0
  48. end
  49.  
  50. if C < 3 then
  51.     oneLayer = 0
  52. else
  53.     oneLayer = C - 3
  54. end
  55.  
  56. function fuel()
  57.     fuelNeeded = (A * B - 1) * math.ceil(C / 3) + oneLayer
  58.     fuelLevel = turtle.getFuelLevel()
  59.     fuelDifference = fuelNeeded - fuelLevel
  60.     fuelCoal = math.ceil(fuelDifference / 80)
  61.     if fuelLevel >= fuelNeeded then
  62.         print("*Fuel usage: ".. fuelNeeded .." out of ".. fuelLevel .."")
  63.         print("*Enough fuel to proceed")
  64.     else
  65.         print("*Need ".. fuelDifference .." more fuel (".. fuelCoal .." Coal)")
  66.         while fuelNeeded > fuelLevel do
  67.             C = C - 1
  68.             if C < 3 then
  69.                 oneLayer = 0
  70.             else
  71.                 oneLayer = C - 3
  72.             end
  73.         fuelNeeded = (A * B - 1) * math.ceil(C / 3) + oneLayer
  74.         end
  75.         print("*Max area with current fuel: ".. A .." ".. B .." ".. C .."")
  76.         print("*Shutting Down...")
  77.         error()
  78.     end
  79. end
  80.  
  81. fuel()
  82. print("'Put an enderchest in slot 1'")
  83. print("'put compare blocks in slot 2/3/4") --added
  84. print("'Turtle will mine forward, right, down'")
  85. print("'Type in anything to start'")
  86.  
  87. io.read()
  88.  
  89. function compareUp() --added
  90.     for ore=2, 4 do
  91.         turtle.select(ore)
  92.         if turtle.compareUp() then
  93.             compared = compared + 1
  94.             return true
  95.         end
  96.     end
  97.     return false
  98. end
  99.  
  100. function compareDown() --added
  101.     for ore=2, 4 do
  102.         turtle.select(ore)
  103.         if turtle.compareDown() then
  104.             compared = compared + 1
  105.             return true
  106.         end
  107.     end
  108.     return false
  109. end
  110.  
  111. function full()
  112.     if turtle.getItemCount(16) > 0 then
  113.         dropOff()
  114.     end
  115. end
  116.  
  117. function dropOff()
  118.     turtle.select(1)
  119.     while turtle.placeUp() == false do
  120.         if turtle.digUp() == false then
  121.             turtle.attackUp()
  122.         end
  123.     end
  124.     slot = 5
  125.     for e=1, 12 do
  126.         turtle.select(slot)
  127.         turtle.dropUp()
  128.         slot = slot + 1
  129.     end
  130.     turtle.select(1)
  131.     turtle.digUp()
  132.     dropped = dropped + 1
  133. end
  134.  
  135. function mine()
  136.     full()
  137.     while turtle.forward() == false do
  138.         if turtle.dig() == false then
  139.             turtle.attack()
  140.             mined = mined - 1
  141.             attacked = attacked + 1
  142.         end
  143.         mined = mined + 1
  144.     end
  145.  
  146.     full()
  147.     if not compareDown() then --added
  148.         if turtle.digDown() then
  149.             mined = mined + 1
  150.         end
  151.     end
  152.     full()
  153.     if not compareUp() then --added
  154.         if turtle.digUp() then
  155.             mined = mined + 1
  156.         end
  157.     end
  158. end
  159.  
  160. function line()
  161.     for x=1, forward do
  162.         mine()
  163.     end
  164. end
  165.  
  166. function square()
  167.     for y=1, right do
  168.         line()
  169.         if turn == 0 then
  170.             turtle.turnRight()
  171.             mine()
  172.             turtle.turnRight()
  173.             turn = turn + 1
  174.         else
  175.             turtle.turnLeft()
  176.             mine()
  177.             turtle.turnLeft()
  178.             turn = turn - 1
  179.         end
  180.     end
  181.     line()
  182. end
  183.  
  184. function cube()
  185.     full()
  186.     if not compareDown() then --added
  187.         if turtle.digDown() then
  188.             mined = mined + 1
  189.         end
  190.     end
  191.     full()
  192.     if not compareUp() then --added
  193.         if turtle.digUp() then
  194.             mined = mined + 1
  195.         end
  196.     end
  197.  
  198.     square()
  199.     for z=1, down do
  200.         digCube()
  201.     end
  202.     if downRemaining ~= 0 then
  203.         deep = downRemaining
  204.         digCube()
  205.     end
  206. end
  207.  
  208. function digCube()
  209.     for d=1, deep do
  210.         while turtle.down() == false do
  211.             if turtle.digDown() == false then
  212.                 turtle.attackDown()
  213.                 mined = mined - 1
  214.                 attacked = attacked + 1
  215.             end
  216.             mined = mined + 1
  217.         end
  218.     end
  219.     full()
  220.     if not compareDown() then --added
  221.         if turtle.digDown() then
  222.             mined = mined + 1
  223.         end
  224.     end
  225.     turtle.turnRight()
  226.     turtle.turnRight()
  227.     square()
  228. end
  229.  
  230. cube()
  231. dropOff()
  232. print ("Mined ".. mined .." blocks")
  233. print ("Attacked ".. attacked .." times")
  234. print ("Dropped off ".. dropped .." times")
  235. print ("Found ".. compared .." special ores")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement