Advertisement
ozozx235

TUtil.lua

Dec 5th, 2022 (edited)
574
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.92 KB | Gaming | 0 0
  1. function arrComp (a,b)
  2.     return textutils.serialise(a) == textutils.serialise(b)
  3. end
  4. function findEmp ()
  5.     for i=1,16 do
  6.         if not turtle.getItemDetail(i) then
  7.             return i
  8.         end
  9.     end
  10. end
  11. function findI (name)
  12.     for slot in invItr() do
  13.         if slot.it then
  14.             if slot.it.name == name then
  15.                 return slot.idx
  16.             end
  17.         end
  18.     end
  19. return 0
  20. end
  21. function mkItr(tab)
  22.     local i=0
  23.     local n = #tab
  24.     return function()
  25.         i=i+1
  26.         if i <= n then return tab[i] end
  27.     end
  28. end
  29. local function invTab ()
  30.     local inv = {}
  31.     for i=1,16 do
  32.         local item = turtle.getItemDetail(i)
  33.         inv[i]={idx=i,it=item}
  34.     end
  35.     return inv
  36. end
  37. function invItr ()
  38.     return mkItr(invTab())
  39. end
  40. function getInv ()
  41.     inv = {}
  42.     i=1
  43.     for slot in invItr() do
  44.         if slot.it then
  45.             inv[i]=slot.it
  46.             i=i+1
  47.         end
  48.     end
  49.     return inv
  50. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement