Advertisement
Reisyukaku

Untitled

Oct 3rd, 2022
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. InventoryCache = {}
  2.  
  3. function InventoryCache:new(o)
  4. o = o or {}
  5. setmetatable(o, self)
  6. self.__index = self
  7. self.data = {}
  8. return o
  9. end
  10.  
  11. function InventoryCache:FindItem(item)
  12. local ret = -1
  13. for i = 1,16 do
  14. data = self.data[i]
  15. if (data ~= nil and data.name == item) then
  16. ret = i
  17. end
  18. end
  19. return ret
  20. end
  21.  
  22. function InventoryCache:MoveItem(from, to, count)
  23. print("Moving items from " .. from .. " to " .. to)
  24. turtle.select(from)
  25. if(count ~= nil) then
  26. turtle.transferTo(to, count)
  27. else
  28. turtle.transferTo(to)
  29. end
  30. local tmp = self.data[to]
  31. self.data[to] = self.data[from]
  32. self.data[from] = tmp
  33. end
  34.  
  35. function InventoryCache:IsSlotOpen(slot)
  36. return self.data[slot] == nil
  37. end
  38.  
  39. function InventoryCache:Update()
  40. print("Updating cache..")
  41. for i = 1,16 do
  42. turtle.select(i)
  43. data = turtle.getItemDetail(i)
  44. self.data[i] = data
  45. end
  46. end
  47.  
  48. function InventoryCache:PrintInventory()
  49. for i = 1,16 do
  50. if(self.data[i] ~= nil) then
  51. print(self.data[i].name .. " in slot " .. i)
  52. end
  53. end
  54. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement