Advertisement
massacring

MassaTurtleLib

Jun 18th, 2024 (edited)
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.81 KB | None | 0 0
  1. local function getItems(detailed)
  2.     if not detailed then detailed = false end
  3.     local items = {}
  4.     for i = 1, 16, 1 do
  5.         table.insert(items, turtle.getItemDetail(i, detailed))
  6.     end
  7.     return items
  8. end
  9.  
  10. local function getItemIndex(identifier)
  11.     local id, tag
  12.     if string.sub(identifier, 1, 1) == "#" then
  13.         tag = identifier:sub(2)
  14.     else
  15.         id = identifier
  16.     end
  17.     for i = 1, 16, 1 do
  18.         local item = turtle.getItemDetail(i, true)
  19.         if not item then goto continue end
  20.  
  21.         if tag and item.tags then
  22.             if item.tags[tag] then return i end
  23.         else
  24.             if item.name == id then return i end
  25.         end
  26.  
  27.         ::continue::
  28.     end
  29.     error("Item not found.", 2)
  30. end
  31.  
  32. return { getItems = getItems, getItemIndex = getItemIndex }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement