Advertisement
mehmattski

branchmine

Jan 17th, 2013
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.74 KB | None | 0 0
  1. -- Dig a S shaped mine to the left or right based on input
  2. -- Checks for whether all slots are full, dumps everything in ender chest in slot 1.
  3. -- Places torches reasonably when they are placed in slot 16.
  4.  
  5. function turnAround()
  6.     for i=1,2 do
  7.        turtle.turnLeft()
  8.     end
  9. end
  10.  
  11. function smartForward()
  12.     --Dig a 2 high, 1 wide tunnel; gravel and sand friendly.
  13.     while not turtle.forward() do
  14.         turtle.dig()
  15.     end
  16.     while turtle.detectUp() do
  17.         turtle.digUp()
  18.         sleep(0.5)    
  19.     end
  20. end
  21.  
  22. function snakeRight()
  23.     -- Make a right turn in the snake.
  24.     turtle.turnRight()
  25.     for i=1,3 do
  26.         smartForward()
  27.     end
  28.     torchPlace()
  29.     turtle.turnRight()
  30. end
  31.  
  32. function snakeLeft()
  33.     -- Make a left turn in the snake.
  34.     turtle.turnLeft()
  35.     for i=1,3 do
  36.         smartForward()
  37.     end
  38.     torchPlace()
  39.     turtle.turnLeft()
  40. end
  41.  
  42. function enderDump()
  43.     --Dump contents of slots 2 through 15 in an ender chest.
  44.     turnAround()
  45.     turtle.select(1)
  46.     turtle.place()
  47.     for i=2,15 do
  48.         turtle.select(i)
  49.         turtle.drop()
  50.     end
  51.     turtle.select(1)
  52.     turtle.dig()
  53.     turnAround()
  54. end
  55.  
  56. function torchPlace()
  57.     while turtle.getItemCount(16) == 0 do
  58.         print("Waiting for more torches!")
  59.         sleep(2)
  60.     end
  61.  
  62.     turtle.select(16)
  63.     turtle.turnRight()
  64.     sleep(0.25)
  65.     turtle.placeUp()
  66.     turtle.turnLeft()
  67.     turtle.select(1)
  68. end
  69.  
  70.  
  71. function isFull()
  72.     if turtle.getItemCount(15) < 64 then
  73.         return false
  74.      end
  75.     return true
  76. end
  77.  
  78. local args = {...}
  79. if table.getn(args) < 1 then
  80.     print("Usage: snakemine numBranch branchLength direction")
  81.     print("numBranch is the number of loops to make.")
  82.     print("branchLength is the length of the side branch")
  83.     print("direction is left or right")
  84.     print("Make sure torches are in slot 16!")
  85.     print("Make sure Enderchest is in slot 1!")
  86.     return
  87. end
  88. local numBranch = tonumber(args[1])
  89. local branchLength = tonumber(args[2])
  90. local direction = args[3]
  91.  
  92. if direction == "left" then
  93.     print("left-handed!")
  94. elseif direction == "right" then
  95.     print("right-handed!")
  96. else
  97.     print("Direction must be left or right!")
  98.     return
  99. end
  100.  
  101. local sincetorch = 0
  102.  
  103. for a=1,numBranch do
  104.     for b=1,branchLength do
  105.         smartForward()
  106.         sincetorch = sincetorch + 1
  107.         if sincetorch == 10 then
  108.            
  109.             torchPlace()
  110.             sincetorch = 0
  111.         end
  112.        
  113.         if isFull() then
  114.             enderDump()
  115.         end
  116.     end
  117.     if direction == "left" then
  118.         snakeRight()
  119.     else
  120.         snakeLeft()
  121.     end
  122.  
  123.     for b=1,branchLength do
  124.         smartForward()
  125.         sincetorch = sincetorch + 1
  126.        
  127.         if sincetorch == 10 then
  128.             torchPlace()
  129.             sincetorch = 0
  130.         end
  131.        
  132.         if isFull() then
  133.             enderDump()
  134.         end
  135.    
  136.     end
  137.     if direction == "left" then
  138.         snakeLeft()
  139.     else
  140.         snakeRight()
  141.     end
  142. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement