Advertisement
Drorox

craftMirion

Dec 9th, 2023 (edited)
839
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.04 KB | None | 0 0
  1. local function takeFromInv(args)
  2.     args.count = args.count or 1
  3.     while true do
  4.         local success, reason = turtle.suck(args.count)
  5.         if success then
  6.             break
  7.         else
  8.             print(reason)
  9.             sleep(10)
  10.         end
  11.     end
  12. end
  13.  
  14. local function selectSlot(args)
  15.     args.slot = args.slot or 1
  16.     while true do
  17.         if turtle.select(args.slot) then
  18.             break
  19.         else
  20.             print(reason)
  21.             sleep(10)
  22.         end
  23.     end
  24. end
  25.  
  26. local function dropItems(args)
  27.     args.count = args.count or 1
  28.     while true do
  29.         if turtle.drop(args.count) then
  30.             break
  31.         end
  32.         sleep(5)
  33.     end
  34. end
  35.  
  36. local function move(args)
  37.     args.count = args.count or 1
  38.     for i=1,args.count do
  39.         while true do
  40.             success = false
  41.             if args.direction=="up" then
  42.                 success = turtle.up()
  43.             elseif args.direction=="down" then
  44.                 success = turtle.down()
  45.             elseif args.direction=="forward" then
  46.                 success = turtle.forward()
  47.             end
  48.             if success then
  49.                 break
  50.             end
  51.             sleep(5)
  52.         end
  53.     end
  54. end
  55.  
  56. local function moveAndTake(args)
  57.     args.itemcount = args.itemcount or 1
  58.     args.movecount = args.movecount or 1
  59.     for i=1,args.movecount do
  60.         move({direction=args.direction})
  61.         takeFromInv({count=args.itemcount})
  62.         selectSlot({slot = turtle.getSelectedSlot()+1})
  63.     end
  64. end
  65.  
  66.  
  67.  
  68. local function takeItems()
  69.    
  70.     moveAndTake({itemcount=1, direction="up", movecount=4})
  71.    
  72.     turtle.turnRight()
  73.     takeFromInv({count=1})
  74.     selectSlot({slot = turtle.getSelectedSlot()+1})
  75.     moveAndTake({itemcount=4, direction="down", movecount=3})
  76.     move({direction="down"})
  77. end
  78.  
  79. local function insertItems()
  80.     turtle.turnRight()
  81.     for i =1,5 do
  82.         selectSlot({slot = i})
  83.         dropItems({count=1})
  84.     end
  85.     turtle.turnRight()
  86.     for i =6,8 do
  87.         selectSlot({slot = i})
  88.         dropItems({count=4})
  89.     end
  90.    
  91.     turtle.turnRight()
  92. end
  93.  
  94. local function fuelup()
  95.     if turtle.getFuelLevel()<10 then
  96.         local success, reason = turtle.suck(1)
  97.         while true do
  98.             if success then
  99.                 break
  100.             else
  101.                 print(reason)
  102.                 sleep(10)
  103.             end
  104.         end
  105.         turtle.refuel(1)
  106.     end
  107. end
  108.  
  109. while true do
  110.     selectSlot({})
  111.     fuelup()
  112.     takeItems()
  113.     insertItems()
  114. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement