kd8lvt

Mining Turtle EXPERIMENTAL!

Jan 28th, 2016
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.93 KB | None | 0 0
  1. --KdMine by Kd8lvt--
  2. --Made for Lokbatch, and personal use--
  3. --Type 'copyright' as the length to see an abbreviated version of the Mozilla Public License.--
  4. function dump()
  5.   for i = 1,16 do
  6.     itemid = turtle.getItemDetal(i)
  7.     if itemid == "minecraft:cobblestone" then
  8.       turtle.select(i)
  9.       turtle.drop()
  10.     elseif itemid == "minecraft:netherrack" then
  11.       turtle.select(i)
  12.       turtle.drop()
  13.     else
  14.       --Do nothing, we want to keep this item!
  15.     end
  16.   end
  17.   turtle.select(1)
  18. end
  19. function dig(direction)
  20.   if direction == "up" then
  21.     turtle.digUp()
  22.   elseif direction == "down" then
  23.     turtle.digDown()
  24.   else
  25.     turtle.dig()
  26.   end
  27. end
  28. function turn(direction, times)
  29.   if times then
  30.     while times > 0 do
  31.       if direction == "left" then
  32.         turtle.turnLeft()
  33.       elseif direction == "right" then
  34.         turtle.turnRight()
  35.       end
  36.       times = times - 1
  37.     end
  38.   else
  39.     if direction == "left" then
  40.       turtle.turnLeft()
  41.     elseif direction == "right" then
  42.       turtle.turnRight()
  43.     end
  44.   end
  45. end
  46. function mine(length)
  47.   turn("left",2)
  48.   dump()
  49.   turn("left",2)
  50.   dig()
  51.   turtle.forward()
  52.   dig("up")
  53.   turtle.up()
  54.   if lastTorch then
  55.     if length == lastTorch - 4 then
  56.       torch()
  57.     end
  58.   else
  59.     torch()
  60.     lastTorch = length
  61.   end
  62.   dig("up")
  63.   turn("left")
  64.   dig()
  65.   turtle.forward()
  66.   turn("right",2)
  67.   dig("up")
  68.   dig("down")
  69.   turtle.forward()
  70.   dig()
  71.   turtle.forward()
  72.   dig("up")
  73.   dig("down")
  74.   turn("left",2)
  75.   turtle.forward()
  76.   turtle.down()
  77.   turn("right")
  78. end
  79. function checkFuel()
  80.   local fuel = turtle.getFuelLevel()
  81.   if fuel < 50 then
  82.     for i = 1,16 do
  83.       itemid, count = turtle.getItemDetail(i)
  84.       if itemid == "minecraft:coal" then
  85.         turtle.select(i)
  86.         if count > 31 then
  87.           turtle.refuel(count/2)
  88.         end
  89.       elseif itemid == "minecraft:charcoal" then
  90.         turtle.select(i)
  91.         if count > 31 then
  92.           turtle.refuel(count/2)
  93.         end
  94.       elseif itemid == "minecraft:lava_bucket" then
  95.         turtle.select(i)
  96.         turtle.refuel()
  97.       elseif i == 16 and turtle.getFuelLevel == fuel then
  98.         error("I ran out of fuel! Please refuel me :( I can take Coal, Charcoal, or Lava.")
  99.       end
  100.     end
  101.   end
  102. end
  103. function torch()
  104.   for i = 1,16 do
  105.     itemid = turtle.getItemDetail(i)
  106.     if itemid == "minecraft:torch" then
  107.       turtle.select(i)
  108.       turtle.placeDown()
  109.     end
  110.   end
  111. end
  112. function main()
  113.   textutils.slowPrint("How far to mine? [Or, type 'license' to see the license]")
  114.   input = io.read()
  115.   if input == "license" then
  116.     print("This work is protected under the Mozilla Public License 2.0. here is an abbreviated version: ")
  117.     print("If you edit and re-publish this work, you MUST: ")
  118.     print("    1. Disclose your source (Make it open-source)")
  119.     print("    2. License and copyright notice (Just don't change this part and you'll be fine)")
  120.     print("You are NOT allowed to do these things: ")
  121.     print("    1. Hold kd8lvt liable for any damages done to your game / computer (It shouldn't anyways)")
  122.     print("    2. Use a trademark (This does NOT grant you any rights in the trademarks or other rights of contributors.)")
  123.     print("You ARE allowed to do these things:  ")
  124.     print("    1. Use this for commercial purposes (I'd prefer if you didn't though, Ad.fly is ok.)")
  125.     print("    2. Redistribute")
  126.     print("    3. Modify")
  127.     print("    4. Use Patents")
  128.     print("    5. Use and modify without distributing (no liability to kd8lvt)")
  129.     print("    6. Sublicense (I don't have one)")
  130.     error("Displayed Abbreviated Mozilla Public License 2.0")
  131.   else
  132.     if tonumber(input) ~= nil then
  133.       length = tonumber(input)
  134.       while length > 0 do
  135.         mine(length)
  136.         length = length - 1
  137.       end
  138.     else
  139.       error("You must input a number, or 'license'")
  140.     end
  141.   end
  142. end
  143. while true do
  144.   main()
  145. end
Add Comment
Please, Sign In to add comment