Inkkubus

Blutalter

Sep 5th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.58 KB | None | 0 0
  1. -- BM Altar Automation by Apoc
  2. -- v1.0 - 2/20/2016
  3. -- Initial Release
  4.  
  5. local altarPeripheralName = "tealtar_0"
  6. local altarBufferChestDir = "west"
  7. local altarBufferChestName = "crystal_1"
  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.getStackInSlot(1)
  35. if not stack then return nil end
  36. return stack.name
  37. end
  38.  
  39. function altarHasOrb()
  40. local item = getAltarItem()
  41. if item ~= nil and string.find(item, "BloodOrb") 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.getInventorySize() do
  54. if chest.getStackInSlot(i) then
  55. if string.find(chest.getStackInSlot(i).name, "BloodOrb") then
  56. return i
  57. end
  58. end
  59. end
  60. return 0
  61. end
  62.  
  63. function putOrbInAltar()
  64. -- Only check if there is *any* item there. We may be crafting something
  65. -- if the orb is there already, there's no point in running this yet anyway.
  66. if getAltarItem() == nil then
  67. if not chestHasOrb() then
  68. 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?")
  69. end
  70. print("Moving Blood Orb back into the altar to charge LP")
  71. altar.pullItem(altarBufferChestDir, getChestOrbSlot(), 1)
  72. sleep(0.5)
  73. end
  74. end
  75.  
  76. function removeOrbFromAltar()
  77. if altarHasOrb() then
  78. altar.pushItem(altarBufferChestDir, 1)
  79. sleep(0.5)
  80. end
  81. end
  82.  
  83. function findCraftingRecipe(stack)
  84. local itemId = getItemId(stack)
  85. if itemId then
  86. for i=1, #recipes do
  87. if recipes[i].source == itemId then
  88. return recipes[i]
  89. end
  90. end
  91. end
  92. return nil
  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 craftSlate()
  107. for i=1, chest.getInventorySize() do
  108. -- Figure out if we have anything to craft
  109. local stack = chest.getStackInSlot(i)
  110. local recipe = findCraftingRecipe(stack)
  111. if stack ~= nil then
  112. if recipe ~= nil then
  113. removeOrbFromAltar()
  114. print("Transmuting " .. stack.display_name)
  115. altar.pullItem(altarBufferChestDir, i, 1)
  116. --sleep(0.5)
  117. while getItemId(altar.getStackInSlot(1)) ~= recipe.final do
  118. sleep(0.1)
  119. end
  120. --sleep(0.5)
  121. altar.pushItem(altarOutputChestDir, 1)
  122. --sleep(0.5)
  123. return true
  124. end
  125. end
  126. end
  127. return false
  128. end
  129.  
  130.  
  131. while true do
  132. if not craftSlate() then
  133. putOrbInAltar()
  134. sleep(1)
  135. end
  136. end
Add Comment
Please, Sign In to add comment