NeoGriever

Untitled

Aug 15th, 2022 (edited)
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.14 KB | None | 0 0
  1. -- Config
  2. deepStorageName = "deep_storage_unit_0"
  3. bloodAltarName = "tealtar_2"
  4. mainMonitorIndex = 3
  5. craftMonitorIndex = 4
  6. switchMonitorIndex = 5
  7.  
  8. -- Global Peripheral Vars
  9. deepStorage = nil
  10. bloodAltar = nil
  11. mainMonitor = nil
  12. craftMonitor = nil
  13. switchMonitor = nil
  14. function initializePeripheral()
  15. if deepStorage == nil then
  16. deepStorage = peripheral.wrap("deep_storage_unit_0")
  17. end
  18. if bloodAltar == nil then
  19. bloodAltar = peripheral.wrap("tealtar_2")
  20. end
  21. if mainMonitor == nil then
  22. mainMonitor = peripheral.wrap("monitor_" .. tostring(mainMonitorIndex))
  23. end
  24. if craftMonitor == nil then
  25. craftMonitor = perpheral.wrap("monitor_4" .. tostring(craftMonitorIndex))
  26. end
  27. if switchMonitor == nil then
  28. switchMonitor = peripheral.wrap("monitor_5" .. tostring(switchMonitorIndex))
  29. end
  30. end
  31.  
  32. -- Global Storage Vars
  33. essence = 0
  34. currentInAltar = { id = "", name = "", amount = 0 }
  35. waitFor = { id = "", name = "", amount = 0 }
  36.  
  37. function updateEssenceStorage()
  38. while true do
  39. essence = bloodAltar.getInfo().contents.amount
  40. updateBloodAltairItem()
  41. sleep(0.1)
  42. end
  43. end
  44. function updateBloodAltairItem()
  45. local stackInSlot = bloodAltar.getStackInSlot(1)
  46. if stackInSlot ~= nil then
  47. currentInAltar = { name = stackInSlot.display_name, id = stackInSlot.id, amount = stackInSlot.qty }
  48. if waitFor.amount > 0 then
  49. if fits(waitFor, currentInAltar) == true then
  50. -- TODO: Move to Output
  51. currentInAltar = { name = "", id = "", amount = 0 }
  52. waitFor = { name = "", id = "", amount = 0 }
  53. end
  54. end
  55. else
  56. currentInAltar = { id = "", name = "", amount = 0 }
  57. end
  58. sleep(0.1)
  59. end
  60. function craft(recipe, maxAmount)
  61. if waitFor.amount == 0 then
  62. possible = math.floor(essence / recipe.requirements.essenceFull)
  63. craftAmount = maxAmount or possible
  64. if amount > 0 then
  65. waitFor = { name = recipe.result.name, id = recipe.result.id, amount = craftAmount }
  66. end
  67. end
  68. end
  69.  
  70. -- Recipes
  71. recipes = {
  72. {result = {name = "Leere Tafel", id = "AWWayofTime:blankSlate", amount = 1}, requirements = {name = "Stein", id = "minecraft:stone", amount = 1, essence = 1000, essenceFull = 1000},
  73. {result = {name = "Verst. Tafel", id = "AWWayofTime:reinforcedSlate", amount = 1}, requirements = {name = "Leere Tafel", id = "AWWayofTime:blankSlate", amount = 1, essence = 2000, essenceFull = 3000},
  74. {result = {name = "Erf. Tafel", id = "AWWayofTime:imbuedSlate", amount = 1}, requirements = {name = "Verst. Tafel", id = "AWWayofTime:reinforcedSlate", amount = 1, essence = 5000, essenceFull = 8000},
  75. {result = {name = "Daem. Tafel", id = "AWWayofTime:demonicSlate", amount = 1}, requirements = {name = "Erf. Tafel", id = "AWWayofTime:imbuedSlate", amount = 1, essence = 15000, essenceFull = 23000},
  76. {result = {name = "Eth. Slate", id = "AWWayofTime:etherealSlate", amount = 1}, requirements = {name = "Daem. Tafel", id = "AWWayofTime:demonicSlate", amount = 1, essence = 30000, essenceFull = 53000}
  77. }
  78. selectedRecipe = 1
  79.  
  80. -- Help Functions
  81. function fits(what1, what2)
  82. if (what1.id == what2.id) and (what1.amount == what2.amount) then
  83. return true
  84. else
  85. return false
  86. end
  87. end
  88.  
  89. -- Monitor
  90. function updateMainMonitor()
  91. sleep(0.3)
  92. mainMonitor.setBackgroundColor(colors.black)
  93. mainMonitor.setTextColor(colors.white)
  94. mainMonitor.setTextScale(1.5)
  95. mainMonitor.clear()
  96. while true do
  97. for iRec = 1, #recipes, 1 do
  98. local recipe = recipes[iRec]
  99. local amnt = math.floor(essence / recipe.requirements.essenceFull)
  100. local line = " "
  101. if selectedRecipe == iRec then
  102. line = "> "
  103. end
  104. line = line .. tostring(amnt) .. 'x ' .. recipe.name
  105. if amnt >= 1 then
  106. mainMonitor.setTextColor(colors.lime)
  107. else
  108. mainMonitor.setTextColor(colors.gray)
  109. end
  110. w, h = mainMonitor.getSize()
  111. local offx = (iRec % (h - 3))
  112. local offy = math.floor(iRec / (h - 3)) * 22
  113. mainMonitor.setCursorPos(2 + offx, 1 + offy)
  114. end
  115. sleep(0.2)
  116. end
  117. end
  118. function updateSwitchMonitor()
  119. switchMonitor.setTextScale(5)
  120. w, h = switchMonitor.getSize()
  121. if switchMonitor == true then
  122. switchMonitor.setBackgroundColor(colors.lime)
  123. switchMonitor = false
  124. else
  125. switchMonitor.setBackgroundColor(colors.yellow)
  126. end
  127. for iV = 1, h, 1 do
  128. local ln = ""
  129. for iH = 1, w, 1 do
  130. ln = ln .. " "
  131. end
  132. switchMonitor.write(ln)
  133. end
  134. end
  135. function updateCraftMonitor()
  136. craftMonitor.setTextScale(5)
  137. w, h = craftMonitor.getSize()
  138. if craftMonitor == true then
  139. craftMonitor.setBackgroundColor(colors.lime)
  140. craftMonitor = false
  141. else
  142. craftMonitor.setBackgroundColor(colors.yellow)
  143. end
  144. for iV = 1, h, 1 do
  145. local ln = ""
  146. for iH = 1, w, 1 do
  147. ln = ln .. " "
  148. end
  149. craftMonitor.write(ln)
  150. end
  151. end
  152.  
  153. -- Click Event
  154. function onClick()
  155. while true do
  156. event, side, x, y = os.pullEvent("monitor_touch")
  157. print(event .. " / " .. side .. " / " .. x .. " / " .. y)
  158. end
  159. end
  160.  
  161. parallel.waitForAll(updateEssenceStorage, updateMainMonitor, onClick)
Advertisement
Add Comment
Please, Sign In to add comment