Advertisement
Morthaden

me-stock-keeper

Aug 7th, 2022 (edited)
961
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.92 KB | None | 0 0
  1. me = peripheral.wrap("right")
  2. tracker = peripheral.wrap("top")
  3.  
  4. while true do
  5.     local list = tracker.list()
  6.     morthutils.clear()
  7.     for key, stack in pairs(list) do
  8.         local minQuant = stack.count
  9.         -- Check if we have enough in the ME system
  10.         local meStack = me.getItem({name = stack.name})
  11.         local craftingStack = {name = stack.name}
  12.         local isCraftable = (meStack and meStack.isCraftable) or me.isItemCraftable(craftingStack)
  13.         local storedQuant = (meStack and meStack.amount) or 0
  14.        
  15.         if storedQuant < minQuant and isCraftable and not me.isItemCrafting(craftingStack) then
  16.             local craftCount = minQuant - storedQuant
  17.             craftingStack.count = craftCount
  18.             craftingStack.nbt = stack.nbt
  19.             me.craftItem(craftingStack)
  20.             print("Crafting " .. craftCount .. " of " .. stack.name)
  21.         end
  22.     end
  23.     sleep(5)
  24. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement