Advertisement
ame824

BM-Altar

Jan 17th, 2022 (edited)
615
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.62 KB | None | 0 0
  1. ------------------------------------------------------------------------------------------------------------------------------
  2. -- BM Altar by ame824
  3. -- created Jan 2021
  4. -- last update Oct 2022
  5. ------------------------------------------------------------------------------------------------------------------------------
  6. --config
  7. ------------------------------------------------------------------------------------------------------------------------------
  8. local altarBufferChestDir = "west"
  9. local altarBufferChestName = "gold"
  10. local altarOutputChestDir = "east"
  11. -- Whether or not the script will wait for the altar to have enough LP in it to do the craft
  12. -- Suggested that this is 'false' if you run a well of suffering, or know that you will have enough LP for any given craft
  13. local checkAltarLPLevelsFirst = true
  14. ------------------------------------------------------------------------------------------------------------------------------
  15. --reciepes
  16. ------------------------------------------------------------------------------------------------------------------------------
  17. local recipes = {
  18. -- "Vanilla" Blood Magic (Stone -> Slate)
  19.   {source="minecraft:stone", final="AWWayofTime:blankSlate", lp=1000},
  20.  
  21. -- FTB Infinity Evolved (Expert) Blood Magic (Arcane Stone Block -> Slate)
  22. --{source="Thaumcraft:blockCosmeticSolid:6", final="AWWayofTime:blankSlate", lp=1000},
  23.  
  24.  
  25. {source="AWWayofTime:blankSlate", final="AWWayofTime:reinforcedSlate", lp=2000},
  26. {source="AWWayofTime:reinforcedSlate", final="AWWayofTime:imbuedSlate", lp=5000},
  27. {source="AWWayofTime:imbuedSlate", final="AWWayofTime:demonicSlate", lp=15000},
  28. {source="AWWayofTime:demonicSlate", final="AWWayofTime:bloodMagicBaseItems:27", lp=30000},
  29. -- Add other recipes here if you want.
  30. }
  31. ------------------------------------------------------------------------------------------------------------------------------
  32. --DON'T CHANGE ANYTHING UNDER THIS
  33. ------------------------------------------------------------------------------------------------------------------------------
  34.  
  35. local altar = peripheral.find("tealtar")
  36. local chest = peripheral.find(altarBufferChestName)
  37.  
  38.  
  39. function getAltarItem()
  40.   local stack = altar.getStackInSlot(1)
  41.   if not stack then return nil end
  42.   return stack.name
  43. end
  44.  
  45. function getAltarLevel()
  46.     local altarInfo = altar.getInfo()
  47.     local level = altarInfo.contents.amount
  48.     return level
  49. end
  50.  
  51. function altarHasOrb()
  52.   local item = getAltarItem()
  53.   if item ~= nil and string.find(item, "Orb") then
  54.         return true
  55.   else
  56.         return false
  57.   end
  58. end
  59.  
  60. function chestHasOrb()
  61.         return getChestOrbSlot() ~= 0
  62. end
  63.  
  64. function getChestOrbSlot()
  65.         for i=1, chest.getInventorySize() do
  66.                 if chest.getStackInSlot(i) then
  67.                         if string.find(chest.getStackInSlot(i).name, "Orb") then
  68.                                 return i
  69.                         end
  70.                 end
  71.         end
  72.         return 0
  73. end
  74.  
  75. function putOrbInAltar()
  76.         -- Only check if there is *any* item there. We may be crafting something
  77.         -- if the orb is there already, there's no point in running this yet anyway.
  78.         if getAltarItem() == nil then
  79.                 if not chestHasOrb() then
  80.                         error("The buffer chest does not have an orb in it, and we expect one for re-charging the LP network. Did you remove it?")
  81.                 end
  82.                 print("Moving Blood Orb back into the altar to charge LP")
  83.                 altar.pullItem(altarBufferChestDir, getChestOrbSlot(), 1)
  84.                 sleep(0.5)
  85.         end
  86. end
  87.  
  88. function removeOrbFromAltar()
  89.         if altarHasOrb() then
  90.                 altar.pushItem(altarBufferChestDir, 1)
  91.                 sleep(0.5)
  92.         end
  93. end
  94.  
  95. function getItemId(stack)
  96.         if stack then
  97.                 if stack.dmg ~= nil and stack.dmg ~= 0 then
  98.                         return stack.id .. ":" .. stack.dmg
  99.                 else
  100.                         return stack.id
  101.                 end
  102.         end
  103.         return nil
  104. end
  105.  
  106. function findCraftingRecipe(stack)
  107.         local itemId = getItemId(stack)
  108.         if itemId then
  109.                 for i=1, #recipes do
  110.                     local source = recipes[i].source
  111.                     if source == itemId then
  112.                         return recipes[i]
  113.                     end
  114.                 end
  115.         end
  116.         return nil
  117. end
  118.  
  119. function craftSlate()
  120.         for i=1, chest.getInventorySize() do
  121.                 -- Figure out if we have anything to craft
  122.                 local stack = chest.getStackInSlot(i)
  123.                 local recipe = findCraftingRecipe(stack)
  124.                 local altarLP = getAltarLevel()
  125.  
  126.                 if stack ~= nil then
  127.                         if recipe ~= nil then
  128.                             local recipeLP = recipe.lp
  129.                             if not checkAltarLPLevelsFirst then
  130.                                 removeOrbFromAltar()
  131.                                 print("Transmuting " .. stack.display_name)
  132.                                 altar.pullItem(altarBufferChestDir, i, 1)
  133.                                 --sleep(0.5)
  134.                                 while getItemId(altar.getStackInSlot(1)) ~= recipe.final do
  135.                                         sleep(0.1)
  136.                                 end
  137.                                 --sleep(0.5)
  138.                                 altar.pushItem(altarOutputChestDir, 1)
  139.                                 --sleep(0.5)
  140.                             else
  141.                                 if altarLP >= recipeLP then
  142.                                     removeOrbFromAltar()
  143.                                     print("Transmuting " .. stack.display_name)
  144.                                     altar.pullItem(altarBufferChestDir, i, 1)
  145.                                     --sleep(0.5)
  146.                                     while getItemId(altar.getStackInSlot(1)) ~= recipe.final do
  147.                                             sleep(0.1)
  148.                                     end
  149.                                     --sleep(0.5)
  150.                                     altar.pushItem(altarOutputChestDir, 1)
  151.                                     --sleep(0.5)
  152.                                 else
  153.                                     if not getChestOrbSlot() then removeOrbFromAltar() end
  154.                                     print("to Less LP for Recipe...")
  155.                                 end
  156.                             end
  157.                             return true
  158.                         end
  159.                 end
  160.         end
  161.         return false
  162. end
  163.  
  164.  
  165. while true do
  166.         if not craftSlate() then
  167.                 putOrbInAltar()
  168.                 sleep(1)
  169.         end
  170. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement