Lion_Kor

Miner 3x3

Apr 7th, 2018
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.35 KB | None | 0 0
  1. local args = { ... }
  2. make_safe = 0
  3. l = 0
  4. if #args == 0 then
  5.     print("*Usage: mine <length> <make_safe(default:0)>")
  6.     exit()
  7. else
  8.     length = math.abs(tonumber(args[1]))
  9.     if not args[2] == nil then
  10.         make_safe = math.abs(tonumber(args[2]))
  11.     end
  12.     print("length: "..length)
  13. end
  14.  
  15. if os.getComputerLabel() == nil then
  16.     oldName = nil
  17. else
  18.     oldName = os.getComputerLabel()
  19. end
  20.  
  21. os.setComputerLabel("miner_"..math.random(9999999))
  22. print("temporarily changed label to "..os.getComputerLabel())
  23.  
  24. function select(name)
  25.     for i = 16, 1, -1 do
  26.         turtle.select(i)
  27.         local item = turtle.getItemDetail()
  28.         if turtle.getItemCount() > 0 then
  29.             print(item.name)
  30.             if item.name == name then
  31.                 turtle.select(i)
  32.                 return true
  33.             end
  34.         end
  35.     end
  36.     turtle.select(1)
  37.     return false
  38. end
  39.  
  40. function checkSpace()
  41.     slotsFull = 0
  42.     for i = 16, 1, -1 do
  43.         if turtle.getItemCount(i) > 0 then
  44.             slotsFull = slotsFull + 1
  45.         end
  46.     end
  47.     if slotsFull == 16 then
  48.         if select("minecraft:chest") then
  49.             turtle.turnRight()
  50.             turtle.down()
  51.             turtle.place()
  52.             for i = 16, 1, -1 do
  53.                 turtle.select(i)
  54.                 if turtle.getItemCount() > 0 then
  55.                     local item = turtle.getItemDetail(i)
  56.                     if item.name == "minecraft:torch" or item.name == "minecraft:chest" then
  57.                     else
  58.                         turtle.drop()
  59.                     end
  60.                 end
  61.             end
  62.             turtle.select(1)
  63.             turtle.up()
  64.             turtle.turnLeft()
  65.         end
  66.     end
  67. end
  68.  
  69. function throwAwayCobble()
  70.     cobbles = 0
  71.     for i = 16, 1, -1 do
  72.         if turtle.getItemCount(i) > 0 then
  73.             item = turtle.getItemDetail(i)
  74.             if item.name == "minecraft:cobblestone" then
  75.                 cobbles = cobbles + 1
  76.             end
  77.         end
  78.     end
  79.     if cobbles > 1 then
  80.         for i = 1, cobbles - 1, 1 do
  81.             select("minecraft:cobblestone")
  82.             turtle.dropDown()
  83.         end
  84.     end
  85. end
  86.  
  87. function fuel()
  88.     if turtle.getFuelLevel() < 12 then
  89.         for i = 16, 1, -1 do
  90.             turtle.select(i)
  91.             if turtle.getItemCount() > 0 then
  92.                 local item = turtle.getItemDetail(i)
  93.                 if item.name == "minecraft:torch" or item.name == "minecraft:chest" then
  94.                 else
  95.                     turtle.refuel()
  96.                 end
  97.             end
  98.         end
  99.         turtle.select(1)
  100.     end
  101. end
  102.  
  103. function makeSafe()
  104.     select("minecraft:cobblestone")
  105.     turtle.down()
  106.     local success, block = turtle.inspectDown()
  107.     if success then
  108.         if not block.name == "minecraft:stone" and not block.name == "minecraft:dirt" and not block.name == "minecraft:cobblestone" then
  109.             turtle.digDown()
  110.             turtle.placeDown()
  111.         end
  112.     end
  113.     turtle.up()
  114. end
  115.  
  116. function make3by3()
  117.     turtle.dig()
  118.     turtle.forward()
  119.     turtle.digUp()
  120.     turtle.digDown()
  121.     turtle.turnRight()
  122.     turtle.dig()
  123.     turtle.forward()
  124.     turtle.digUp()
  125.     turtle.digDown()
  126.     turtle.back()
  127.     turtle.turnLeft()
  128.     turtle.turnLeft()
  129.     turtle.dig()
  130.     turtle.forward()
  131.     turtle.digUp()
  132.     turtle.digDown()
  133.     turtle.back()
  134.     turtle.turnRight()
  135. end
  136.  
  137. torchDistance = 7
  138.  
  139.  
  140.  
  141. while l <= length do
  142.     l = l + 1
  143.     fuel()
  144.     make3by3()
  145.     if make_safe == 1 then
  146.         makeSafe()
  147.     end
  148.     if torchDistance == 7 then
  149.         if select("minecraft:torch") then
  150.             turtle.turnRight()
  151.             turtle.place()
  152.             turtle.turnLeft()
  153.             turtle.select(1)
  154.         else
  155.             print("no torches found")
  156.         end
  157.         torchDistance = 0
  158.     end
  159.     torchDistance = torchDistance + 1
  160.     turtle.select(1)
  161.     checkSpace()
  162.     turtle.select(1)
  163.     throwAwayCobble()
  164.     turtle.select(1)
  165. end
  166.  
  167. if not oldName == nil then
  168.     os.setComputerLabel(oldName)
  169. else
  170.     os.setComputerLabel("turtle_"..math.random(9999999))
  171. end
Advertisement
Add Comment
Please, Sign In to add comment