Advertisement
k2green

compactor.lua

Aug 14th, 2023
806
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.97 KB | Gaming | 0 0
  1. local args = { ... }
  2.  
  3. local function turnTo(block)
  4.     while true do
  5.         if turtle.detect() then
  6.             local success, data = turtle.inspect()
  7.  
  8.             if data.name == block then
  9.                 break
  10.             end
  11.         end
  12.  
  13.         turtle.turnLeft()
  14.     end
  15. end
  16.  
  17. local function fillSlot(slot)
  18.     turtle.select(slot)
  19.  
  20.     while turtle.getItemCount() < 1 do
  21.         turtle.suck(1)
  22.     end
  23. end
  24.  
  25. local function craftLoopIteration()
  26.     turnTo(args[1])
  27.  
  28.     for y = 1, 4, 1 do
  29.         for x = 1, 4, 1 do
  30.             if x ~= 4 and y ~= 4 then
  31.                 local slot = (y - 1) * 4 + x
  32.                 fillSlot(slot)
  33.             end
  34.         end
  35.     end
  36.  
  37.     turtle.select(1)
  38.     turtle.craft()
  39.  
  40.     turnTo(args[2])
  41.     turtle.drop()
  42. end
  43.  
  44. if type(args[1]) ~= "string" or type(args[2]) ~= "string" then
  45.     print("Usage: compactor <source_invenory> <output_inventory>")
  46. else
  47.     while true do
  48.         craftLoopIteration()
  49.     end
  50. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement