Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- args={...}
- function saveRecipes()
- if recipes~=nil then
- fp=fs.open("recipes.lua","w")
- fp.write(textutils.serialize(recipes))
- fp.close()
- else
- error("recipes empty?!?!")
- end
- end
- function getRecipes()
- fp=fs.open("recipes.lua","r")
- recipes=textutils.unserialize(fp.readAll())
- fp.close()
- end
- if fs.exists("recipes.lua")==false then
- recipes={}
- saveRecipes()
- end
- function scan()
- items={}
- for i=1, 16 do
- item=turtle.getItemDetail(i)
- if item~=nil then
- table.insert(items,item)
- end
- end
- end
- if args[1]=="scan" then
- itemName=args[2]
- if itemName==nil then
- error("usage: scan itemname")
- end
- scan()
- getRecipes()
- if items~=nil then
- recipes[itemName]=items
- end
- saveRecipes()
- end
- function checkRecipes()
- for recipeName,recipe in pairs(recipes) do
- recipePossible=true
- scan()
- for iC1=1,#recipe do
- itemAvailable=false
- for iC2=1, #items do
- if compareStack(recipe[iC1],items[iC2]) then
- itemAvailable=true
- end
- end
- if itemAvailable==false then
- recipePossible=false
- end
- end
- if recipePossible then
- print(recipeName.." found!")
- for iC3=1, #items do
- turtle.select(iC3)
- turtle.dropDown()
- end
- end
- end
- end
- function compareStack(itemA,itemB)
- sameItems=false
- --print("compare "..itemA.name.." and "..itemB.name)
- if itemA~=nil and itemB~=nil then
- if itemA.name==itemB.name and itemA.count==itemB.count and itemA.nbtHash==itemB.nbtHash then
- sameItems=true
- end
- end
- --print(sameItems)
- return sameItems
- end
- if args[1]==nil then
- getRecipes()
- while true do
- sleep(1)
- checkRecipes()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment