Advertisement
WatermellonLOL

Untitled

Apr 27th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.30 KB | None | 0 0
  1. running = true
  2. distance = 1
  3.  
  4. local function dropCobblestone()
  5.   lastItem = turtle.getItemCount(16)
  6.  
  7.   if lastItem > 0 then
  8.     dropped = 0
  9.     for i=16,3,-1 do
  10.       turtle.select(i)
  11.       amount = turtle.getItemCount()
  12.    
  13.       if amount > 0 then
  14.         data = turtle.getItemDetail()
  15.      
  16.         if data.name == "minecraft:cobblestone" then
  17.           turtle.drop()
  18.           dropped = dropped + amount
  19.         end
  20.       end
  21.    
  22.     end
  23.  
  24.     if dropped > 128 then
  25.       print("Dropped x" .. dropped .. " cobblestone.")
  26.     end  
  27.   end
  28.  
  29. end
  30.  
  31. local function alternativeFuel()
  32.   print("No main fuel, trying alternative.")
  33.  
  34.   for i=16,3,-1 do
  35.     turtle.select(i)
  36.  
  37.     amount = turtle.getItemCount(i)
  38.  
  39.     if amount > 0 then
  40.       data = turtle.getItemDetail(i)
  41.       if data.name == "minecraft:coal" then
  42.         turtle.refuel()
  43.         print("Found coal alternative fuel.")
  44.       end
  45.  
  46.     end
  47.  
  48.   end
  49.  
  50.   if turtle.getFuelLevel() == 0 then
  51.     print("No alternatives found, quitting.")
  52.     running = false
  53.   end
  54. end
  55.  
  56. local function depositItems()
  57.   if turtle.getItemCount(16) > 0 then
  58.     turtle.turnLeft()
  59.     turtle.turnLeft()
  60.    
  61.     for i=turtle.getFuelLevel(),0,-1 do
  62.       turtle.forward()
  63.      
  64.       success, data = turtle.inspect()
  65.      
  66.       if success then
  67.         if data.name == "minecraft:chest" then
  68.           for o=16,3,-1 do
  69.             turtle.select(o)
  70.             turtle.drop()
  71.           end
  72.           turtle.turnLeft()
  73.           turtle.turnLeft()
  74.         else
  75.           turtle.dig()
  76.         end
  77.       end
  78.      
  79.     end
  80.   end
  81.  
  82.   if turtle.getFuelLevel() <= distance then
  83.     turtle.turnLeft()
  84.     turtle.turnLeft()
  85.    
  86.     for i=turtle.getFuelLevel(),0,-1 do
  87.       turtle.forward()
  88.      
  89.       success, data = turtle.inspect()
  90.      
  91.       if success then
  92.         if data.name == "minecraft:chest" then
  93.           for o=16,3,-1 do
  94.             turtle.select(o)
  95.             turtle.drop()
  96.           end
  97.           turtle.turnLeft()
  98.           turtle.turnLeft()
  99.         else
  100.           turtle.dig()
  101.         end
  102.       end
  103.      
  104.     end
  105.   end
  106. end
  107.  
  108. local function fuel()
  109.   if turtle.getFuelLevel() == 0 then
  110.     amount = turtle.getItemCount(1)
  111.    
  112.     if amount > 0 then
  113.       data = turtle.getItemDetail()
  114.    
  115.       if data.name == "minecraft:bucket" then
  116.         alternativeFuel()
  117.       end
  118.      
  119.       if data.name == "minecraft:lava_bucket" then
  120.         turtle.refuel()
  121.         print("Refuelling.")
  122.       else
  123.         alternativeFuel()
  124.       end
  125.      
  126.     end
  127.    
  128.   end
  129.  
  130.   turtle.select(1)
  131.  
  132. end
  133.  
  134. local function checkSide()
  135.  
  136.   turtle.turnLeft()
  137.  
  138.   success_left, data_left = turtle.inspect()
  139.  
  140.   if success_left then
  141.     if data_left.name == "minecraft:gold_ore" then
  142.       turtle.dig()
  143.       turtle.select(2)
  144.       turtle.dig()
  145.       turtle.select(1)
  146.     end
  147.    
  148.     if data_left.name == "minecraft:diamond_ore" then
  149.       turtle.dig()
  150.       turtle.select(2)
  151.       turtle.dig()
  152.       turtle.select(1)
  153.     end
  154.   end
  155.  
  156.   turtle.turnRight()
  157.   turtle.turnRight()
  158.  
  159.   success_right, data_right = turtle.inspect()
  160.  
  161.   if success_right then
  162.     if data_right.name == "minecraft:gold_ore" then
  163.       turtle.digRight()
  164.       turtle.select(2)
  165.       turtle.placeRight()
  166.       turtle.select(1)
  167.     end
  168.    
  169.     if data_right.name == "minecraft:diamond_ore" then
  170.       turtle.digRight()
  171.       turtle.select(2)
  172.       turtle.placeRight()
  173.       turtle.select(1)
  174.     end
  175.   end
  176.  
  177.   turtle.turnLeft()
  178.  
  179. end
  180.  
  181. local function mine()
  182.  
  183.   turtle.select(1)
  184.   fuel()
  185.   -- checkSide()
  186.  
  187.   turtle.dig()
  188.   turtle.forward()
  189.     distance = distance + 1
  190.   turtle.digUp()
  191.  
  192.   dropCobblestone()
  193.  
  194.   success, data = turtle.inspectDown()
  195.  
  196.   if not success then
  197.   turtle.select(2)
  198.   turtle.placeDown()
  199.   turtle.select(1)
  200.   end
  201.  
  202.   if success then
  203.     if data.name == "minecraft:flowing_lava" then
  204.       turtle.select(1)
  205.       data_item = turtle.getItemDetail(1)
  206.      
  207.       if data_item.name == "minecraft:bucket" then
  208.         turtle.place()
  209.         data = turtle.getItemDetail()
  210.         if data.name == "minecraft:lava_bucket" then
  211.           print("Got more fuel!")
  212.           if turtle.getFuelLevel() < 10000 then
  213.             turtle.refuel()
  214.             print(turtle.getFuelLevel())
  215.           else
  216.             print("Turtle is above 10,000 fuel units.")
  217.           end
  218.         end
  219.       else
  220.         print("Lava found, but bucket is full.")
  221.       end
  222.      
  223.     end
  224.   end
  225.  
  226. end
  227.  
  228. local function tick()
  229.   if distance > 1 then
  230.     depositItems()
  231.   end
  232.   mine()
  233. end
  234.  
  235. while running do
  236.   tick()
  237.  
  238.   if not running then
  239.     turtle.select(1)
  240.     print("The mining script has terminated.")
  241.   end
  242. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement