Advertisement
ItsNoah

tutils.lua

May 24th, 2023 (edited)
1,019
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.07 KB | None | 0 0
  1. local tutils = {}
  2.  
  3. function tutils.findItem(name)
  4.     for i = 1, 16 do
  5.         local item = turtle.getItemDetail(i)
  6.         if item and item.name == name then
  7.             return i
  8.         end
  9.     end
  10. end
  11.  
  12. function tutils.selectItem(name)
  13.     for i = 1, 16 do
  14.         local item = turtle.getItemDetail(i)
  15.         if item and item.name == name then
  16.             turtle.select(i)
  17.         end
  18.     end
  19. end
  20.  
  21. function tutils.selectEmptySlot()
  22.     for i = 1, 16 do
  23.         if turtle.getItemCount(i) == 0 then
  24.             turtle.select(i)
  25.             return true
  26.         end
  27.     end
  28.     return false
  29. end
  30.  
  31. function tutils.selectFullSlot()
  32.     for i = 1, 16 do
  33.         if turtle.getItemCount(i) > 0 then
  34.             turtle.select(i)
  35.             return true
  36.         end
  37.     end
  38.     return false
  39. end
  40.  
  41. function tutils.getItemCount(name)
  42.     local count = 0
  43.     for i = 1, 16 do
  44.         local item = turtle.getItemDetail(i)
  45.         if item and item.name == name then
  46.             count = count + item.count
  47.         end
  48.     end
  49.     return count
  50. end
  51.  
  52. return tutils
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement