Advertisement
OldDragon2A

Cap

Jan 6th, 2013
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.86 KB | None | 0 0
  1. -- cap - caps a square hole
  2. -- Designed for covering the holes from a quarry
  3.  
  4. -- Place on the bottom level you want to cap in a corner.
  5.  
  6. local drop_slots       = { 1, 15 }
  7. local fuel_slot        = 16
  8. local refuel_level     = 0
  9.  
  10. function getEmptySlots()
  11.   numslots = 0
  12.   for i = drop_slots[1], drop_slots[2] do
  13.     if turtle.getItemCount(i) == 0 then
  14.       numslots = numslots + 1
  15.     end
  16.   end
  17.   return numslots
  18. end
  19. function isDropSlotsEmpty()
  20.   return getEmptySlots() == drop_slots[2] - drop_slots[1]
  21. end
  22.  
  23. function refuel()
  24.   while turtle.getFuelLevel() == 0 do
  25.     if turtle.getItemCount(fuel_slot) ~= 0 then
  26.       turtle.select(fuel_slot)
  27.       turtle.refuel(1)
  28.     else
  29.       sleep(1)
  30.     end
  31.   end
  32.   turtle.select(drop_slots[1])
  33. end
  34.  
  35. function cap(levels)
  36.   for i = 1,levels do
  37.     local count
  38.    
  39.     turtle.turnLeft()
  40.     count = turtle.detect() and 0 or 1
  41.     turtle.turnRight()
  42.     refuel()
  43.     turtle.up()
  44.    
  45.     while true do
  46.       if (turtle.detect() or turtle.detectDown()) then break end
  47.      
  48.       while not turtle.detect() and not turtle.detectDown() do
  49.         while isDropSlotsEmpty() do sleep(1000) end
  50.         turtle.placeDown()
  51.         turtle.attack()
  52.         refuel()
  53.         turtle.forward()
  54.       end
  55.      
  56.       if (turtle.detectDown()) then
  57.         refuel()
  58.         turtle.back()
  59.       else
  60.         while isDropSlotsEmpty() do sleep(1000) end
  61.         turtle.placeDown()
  62.       end
  63.      
  64.       if (count%2 == 0) then turtle.turnRight() else turtle.turnLeft() end
  65.       if (turtle.detect()) then break end
  66.       turtle.attack()
  67.       refuel()
  68.       turtle.forward()
  69.       if (count%2 == 0) then turtle.turnRight() else turtle.turnLeft() end
  70.       count = count + 1
  71.     end
  72.   end
  73. end
  74.  
  75. local tArgs = { ... }
  76. if #tArgs == 1 then
  77.   cap(tonumber(tArgs[1]))
  78. else
  79.   print("usage: cap levels")
  80.   return
  81. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement