Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local drop_chest = peripheral.wrap( "left" )
- local output_chest = peripheral.wrap( "right" )
- local trash = peripheral.wrap( "front" )
- local filename = "pages"
- local file = fs.open(filename, "r")
- local data = nil
- if file ~= nil then
- local raw_data = file.readAll( )
- data = string.len(raw_data) == 0 and {} or textutils.unserialize(raw_data)
- file.close( )
- else
- data = {}
- end
- local new_count = 0
- local repeat_count = 0
- local drop_chest_size = drop_chest.getInventorySize( )
- for s=1, drop_chest_size do
- local item = drop_chest.getStackInSlot(s)
- if item ~= nil then
- local name = item.display_name
- local amount = item.qty
- print( name .. " : " .. amount )
- drop_chest.pushItem("west", s, 64)
- for i = 1, amount do
- if data[name] == nil then
- -- New Page
- data[name] = 1
- output_chest.pullItem( "east", 1, 1 )
- new_count = new_count + 1
- else
- -- Old Page
- trash.pullItem( "north", 1, 1 )
- repeat_count = repeat_count + 1
- end
- end
- end
- end
- print("New Pages Found: " .. tostring(new_count))
- print("Repeat Pages Discarded: " .. tostring(repeat_count))
- file = fs.open(filename, "w")
- file.write(textutils.serialize(data))
- file.close( )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement