Advertisement
Guest User

Untitled

a guest
May 31st, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- BM Altar Automation by Apoc
  2. -- v1.0 - 2/20/2016
  3. --              Initial Release
  4.  
  5. local altarPeripheralName = "tealtar_0"
  6. local altarBufferChestDir = "east"
  7. local altarBufferChestName = "crystal_0"
  8. local altarOutputChestDir = "west"
  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. {source="Botania:manaResource:1", final="AWWayofTime:telepositionFocus", lp=30000},
  27. -- Add other recipes here if you want.
  28. }
  29.  
  30. local altar = peripheral.wrap(altarPeripheralName)
  31. local chest = peripheral.wrap(altarBufferChestName)
  32.  
  33.  
  34. function getAltarItem()
  35.   local stack = altar.getStackInSlot(1)
  36.   if not stack then return nil end
  37.   return stack.name
  38. end
  39.  
  40. function altarHasOrb()
  41.   local item = getAltarItem()
  42.   if item ~= nil and string.find(item, "BloodOrb") then
  43.         return true
  44.   else
  45.         return false
  46.   end
  47. end
  48.  
  49. function chestHasOrb()
  50.         return getChestOrbSlot() ~= 0
  51. end
  52.  
  53. function getChestOrbSlot()
  54.         for i=1, chest.getInventorySize() do
  55.                 if chest.getStackInSlot(i) then
  56.                         if string.find(chest.getStackInSlot(i).name, "BloodOrb") then
  57.                                 return i
  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.pullItem(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.                                 return recipes[i]
  90.                         end
  91.                 end
  92.         end
  93.         return nil
  94. end
  95.  
  96. function getItemId(stack)
  97.         if stack then
  98.                 if stack.dmg ~= nil and stack.dmg ~= 0 then
  99.                         return stack.id .. ":" .. stack.dmg
  100.                 else
  101.                         return stack.id
  102.                 end
  103.         end
  104.         return nil
  105. end
  106.  
  107. function craftSlate()
  108.         for i=1, chest.getInventorySize() do
  109.                 -- Figure out if we have anything to craft
  110.                 local stack = chest.getStackInSlot(i)
  111.                 local recipe = findCraftingRecipe(stack)
  112.                 if stack ~= nil then
  113.                         if recipe ~= nil then
  114.                                 removeOrbFromAltar()
  115.                                 print("Transmuting " .. stack.display_name)
  116.                                 altar.pullItem(altarBufferChestDir, i, 1)
  117.                                 --sleep(0.5)
  118.                                 while getItemId(altar.getStackInSlot(1)) ~= recipe.final do
  119.                                         sleep(0.1)
  120.                                 end
  121.                                 --sleep(0.5)
  122.                                 altar.pushItem(altarOutputChestDir, 1)
  123.                                 --sleep(0.5)
  124.                                 return true
  125.                         end
  126.                 end
  127.         end
  128.         return false
  129. end
  130.  
  131.  
  132. while true do
  133.         if not craftSlate() then
  134.                 putOrbInAltar()
  135.                 sleep(1)
  136.         end
  137. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement