Advertisement
lucifersamfr

RunicAltar

Mar 20th, 2015
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.81 KB | None | 0 0
  1. local tempSlot = 4
  2. local targetRuneCount = 16
  3. local getRuneWait = 4
  4. local dropEachWait = 1
  5. local wandTapWait = 4
  6. local runicAltarWait = 18
  7. local loopWait = 1
  8. local quit = false
  9.  
  10. --materials chest
  11. local materialsSide = "right"
  12. local dirMatTurtle  = "east"
  13. local dirTurtleMat  = "west"
  14.  
  15. --runes chest
  16. local runeChestSide = "left"
  17. local dirRuneTurtle  = "west"
  18. local dirTurtleRune  = "east"
  19.  
  20. --redstone config
  21. local sigSide = "bottom"
  22. local wandCol = colors.green
  23. local blockNodeCol = colors.blue
  24. local nodeState = false
  25.  
  26. local runeChest = peripheral.wrap(runeChestSide)
  27. local materials = peripheral.wrap(materialsSide)
  28.  
  29. local recipes = {}
  30. recipes["Rune of Water"]={
  31.   {name="Manasteel Ingot" ,qty=3},
  32.   {name="Fishing Rod" ,qty=1},
  33.   {name="Sugar Canes" ,qty=1},
  34.   {name="Bone Meal" ,qty=1}
  35. }
  36. recipes["Rune of Fire"]={
  37.   {name="Manasteel Ingot" ,qty=3},
  38.   {name="Nether Wart" ,qty=1},
  39.   {name="Nether Brick" ,qty=1},
  40.   {name="Gunpowder" ,qty=1}
  41. }
  42. recipes["Rune of Earth"]={
  43.   {name="Manasteel Ingot" ,qty=3},
  44.   {name="Stone" ,qty=1},
  45.   {name="Block of Coal" ,qty=1},
  46.   {name="Mushroom" ,qty=1}
  47. }
  48. recipes["Rune of Air"]={
  49.   {name="Manasteel Ingot" ,qty=3},
  50.   {name="String" ,qty=1},
  51.   {name="Feather" ,qty=1},
  52.   {name="Carpet" ,qty=1}
  53. }
  54.  
  55. local advRecipes = {}
  56. advRecipes["Rune of Spring"]={
  57.   {name="Rune of Water" ,qty=1},
  58.   {name="Rune of Fire" ,qty=1},
  59.   {name="Wheat" ,qty=1},
  60.   {name="Spruce Sapling" ,qty=3}
  61. }
  62. advRecipes["Rune of Summer"]={
  63.   {name="Rune of Earth" ,qty=1},
  64.   {name="Rune of Air" ,qty=1},
  65.   {name="Melon" ,qty=1},
  66.   {name="Slimeball" ,qty=1},
  67.   {name="Sand" ,qty=2}
  68. }
  69. advRecipes["Rune of Autumn"]={
  70.   {name="Rune of Fire" ,qty=1},
  71.   {name="Rune of Air" ,qty=1},
  72.   {name="Spider Eye" ,qty=1},
  73.   {name="Oak Leaves" ,qty=3}
  74. }
  75. advRecipes["Rune of Winter"]={
  76.   {name="Rune of Water" ,qty=1},
  77.   {name="Rune of Earth" ,qty=1},
  78.   {name="Cake" ,qty=1},
  79.   {name="Wool" ,qty=1},
  80.   {name="Snow" ,qty=2}
  81. }
  82. advRecipes["Rune of Mana"]={
  83.   {name="Manasteel Ingot" ,qty=5},
  84.   {name="Mana Pearl" ,qty=1}
  85. }
  86. local adv2Recipes = {}
  87. adv2Recipes["Rune of Lust"]={
  88.   {name="Rune of Summer" ,qty=1},
  89.   {name="Rune of Air" ,qty=1},
  90.   {name="Mana Diamond" ,qty=2}
  91. }
  92. adv2Recipes["Rune of Gluttony"]={
  93.   {name="Rune of Fire" ,qty=1},
  94.   {name="Rune of Winter" ,qty=1},
  95.   {name="Mana Diamond" ,qty=2}
  96. }
  97. adv2Recipes["Rune of Greed"]={
  98.   {name="Rune of Water" ,qty=1},
  99.   {name="Rune of Spring" ,qty=1},
  100.   {name="Mana Diamond" ,qty=2}
  101. }
  102. adv2Recipes["Rune of Sloth"]={
  103.   {name="Rune of Autumn" ,qty=1},
  104.   {name="Rune of Air" ,qty=1},
  105.   {name="Mana Diamond" ,qty=2}
  106. }
  107. adv2Recipes["Rune of Wrath"]={
  108.   {name="Rune of Earth" ,qty=1},
  109.   {name="Rune of Winter" ,qty=1},
  110.   {name="Mana Diamond" ,qty=2}
  111. }
  112. adv2Recipes["Rune of Envy"]={
  113.   {name="Rune of Water" ,qty=1},
  114.   {name="Rune of Winter" ,qty=1},
  115.   {name="Mana Diamond" ,qty=2}
  116. }
  117. adv2Recipes["Rune of Pride"]={
  118.   {name="Rune of Fire" ,qty=1},
  119.   {name="Rune of Summer" ,qty=1},
  120.   {name="Mana Diamond" ,qty=2}
  121. }
  122.  
  123. function debugSignal()
  124.   local sig = rs.getBundledOutput(sigSide)
  125.   if colors.test(sig, colors.blue) then
  126.     print("DEBUG : rs signal blocking node!")
  127.   else
  128.     print("DEBUG : node free!")
  129.   end
  130.   if colors.test(sig, colors.green) then
  131.     print("DEBUG : rs signal activating wand!")
  132.   else
  133.     print("DEBUG : wand inactive!")
  134.   end
  135. end
  136.  
  137. function blockTransferNode()
  138.   rs.setBundledOutput(sigSide, blockNodeCol)
  139.   nodeState=false
  140. end
  141.  
  142. function releaseTransferNode()
  143.   rs.setBundledOutput(sigSide, 0)
  144.   nodeState=true
  145. end
  146.  
  147. function printItemSlot(slot)
  148.   if slot.display_name ~= nil then  print("display_name : "..slot.display_name) end
  149.   if slot.qty ~= nil then           print("qty          : "..slot.qty) end
  150.   if slot.max_size ~= nil then      print("max_size     : "..slot.max_size) end
  151.   if slot.max_dmg ~= nil then       print("max_dmg      : "..slot.max_dmg) end
  152.   if slot.raw_name ~= nil then      print("raw_name     : "..slot.raw_name) end
  153.   if slot.dmg ~= nil then           print("dmg          : "..slot.dmg) end
  154.   if slot.id ~= nil then            print("id           : "..slot.id) end
  155.   if slot.name ~= nil then          print("name         : "..slot.name) end
  156.   if slot.mod_id ~= nil then        print("mod_id       : "..slot.mod_id) end
  157. end
  158.  
  159. function isRecipeComplete(ing)
  160.   for i,j in pairs(ing) do
  161.     if j~=nil then  
  162.       if j.qty > 0 then
  163.         return false
  164.       end
  165.     end
  166.   end
  167.   return true
  168. end
  169.  
  170. function dropTempSlot()
  171.   turtle.select(tempSlot)
  172.   while turtle.getItemCount(tempSlot) > 0 do
  173.     turtle.dropUp(1)
  174.     sleep(dropEachWait)
  175.   end
  176. end
  177.  
  178. function collectChest(chest,dirChestTur,todo)
  179.   if not isRecipeComplete(todo) then
  180.     chest.condenseItems()
  181.     local as = chest.getAllStacks()
  182.     for s=1,#as do
  183.       if as[s]~=nil then
  184.         local slot = as[s]
  185.         --printItemSlot(as[s])
  186.         for i=1,#todo do
  187.           if todo[i].qty > 0 and todo[i].name == slot.display_name then
  188.             --print("| | "..slot.display_name.." found.")
  189.             local pushed = chest.pushItemIntoSlot(dirChestTur,s,todo[i].qty,tempSlot)
  190.             todo[i].qty = todo[i].qty - pushed
  191.             dropTempSlot()
  192.             print("| | "..pushed.." "..slot.display_name.." dropped in altar.")
  193.           end
  194.         end
  195.       end
  196.     end
  197.   end
  198.   return todo
  199. end
  200.  
  201. function copy3(obj, seen)
  202. -- Handle non-tables and previously-seen tables.
  203. if type(obj) ~= 'table' then return obj end
  204. if seen and seen[obj] then return seen[obj] end
  205.  
  206. -- New table; mark it as seen an copy recursively.
  207. local s = seen or {}
  208. local res = setmetatable({}, getmetatable(obj))
  209. s[obj] = res
  210. for k, v in pairs(obj) do res[copy3(k, s)] = copy3(v, s) end
  211. return res
  212. end
  213.  
  214. function dropInAltar(ingredients)
  215.   local todo = copy3(ingredients,nil)
  216.  
  217.   print("| collecting input materials...")
  218.   todo = collectChest(materials,dirMatTurtle,todo)
  219.   print("| collecting input runes...")
  220.   todo = collectChest(runeChest,dirRuneTurtle,todo)
  221.   return isRecipeComplete(todo)
  222. end
  223.  
  224. function runeCount(name)
  225.   local as = runeChest.getAllStacks()
  226.   local count=0
  227.   for s=1,#as do
  228.     if as[s]~=nil then
  229.       if string.lower(as[s].display_name) == string.lower(name) then
  230.         count = count + as[s].qty
  231.       end
  232.     end
  233.   end
  234.   return count
  235. end
  236.  
  237. function wandTap()
  238.   rs.setBundledOutput(sigSide, colors.combine(rs.getBundledOutput(sigSide), wandCol))
  239.   print("| WandTap!")
  240.   sleep(wandTapWait)
  241.   rs.setBundledOutput(sigSide, colors.subtract(rs.getBundledOutput(sigSide), wandCol))
  242. end
  243.  
  244. function runeInSlot(slot)
  245.   if slot == nil then
  246.     return false
  247.   else
  248.     return turtle.getItemDetail().name=="Botania:rune"
  249.   end
  250. end
  251.  
  252. function getRune()
  253.   releaseTransferNode()
  254.   wandTap()
  255.   sleep(getRuneWait)  
  256.   blockTransferNode()
  257. end
  258.  
  259. function dropLivingRock()
  260.   return isRecipeComplete(collectChest(materials,dirMatTurtle,{{name="Livingrock",qty=1}}))
  261. end
  262.  
  263. function processRecipes(listRecipes)
  264.   local hadWorked = false
  265.   for i,j in pairs(listRecipes) do
  266.     local nbRune = runeCount(i)
  267.     print("\n"..i.." : "..nbRune.."/"..targetRuneCount)
  268.     if nbRune < targetRuneCount then
  269.       hadWorked=true
  270.       if dropInAltar(j) then
  271.         print("| all ingredients dropped in altar.")
  272.         wandTap()
  273.         print("| Waiting runic altar...")
  274.         sleep(runicAltarWait)
  275.         if dropLivingRock() then
  276.           print("| livingrock dropped.")
  277.         end
  278.        
  279.         getRune()
  280.       else
  281.         quit = true
  282.         break
  283.       end
  284.     end
  285.   end
  286.   return hadWorked
  287. end
  288.  
  289. rs.setBundledOutput(sigSide, blockNodeCol)
  290. sleep(1)
  291.  
  292. blockTransferNode()
  293.  
  294. while true do
  295.   if not processRecipes(recipes) then
  296.     if not processRecipes(advRecipes) then
  297.       processRecipes(adv2Recipes)
  298.     end
  299.   end
  300.   if quit then
  301.     print("Quitting....")
  302.     break
  303.   end
  304.   sleep(loopWait)
  305. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement