ecco7777

CC Turtle Recipe Checker

Jan 16th, 2026
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.99 KB | None | 0 0
  1. args={...}
  2.  
  3. function saveRecipes()
  4.     if recipes~=nil then
  5.         fp=fs.open("recipes.lua","w")
  6.         fp.write(textutils.serialize(recipes))
  7.         fp.close()
  8.     else
  9.         error("recipes empty?!?!")
  10.     end
  11. end
  12.  
  13. function getRecipes()
  14.     fp=fs.open("recipes.lua","r")
  15.     recipes=textutils.unserialize(fp.readAll())
  16.     fp.close()
  17. end
  18.  
  19. if fs.exists("recipes.lua")==false then
  20.     recipes={}
  21.     saveRecipes()
  22. end
  23.  
  24. function scan()
  25.     items={}
  26.     for i=1, 16 do
  27.         item=turtle.getItemDetail(i)
  28.         if item~=nil then
  29.             table.insert(items,item)
  30.         end
  31.  
  32.     end
  33. end
  34.  
  35. if args[1]=="scan" then
  36.     itemName=args[2]
  37.     if itemName==nil then
  38.         error("usage: scan itemname")
  39.     end
  40.     scan()
  41.     getRecipes()
  42.     if items~=nil then
  43.         recipes[itemName]=items
  44.     end
  45.     saveRecipes()
  46. end
  47.  
  48. function checkRecipes()
  49.     for recipeName,recipe in pairs(recipes) do
  50.         recipePossible=true
  51.         scan()
  52.         for iC1=1,#recipe do
  53.             itemAvailable=false
  54.             for iC2=1, #items do
  55.                 if compareStack(recipe[iC1],items[iC2]) then
  56.                     itemAvailable=true
  57.                 end
  58.             end
  59.             if itemAvailable==false then
  60.                 recipePossible=false
  61.             end
  62.         end
  63.         if recipePossible then
  64.             print(recipeName.." found!")
  65.             for iC3=1, #items do
  66.                 turtle.select(iC3)
  67.                 turtle.dropDown()
  68.             end
  69.         end
  70.     end
  71. end
  72.  
  73. function compareStack(itemA,itemB)
  74.     sameItems=false
  75.     --print("compare "..itemA.name.." and "..itemB.name)
  76.     if itemA~=nil and itemB~=nil then
  77.         if itemA.name==itemB.name and itemA.count==itemB.count and itemA.nbtHash==itemB.nbtHash then
  78.             sameItems=true
  79.         end
  80.     end
  81.     --print(sameItems)
  82.     return sameItems
  83. end
  84.  
  85. if args[1]==nil then
  86.     getRecipes()
  87.     while true do
  88.         sleep(1)
  89.         checkRecipes()
  90.     end
  91. end
Advertisement
Add Comment
Please, Sign In to add comment