function count(name) local value = 0 for i = 1,16 do local item = turtle.getItemDetail(i) if item and item.name == name then value = value + item.count end if item and item.name == "packages:package" then turtle.select(i) turtle.placeUp() sleep(.1) pack = peripheral.wrap("top") items = pack.list() for i,v in pairs(items) do if v.name == name then value = value + v.count end end turtle.digUp() end end return value end function select(name) local flag = false for i = 1,16 do item = turtle.getItemDetail(i) if not item then flag = true end if item and item.name == name then turtle.select(i) return true end end for i = 1,16 do item = turtle.getItemDetail(i) if flag and item and item.name == "packages:package" then turtle.select(i) turtle.placeUp() sleep(0.1) items = peripheral.call("top","list") for i,v in pairs(items) do if v.name == name then turtle.suckUp(64) break end end turtle.digUp() for i = 1,16 do item = turtle.getItemDetail(i) if item and item.name == name then turtle.select(i) return true end end end end print("no"..name.."found") return false end function pull(name, slot) slot = slot or turtle.getSelectedSlot() turtle.select(slot) i = 1 item = turtle.getItemDetail(slot) while item and item.name~=name and i <=16 do turtle.transferTo(i) item = turtle.getItemDetail(slot) i = i+1 end local flag = false for i = 1,16 do item = turtle.getItemDetail(i) if item and item.name == name then turtle.select(i) turtle.transferTo(slot) flag = true end end turtle.select(slot) if flag then return turtle.getItemCount(slot) end return error("there is no '"..name.."' in my inventory") end return {pull=pull,count=count,select=select}