Advertisement
joebodo

filler.lua

Jun 11th, 2014
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.43 KB | None | 0 0
  1. vos.loadAPI('core.api')
  2. vos.loadAPI('tl2.api')
  3.  
  4. TL2.setStatus = function(status)
  5.   turtle.status = status
  6. end
  7.  
  8. local function place(action)
  9.   while true do
  10.     local slot = TL2.selectSlotWithItems()
  11.     if not slot then
  12.       return false
  13.     end
  14.     if action.place() then
  15.       return true
  16.     end
  17.     if action.detect() then
  18.       return true
  19.     end
  20.     turtle.drop(1)
  21.   end
  22. end
  23.  
  24. local function escape()
  25.   TL2.setStatus('escaping')
  26.   local loc = TL2.getLocation('enderChest')
  27.   TL2.gotoZ(loc.z - 5)
  28.   while not TL2.gotoLocation('enderChest') do
  29.     sleep(1)
  30.   end
  31.   for i = 1, 10 do
  32.     if not turtle.detect() then
  33.       TL2.forward()
  34.     end
  35.   end
  36. end
  37.  
  38. local function fillHole()
  39.   TL2.turnAround()
  40.   place(TL2.actions.forward)
  41.   TL2.turnAround()
  42. end
  43.  
  44. local function fill()
  45.   TL2.setStatus('filling')
  46.   while true do
  47.     if TL2.getState().abort or
  48.        (turtle.getFuelLevel() < 500) then
  49.       break
  50.     end
  51.     while not turtle.detect() do
  52.       TL2.forward()
  53.       while not turtle.detectDown() do
  54.         TL2.down()
  55.       end
  56.     end
  57.     TL2.turnLeft()
  58.     while not turtle.detect() do
  59.       TL2.forward()
  60.       while not turtle.detectDown() do
  61.         TL2.down()
  62.       end
  63.     end
  64.     TL2.turnRight()
  65.     if turtle.detect() then
  66.       TL2.turnLeft()
  67.       while TL2.back() do
  68.         if not place(TL2.actions.forward) then
  69.           return
  70.         end
  71.         while not turtle.detectDown() do
  72.           TL2.down()
  73.         end
  74.       end
  75.       TL2.turnRight()
  76.       if not TL2.back() then
  77.         TL2.turnLeft()
  78.         if turtle.detect() then
  79.           TL2.up()
  80.           if not place(TL2.actions.down) then
  81.             return
  82.           end
  83.  
  84.           for i = 1, 4 do
  85.             if not turtle.detect() then
  86.               break
  87.             end
  88.             TL2.turnLeft()
  89.           end
  90.  
  91.           if turtle.detect() then
  92.             local ctr = 0
  93.             while turtle.detectUp() do
  94.               ctr = ctr + 1
  95.               if ctr > 10 then
  96.                 return
  97.               end
  98.               TL2.forward()
  99.               fillHole()
  100.               if not turtle.detect() then break end
  101.               TL2.turnLeft()
  102.               if not turtle.detect() then break end
  103.               TL2.forward()
  104.               fillHole()
  105.               if not turtle.detect() then break end
  106.               TL2.turnRight()
  107.               if not turtle.detect() then break end
  108.             end
  109.           end
  110.         end
  111.       elseif not place(TL2.actions.forward) then
  112.         return
  113.       end
  114.     end
  115.     if (TL2.getState().pt.z > -1) then
  116.       break
  117.     end
  118.   end
  119. end
  120.  
  121. function refill()
  122.   TL2.setStatus('refilling')
  123.   local loc = TL2.getLocation('enderChest')
  124.   if TL2.getState().pt.z < 0 then
  125.     TL2.gotoZ(loc.z - 5)
  126.   end
  127.   while not TL2.gotoLocation('enderChest') do
  128.     sleep(1)
  129.   end
  130.   if Peripheral.isPresent({ type = 'ender_chest' }) then
  131.     turtle.select(1)
  132.     for i = 1, 16 do
  133.       turtle.suckUp()
  134.     end
  135.     TL2.forward()
  136.     return true
  137.   end
  138. end
  139.  
  140. TL2.setPolicy(TL2.policies.digAttack)
  141. TL2.setDigPolicy(TL2.digPolicy.turtleSafe)
  142. TL2.saveLocation('enderChest')
  143.  
  144. print('model 501a')
  145. sleep(3)
  146.  
  147. if refill() then
  148.   while true do
  149.     fill()
  150.     if TL2.getState().abort or
  151.        turtle.getFuelLevel() < 500 or
  152.        TL2.getState().pt.z > -1 then
  153.       escape()
  154.       break
  155.     end
  156.     if not refill() then
  157.       escape()
  158.       break
  159.     end
  160.   end
  161. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement