Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local chest = peripheral.wrap("front")
- local query = nil
- rednet.open("bottom")
- function io()
- if query == nil then
- return
- end
- -- Pipe matching items towards player
- local chest_items = chest.list()
- if chest_items ~= nil then
- for slot, item in pairs(chest_items) do
- if string.find(item.name, query) then
- turtle.select(1)
- turtle.suck()
- end
- break
- end
- end
- end
- function empty_garbage()
- -- Pipe non-matching items away from player
- for i=1, 16 do
- turtle.select(i)
- itemDetail = turtle.getItemDetail()
- if query == nil or (itemDetail ~= nil and not string.find(itemDetail.name, query)) then
- turtle.drop()
- end
- end
- turtle.select(1)
- end
- local query_input = ""
- local width, height = term.getSize()
- while true do
- term.setCursorPos(1, height)
- term.clearLine()
- term.write("> " .. query_input)
- os.startTimer(1)
- local eventData = { os.pullEvent() }
- local event = eventData[1]
- if event == "key" then
- local key = eventData[2]
- if key == 257 then
- if string.len(query_input) > 0 then
- query = query_input
- rednet.broadcast(query)
- empty_garbage()
- query_input = ""
- end
- elseif key == 259 then
- query_input = string.sub(query_input, 1, -2)
- elseif key >= 39 and key <= 126 then
- query_input = query_input .. string.char(key)
- end
- end
- io();
- end
Advertisement
Add Comment
Please, Sign In to add comment