Advertisement
sanderronde

place.lua

Jan 28th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.22 KB | None | 0 0
  1. local tArgs = { ... }
  2. if #tArgs ~= 1 then
  3.     print( "Usage: place <cycle_amount>" )
  4.     return
  5. end
  6.  
  7. local cycle_len = tonumber(tArgs[1])
  8.  
  9. local function refuel(amount)
  10.     local fuelLevel = turtle.getFuelLevel()
  11.     if fuelLevel == "unlimited" then
  12.         return true
  13.     end
  14.    
  15.     if turtle.getFuelLevel() < amount then
  16.         local fueled = false
  17.         turtle.select(16)
  18.         if turtle.getItemCount(16) > 0 then
  19.             turtle.select(16)
  20.             if turtle.refuel(1) then
  21.                 while turtle.getItemCount(16) > 0 and turtle.getFuelLevel() < amount do
  22.                     turtle.refuel(1)
  23.                 end
  24.                 if turtle.getFuelLevel() >= amount then
  25.                     turtle.select(1)
  26.                     return true
  27.                 end
  28.             end
  29.         end
  30.         turtle.select(1)
  31.         return false
  32.     end
  33.    
  34.     return true
  35. end
  36.  
  37. local function wait_for_items()
  38.     while turtle.getItemCount() == 0 do
  39.         os.pullEvent( "turtle_inventory")
  40.     end
  41. end
  42.  
  43. local function assert_items()
  44.     if turtle.getItemCount() == 0 then
  45.         print("No more items")
  46.         wait_for_items()
  47.     end
  48. end
  49.  
  50. local function cycle()
  51.     for n=1,cycle_len do
  52.         turtle.select(n)
  53.         assert_items()
  54.         turtle.place()
  55.  
  56.         refuel(1)
  57.         turtle.back()
  58.     end
  59. end
  60.  
  61. local function main()
  62.     while true do
  63.         cycle()
  64.     end
  65. end
  66.  
  67. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement