Advertisement
Guest User

mining

a guest
Jul 31st, 2014
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.37 KB | None | 0 0
  1. function select(info)
  2.     if info == "ladder" then
  3.         turtle.select(1)
  4.     elseif info == "torch" then
  5.         turtle.select(2)
  6.    elseif info == "cobblestone" then
  7.         turtle.select(4)
  8.     end
  9. end
  10. function place(direction)
  11.     if direction == "front" then
  12.         turtle.place()
  13.     elseif direction == "around" then
  14.         turn("around")
  15.         turtle.place()
  16.     elseif direction == "left" then
  17.         turn("left")
  18.         turtle.place()
  19.     elseif direction == "right" then
  20.         turn("right")
  21.         turtle.place()
  22.     elseif direction == "up" then
  23.         turtle.placeUp()
  24.     elseif direction == "down" then
  25.         turtle.placeDown()
  26.     end
  27.     reStock("cobblestone")
  28. end
  29.  
  30. function reStock(info)
  31.     note = ""
  32.     if info == "torch" then
  33.         select("torch")
  34.         if turtle.compareTo(3) then
  35.             note = turtle.getItemSpace(turtle.getSelectedSlot())
  36.             turtle.select(3)
  37.             turtle.transferTo(2,64-note)
  38.         end
  39.     elseif info == "cobblestone" then
  40.         index = 4
  41.         fill = false
  42.         while not fill or index <= 16 do
  43.             if turtle.compare(index) then
  44.                 note = turtle.getItemCount(turtle.getSelectedSlot())
  45.                 turtle.select(index)
  46.                 turtle.transferTo(4,64-note)
  47.                 select("cobblestone")
  48.             end
  49.             if turtle.getItemSpace(turtle.getSelectedSlot()) == 64 then
  50.                 fill = true
  51.             end
  52.             i = i + 1
  53.         end
  54.                            
  55.     end
  56. end
  57.      
  58. function digging(direction)
  59.     if direction == "up" then
  60.         turtle.digUp()
  61.     elseif direction == "down" then
  62.         turtle.digDown()
  63.     elseif direction == "left" then
  64.         turn("left")  
  65.         turtle.dig()
  66.     elseif direction == "around" then
  67.         turn("around")
  68.         turtle.dig()
  69.     elseif direction == "right" then
  70.         turn("right")
  71.         turtle.dig()
  72.     elseif direction == "front" then
  73.         turtle.dig()
  74.     end
  75. end            
  76.          
  77. function move(direction)
  78.     if direction == "down" then
  79.         turtle.down()
  80.     elseif direction == "up" then
  81.         turtle.up()
  82.     elseif direction == "forward" then
  83.         turtle.forward()
  84.     elseif direction == "around" then
  85.         turn("around")
  86.         turtle.forward()
  87.     elseif direction == "right" then
  88.         turn("right")
  89.         turtle.forward()
  90.     elseif direction == "left" then
  91.         turn("left")
  92.         turtle.forward()
  93.     end
  94.     refueling()
  95. end
  96.  
  97. function turn(direction)
  98.     if direction == "right" then
  99.         turtle.turnRight()
  100.     elseif direction == "left" then
  101.         turtle.turnLeft()
  102.         elseif direction == "around" then
  103.         for i = 1,2 do
  104.             turtle.turnRight()
  105.         end
  106.     end
  107. end
  108.      
  109. function torch()
  110.     select("torch")
  111.     turn("around")
  112.     turtle.place()
  113.     reStock("torch")
  114.     turn("around")
  115. end
  116.      
  117. function ladder()
  118.     select("ladder")
  119.     turtle.placeUp()
  120.     reStock("ladder")
  121. end
  122.      
  123. function refueling()
  124.     if turtle.getFuelLevel() < 100 then
  125.         for i = 1,16 do
  126.             turtle.select(i)
  127.             if turtle.refuel(0) then
  128.                 turtle.refuel(1)
  129.             end
  130.         end
  131.     end
  132. end
  133. function checkSides()
  134.     for i = 0,3 do
  135.         turtle.turnRight()
  136.         if i < 3 then
  137.             select("cobblestone")
  138.             place("front")
  139.         end
  140.   end  
  141. end
  142. function ladderProgram(currentLayer,desiredLayer)
  143.     print("Beginning the ladderProgram")
  144.     index = currentLayer
  145.     digging("front")
  146.     while index > desiredLayer do
  147.         digging("down")
  148.         checkSides()
  149.         move("down")
  150.         ladder()
  151.     end
  152. end
  153.  
  154.  
  155. function branch(length)
  156.     t = 8
  157.     for i = 1,2 do
  158.         for i = 0,length do
  159.             while turtle.detect() do
  160.                 digging("front")
  161.                 os.sleep(0.5)
  162.             end
  163.             if not turtle.detectDown() then
  164.                 select("cobblestone")
  165.                 place("down")
  166.             end
  167.             move("front")
  168.             t = t - 1
  169.             if t == 0 then
  170.                 torch()
  171.                 t = 8
  172.             end
  173.         end
  174.         turn("around")
  175.        
  176.         for i = 0,length do
  177.             move("front")
  178.         end
  179.     end
  180.     turn("right")
  181. end
  182.  
  183.  
  184. function nextBranch(length)
  185.     for i = 1,3 do
  186.         if i == 1 then
  187.             torch()
  188.         end
  189.         for j = 1,3 do
  190.             digging("front")
  191.             move("forward")
  192.             digging("up")
  193.             if not turtle.detectDown() then
  194.                 select("cobblestone")
  195.                 place("down")
  196.                 restock("cobblestone")
  197.             end
  198.         end
  199.         turn("left")
  200.         branch(length)
  201.     end
  202. end
  203.        
  204. function mining(length)
  205.     print("Beginning the miningProgram")      
  206.     while true do
  207.         nextBranch(length)
  208.     end
  209. end
  210.    
  211. function main()
  212.     print("write one of the things below for what action i should do")
  213.     print("ladder")
  214.     print("mining")
  215.     local input = read()
  216.     print("you entered: ", input)
  217.     if input == "ladder" then
  218.         print("what layer am I on?")
  219.         local input2 = tonumber(read())
  220.         print ("where should I go down to?")
  221.         local input3 = tonumber(read())
  222.         print("gimme: ", input2 - input3 - 1, " of Ladders")
  223.         local input4 = read()
  224.         print ("going down to layer: ", input3, "from: ", input2)
  225.         ladderProgram(input2,input3)
  226.     elseif input == "mining" then
  227.         print("what length should the branch be?")
  228.         local length = read()
  229.         print(" naow gimme torches on position 2 and 3!!")
  230.         print("some fuel like charcoal/coal or lava bucket would be nice")
  231.         print("waiting for the - go - command")
  232.         local input = read()
  233.         if input == "go" then
  234.             mining(length)
  235.         end
  236.     end
  237. end
  238. refueling()
  239. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement