RJ-Bradach

Full Inventory Checker API

Jun 24th, 2021 (edited)
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.03 KB | None | 0 0
  1. -- Full Inventory Checker API --------------------------------------------------------------------------------------------------------
  2. -- API to check if a turtle a has full inventory or not
  3. -- This API contains two methods for checking a turtles inventory
  4. -- hasFullInventory returns true if all inventory slots have at least one item in them, false otherwise
  5. -- hasMaxInventory returns true if all inventory slots have 64 items in them.
  6. -- Unfortunately for now, there is no method I can find with CC tweaked that can check if an item stacks to 64 or not.
  7. -- If that method becomes a thing I will update this API to include checks for whether items have reached their max stack size
  8.  
  9. function hasFullInventory()
  10.     for i = 1, 16 do
  11.         if turtle.getItemDetail(i) == nil then
  12.             return false
  13.         end
  14.     end
  15.     return true
  16. end
  17.  
  18. function hasMaxInventory()
  19.     for i = 1, 16 do
  20.         local item = turtle.getItemDetail(i)
  21.         if (item.count ~= 64) then
  22.             return false
  23.         end
  24.     end
  25.     return true
  26. end
Add Comment
Please, Sign In to add comment