Advertisement
Guest User

bloodAltar.lua

a guest
Dec 6th, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.79 KB | None | 0 0
  1. -- BM Altar Automation by Apoc
  2. -- v1.0 - 2/20/2016
  3. --              Initial Release
  4.  
  5. local altarPeripheralName = "bloodmagic:altar_0"
  6. local altarBufferChestDir = "west"
  7. local altarBufferChestName = "minecraft:chest_0"
  8. local altarOutputChestDir = "east"
  9. -- Whether or not the script will wait for the altar to have enough LP in it to do the craft
  10. -- Suggested that this is 'false' if you run a well of suffering, or know that you will have enough LP for any given craft
  11. -- Not yet implemented :(/>/>
  12. local checkAltarLPLevelsFirst = false
  13.  
  14. local recipes = {
  15. -- "Vanilla" Blood Magic (Stone -> Slate)
  16. -- {source="Minecraft:blockStone", final="AWWayofTime:blankSlate", lp=1000},
  17.  
  18. -- FTB Infinity Evolved (Expert) Blood Magic (Arcane Stone Block -> Slate)
  19. {source="Thaumcraft:blockCosmeticSolid:6", final="AWWayofTime:blankSlate", lp=1000},
  20.  
  21.  
  22. {source="AWWayofTime:blankSlate", final="AWWayofTime:reinforcedSlate", lp=2000},
  23. {source="AWWayofTime:reinforcedSlate", final="AWWayofTime:imbuedSlate", lp=5000},
  24. {source="AWWayofTime:imbuedSlate", final="AWWayofTime:demonicSlate", lp=15000},
  25. {source="AWWayofTime:demonicSlate", final="AWWayofTime:bloodMagicBaseItems:27", lp=30000},
  26. -- Add other recipes here if you want.
  27. }
  28.  
  29. local altar = peripheral.wrap(altarPeripheralName)
  30. local chest = peripheral.wrap(altarBufferChestName)
  31.  
  32.  
  33. function getAltarItem()
  34.   local stack = altar.getItem(1)
  35.   if not stack then return nil end
  36.   return stack.getMetadata().name
  37. end
  38.  
  39. function altarHasOrb()
  40.   local item = getAltarItem()
  41.   if item ~= nil and string.find(item, "blood_orb") then
  42.         return true
  43.   else
  44.         return false
  45.   end
  46. end
  47.  
  48. function chestHasOrb()
  49.         return getChestOrbSlot() ~= 0
  50. end
  51.  
  52. function getChestOrbSlot()
  53.         for i=1, chest.size() do
  54.                 if chest.getItem(i) then
  55.                         if chest.getItem(i) ~= nil and string.find(chest.getItem(i).getMetadata().name, "blood_orb") then
  56.                                 print("found")
  57.                                 return
  58.                         end
  59.                 end
  60.         end
  61.         return 0
  62. end
  63.  
  64. function putOrbInAltar()
  65.         -- Only check if there is *any* item there. We may be crafting something
  66.         -- if the orb is there already, there's no point in running this yet anyway.
  67.         if getAltarItem() == nil then
  68.                 if not chestHasOrb() then
  69.                         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?")
  70.                 end
  71.                 print("Moving Blood Orb back into the altar to charge LP")
  72.                 altar.pullItems(altarBufferChestDir, getChestOrbSlot(), 1)
  73.                 sleep(0.5)
  74.         end
  75. end
  76.  
  77. function removeOrbFromAltar()
  78.         if altarHasOrb() then
  79.                 altar.pushItem(altarBufferChestDir, 1)
  80.                 sleep(0.5)
  81.         end
  82. end
  83.  
  84. function findCraftingRecipe(stack)
  85.         local itemId = getItemId(stack)
  86.         if itemId then
  87.                 for i=1, #recipes do
  88.                         if recipes[i].source == itemId then
  89.                                 if recipes[i].lp <= altar.getTanks()[1].amount then
  90.                                         return recipes[i]
  91.                                 end
  92.                         end
  93.                 end
  94.         end
  95.         return nil
  96. end
  97.  
  98. function getItemId(stack)
  99.         if stack then
  100.                 if stack.dmg ~= nil and stack.dmg ~= 0 then
  101.                         return stack.id .. ":" .. stack.dmg
  102.                 else
  103.                         return stack.id
  104.                 end
  105.         end
  106.         return nil
  107. end
  108.  
  109. function craftSlate()
  110.         for i=1, chest.size() do
  111.                 -- Figure out if we have anything to craft
  112.                 local stack = chest.getItem(i)
  113.                 local recipe = findCraftingRecipe(stack)
  114.                 if stack ~= nil then
  115.                         if recipe ~= nil then
  116.                                 removeOrbFromAltar()
  117.                                 print("Transmuting " .. stack.display_name)
  118.                                 altar.pullItems(altarBufferChestDir, i, 1)
  119.                                 --sleep(0.5)
  120.                                 while getItemId(altar.getStackInSlot(1)) ~= recipe.final do
  121.                                         sleep(0.1)
  122.                                 end
  123.                                 --sleep(0.5)
  124.                                 altar.pushItem(altarOutputChestDir, 1)
  125.                                 --sleep(0.5)
  126.                                 return true
  127.                         end
  128.                 end
  129.         end
  130.         return false
  131. end
  132.  
  133.  
  134. while true do
  135.         if not craftSlate() then
  136.                 putOrbInAltar()
  137.                 sleep(1)
  138.         end
  139. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement