Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- InventoryCache = {}
- function InventoryCache:new(o)
- o = o or {}
- setmetatable(o, self)
- self.__index = self
- self.data = {}
- return o
- end
- function InventoryCache:FindItem(item)
- local ret = -1
- for i = 1,16 do
- data = self.data[i]
- if (data ~= nil and data.name == item) then
- ret = i
- end
- end
- return ret
- end
- function InventoryCache:MoveItem(from, to, count)
- print("Moving items from " .. from .. " to " .. to)
- turtle.select(from)
- if(count ~= nil) then
- turtle.transferTo(to, count)
- else
- turtle.transferTo(to)
- end
- local tmp = self.data[to]
- self.data[to] = self.data[from]
- self.data[from] = tmp
- end
- function InventoryCache:IsSlotOpen(slot)
- return self.data[slot] == nil
- end
- function InventoryCache:Update()
- print("Updating cache..")
- for i = 1,16 do
- turtle.select(i)
- data = turtle.getItemDetail(i)
- self.data[i] = data
- end
- end
- function InventoryCache:PrintInventory()
- for i = 1,16 do
- if(self.data[i] ~= nil) then
- print(self.data[i].name .. " in slot " .. i)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement