Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- vos.loadApi('apis.lua')
- local chest = Peripheral.wrap({ alias = 'chest' })
- Logger.disable()
- function learn()
- listPage.grid.t = { }
- local t = chest.getAllStacks()
- for k,slot in pairs(t) do
- table.insert(listPage.grid.t, {
- name = slot.name,
- slotNo = k
- })
- end
- Util.writeTable('inventory.table', listPage.grid.t)
- end
- --[[-- listPage --]]--
- listPage = UI.Page({
- titleBar = UI.TitleBar({
- title = 'Organizer'
- }),
- grid = UI.ScrollingGrid({
- columns = {
- { 'Name', 'name', UI.term.width-7 },
- { 'Slot', 'slotNo', 4 }
- },
- sortColumn = 'name',
- pageSize = UI.term.height-3,
- y = 2
- }),
- statusBar = UI.StatusBar({
- status = 'l to learn'
- }),
- accelerators = {
- l = 'learn',
- q = 'quit'
- }
- })
- function listPage:eventHandler(event)
- if event.type == 'quit' then
- Event.exitPullEvents()
- elseif event.type == 'learn' then
- learn()
- self.grid:draw()
- end
- return UI.Page.eventHandler(self, event)
- end
- Event.addHandler('turtle_inventory', function()
- local tslots = TL2.getFilledSlots()
- local function getOpenSlot()
- for i = 1, chest.getInventorySize() do
- if not chest.getStackInSlot(i) then
- return i
- end
- end
- end
- for _,tslot in pairs(tslots) do
- local chestSlot = getOpenSlot()
- chest.pullItemIntoSlot('down', tslot.slotNo, 1, chestSlot)
- local slot = chest.getStackInSlot(chestSlot)
- for k,s in pairs(listPage.grid.t) do
- if s.name == slot.name then
- if not chest.getStackInSlot(s.slotNo) then
- chest.swapStacks(chestSlot, s.slotNo)
- break
- end
- end
- end
- end
- end)
- listPage.grid.t = Util.readTable('inventory.table', slots)
- if Util.empty(listPage.grid.t) then
- learn()
- end
- UI.pager:setPage(listPage)
- Event.pullEvents()
- UI.term:clear()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement