the-vindex

Thaumcraft 4 Mana bean harvester

Jan 14th, 2014
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.02 KB | None | 0 0
  1. local columnHeight = 100
  2. local currentSlot = 1
  3. local currentDirection = "up"
  4. local cycleCount = 1
  5. local stockHandle = nil
  6. local turnDirection = "right"
  7. local dropMode = nil
  8.  
  9. function loopSlot()
  10.    local nextSlot = nil
  11.    if currentSlot<16 then
  12.       nextSlot = currentSlot+1
  13.    else
  14.       nextSlot = 1
  15.    end
  16.    selectSlot(nextSlot)
  17. end
  18.  
  19. function place()
  20.    local limit=16
  21.    while turtle.getItemCount(currentSlot) == 0 and limit>0 do
  22.       loopSlot()
  23.       limit = limit - 1
  24.    end
  25.    if limit == 0 then
  26.       print("Place limit reached - inventory empty")
  27.    end
  28.    print ("Items in current slot: ", turtle.getItemCount(currentSlot))
  29.    print ("Current slot: ", currentSlot)
  30.    return turtle.place()
  31. end
  32.  
  33. function dig()
  34.    if turnDirection == "none" and currentDirection == "down" then
  35.       --do nothing
  36.    else
  37.       turtle.dig()
  38.    end
  39. end
  40.  
  41. function turtleUp()
  42.    local limit = 5
  43.    for i = 1,5 do
  44.       if turtle.up() then
  45.          return true
  46.       else
  47.          sleep(0.3)
  48.       end
  49.    end
  50.    return false
  51. end
  52.  
  53. function turtleDown()
  54.    local limit = 5
  55.    for i = 1,5 do
  56.       if turtle.down() then
  57.          return true
  58.       else
  59.          sleep(0.3)
  60.       end
  61.    end
  62.    return false
  63. end
  64.  
  65. function move()
  66.    if currentDirection == "up" then
  67.       return turtleUp()
  68.    elseif currentDirection == "down" then
  69.       return turtleDown()
  70.    else
  71.       print("Unknown direction: ", currentDirection)
  72.       exit()
  73.    end
  74. end
  75.  
  76. function revertDirection()
  77.    if currentDirection == "up" then
  78.       currentDirection = "down"
  79.    elseif currentDirection == "down" then
  80.       currentDirection = "up"
  81.    else
  82.       print("Unknown current direction: ", currentDirection)
  83.       exit()
  84.    end
  85. end
  86.  
  87. function selectSlot(slotNumber)
  88.    turtle.select(slotNumber)
  89.    currentSlot = slotNumber  
  90. end
  91.  
  92. function oneDirection()
  93.    selectSlot(1)
  94.    
  95.    local movesInOneDir = 0
  96.    while movesInOneDir < columnHeight do
  97.       dig()
  98.       if not place() and currentDirection == "up" then
  99.          print("Cannot place, breaking")
  100.          break
  101.       end
  102.       if not move() then
  103.          print("Can't go current direction, reverting")
  104.          break
  105.       end
  106.       movesInOneDir = movesInOneDir + 1
  107.       if dropMode == "continousDrop" then
  108.          selectSlot(2)
  109.          turtle.dropDown()
  110.          selectSlot(1)
  111.          turtle.dropDown()
  112.       end
  113.    end
  114. end
  115.  
  116. function turn()
  117.     if turnDirection == "right" then
  118.         turtle.turnRight()
  119.     elseif turnDirection == "left" then
  120.         turtle.turnLeft()
  121.     elseif turnDirection == "around" then
  122.         turtle.turnLeft()
  123.         turtle.turnLeft()
  124.     elseif turnDirection == "none" then
  125.         print("Turn direction = 'none', not turning")
  126.     else
  127.         print("Incorrect turn direction, turning right")
  128.         turtle.turnRight()
  129.     end
  130. end
  131.  
  132. function goUpAndDown()
  133.    
  134.     if turtle.getFuelLevel() < 300 then
  135.        print("Error - low on fuel ", turtle.getFuelLevel())
  136.        exit()
  137.     end
  138.    
  139.     resupplyBeans()
  140.     oneDirection()
  141.     revertDirection()
  142.     turn()
  143.  
  144.     oneDirection()
  145.     revertDirection()
  146.     turn()
  147. end
  148.  
  149. function resupplyBeans()    
  150.     -- refilling from filing cabinet below us
  151.     for i=1,16 do
  152.        selectSlot(i)
  153.        if stockHandle == "resupply" then
  154.           turtle.suckDown()
  155.        elseif stockHandle == "dump" then
  156.         -- we expect vacuum hopper to grab mana beans we drop
  157.           turtle.drop()
  158.           --turtle.dropDown()
  159.        elseif not stockHandle then
  160.           -- doing nothing
  161.        else
  162.           print("Wrong resupply command")
  163.           exit()
  164.        end
  165.     end
  166. end
  167.  
  168. local args = {...}
  169. if args[1] and tonumber(args[1]) then
  170.    cycleCount = tonumber(args[1])
  171. end
  172.  
  173. if args[2] == "resupply" then
  174.    stockHandle = "resupply"
  175. elseif args[2] == "dump" then
  176.    stockHandle = "dump"
  177. else
  178.    print("No resupply command")
  179. end
  180.  
  181. if args[3] == "left" or args[3] == "right" or args[3] == "around" or args[3] == "none" then
  182.    turnDirection = args[3]
  183. else
  184.    print("Using default turn direction")
  185. end
  186.  
  187. if args[4] == "continousDrop" then
  188.    dropMode = args[4]
  189. else
  190.    print("No special drop mode")
  191. end
  192.  
  193. for cycle = 1,cycleCount do
  194.    goUpAndDown()
  195. end
Advertisement
Add Comment
Please, Sign In to add comment