Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local channel = 11
- local recipes = {}
- local lp = peripheral.wrap("right")
- if not lp.getTurtleConnect() then lp.setTurtleConnect(true) end
- local wifi = peripheral.find("modem")
- if not wifi.isWireless() then wifi = nil end
- wifi.open(channel)
- local ae = peripheral.wrap("top")
- -- http://lua-users.org/wiki/SplitJoin
- local function split(str, pat)
- local t = {}
- local fpat = "(.-)" .. pat
- local last_end = 1
- local s, e, cap = str:find(fpat, 1)
- while s do
- if s ~= 1 or cap ~= "" then
- table.insert(t,cap)
- end
- last_end = e+1
- s, e, cap = str:find(fpat, last_end)
- end
- if last_end <= #str then
- cap = str:sub(last_end)
- table.insert(t, cap)
- end
- return t
- end
- local beans = {}
- local function scanBeans()
- local allItems = lp.getAvailableItems()
- --print(#allItems, " items in lp system")
- for i,item in pairs(allItems) do
- if lp.getItemID(item[1]) == 25366 then
- local nbt = lp.getNBTTagCompound(item[1])
- if nbt then
- local name = nbt.value.Aspects.value[1].value.key.value
- if not beans[name] then beans[name] = {lpID=item[1], qty=item[2]}
- else print("duplicate bean: ",name) end
- end
- end
- end
- end
- local function readRecipes()
- local recipeFile = fs.open("recipes","r")
- if not recipeFile then return 0 end
- local line = recipeFile.readLine()
- while line do
- local recipe = split(line,",")
- if #recipe % 2 ~= 1 then break end
- recipes[recipe[1]] = {}
- for i=2,#recipe,2 do
- table.insert(recipes[recipe[1]],{type=recipe[i],qty=recipe[i+1]})
- end
- line = recipeFile.readLine()
- end
- recipeFile.close()
- end
- scanBeans()
- readRecipes()
- --for i,k in pairs(recipes) do print(i); for n=1,#k do for j,l in pairs(k[n]) do print(j," ",l) end end end
- --for i,k in pairs(recipes) do print(i," ",k) end
- local function clearInventory()
- for i=1,16 do
- local n = turtle.getItemCount(i)
- if ae.pullItem("down",i,n) - n ~= 0 then i = i - 1 end
- end
- end
- clearInventory()
- while true do
- os.pullEvent("turtle_inventory")
- --print("inventory's changed")
- wifi.transmit(channel,channel,"getJobList")
- local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
- --for i,k in pairs(message[1]) do print(i," ",k) end
- --if message and message[1] and message[1].name then print(message[1].name) end
- if message then
- for i=1,#message do
- if message[i] and message[i].name and message[i].qty and recipes[message[i].name] then print(message[i].name," ",message[i].qty) end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment