Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Config
- deepStorageName = "deep_storage_unit_0"
- bloodAltarName = "tealtar_2"
- mainMonitorIndex = 3
- craftMonitorIndex = 4
- switchMonitorIndex = 5
- -- Global Peripheral Vars
- deepStorage = nil
- bloodAltar = nil
- mainMonitor = nil
- craftMonitor = nil
- switchMonitor = nil
- function initializePeripheral()
- if deepStorage == nil then
- deepStorage = peripheral.wrap("deep_storage_unit_0")
- end
- if bloodAltar == nil then
- bloodAltar = peripheral.wrap("tealtar_2")
- end
- if mainMonitor == nil then
- mainMonitor = peripheral.wrap("monitor_" .. tostring(mainMonitorIndex))
- end
- if craftMonitor == nil then
- craftMonitor = perpheral.wrap("monitor_4" .. tostring(craftMonitorIndex))
- end
- if switchMonitor == nil then
- switchMonitor = peripheral.wrap("monitor_5" .. tostring(switchMonitorIndex))
- end
- end
- -- Global Storage Vars
- essence = 0
- currentInAltar = { id = "", name = "", amount = 0 }
- waitFor = { id = "", name = "", amount = 0 }
- function updateEssenceStorage()
- while true do
- essence = bloodAltar.getInfo().contents.amount
- updateBloodAltairItem()
- sleep(0.1)
- end
- end
- function updateBloodAltairItem()
- local stackInSlot = bloodAltar.getStackInSlot(1)
- if stackInSlot ~= nil then
- currentInAltar = { name = stackInSlot.display_name, id = stackInSlot.id, amount = stackInSlot.qty }
- if waitFor.amount > 0 then
- if fits(waitFor, currentInAltar) == true then
- -- TODO: Move to Output
- currentInAltar = { name = "", id = "", amount = 0 }
- waitFor = { name = "", id = "", amount = 0 }
- end
- end
- else
- currentInAltar = { id = "", name = "", amount = 0 }
- end
- sleep(0.1)
- end
- function craft(recipe, maxAmount)
- if waitFor.amount == 0 then
- possible = math.floor(essence / recipe.requirements.essenceFull)
- craftAmount = maxAmount or possible
- if amount > 0 then
- waitFor = { name = recipe.result.name, id = recipe.result.id, amount = craftAmount }
- end
- end
- end
- -- Recipes
- recipes = {
- {result = {name = "Leere Tafel", id = "AWWayofTime:blankSlate", amount = 1}, requirements = {name = "Stein", id = "minecraft:stone", amount = 1, essence = 1000, essenceFull = 1000},
- {result = {name = "Verst. Tafel", id = "AWWayofTime:reinforcedSlate", amount = 1}, requirements = {name = "Leere Tafel", id = "AWWayofTime:blankSlate", amount = 1, essence = 2000, essenceFull = 3000},
- {result = {name = "Erf. Tafel", id = "AWWayofTime:imbuedSlate", amount = 1}, requirements = {name = "Verst. Tafel", id = "AWWayofTime:reinforcedSlate", amount = 1, essence = 5000, essenceFull = 8000},
- {result = {name = "Daem. Tafel", id = "AWWayofTime:demonicSlate", amount = 1}, requirements = {name = "Erf. Tafel", id = "AWWayofTime:imbuedSlate", amount = 1, essence = 15000, essenceFull = 23000},
- {result = {name = "Eth. Slate", id = "AWWayofTime:etherealSlate", amount = 1}, requirements = {name = "Daem. Tafel", id = "AWWayofTime:demonicSlate", amount = 1, essence = 30000, essenceFull = 53000}
- }
- selectedRecipe = 1
- -- Help Functions
- function fits(what1, what2)
- if (what1.id == what2.id) and (what1.amount == what2.amount) then
- return true
- else
- return false
- end
- end
- -- Monitor
- function updateMainMonitor()
- sleep(0.3)
- mainMonitor.setBackgroundColor(colors.black)
- mainMonitor.setTextColor(colors.white)
- mainMonitor.setTextScale(1.5)
- mainMonitor.clear()
- while true do
- for iRec = 1, #recipes, 1 do
- local recipe = recipes[iRec]
- local amnt = math.floor(essence / recipe.requirements.essenceFull)
- local line = " "
- if selectedRecipe == iRec then
- line = "> "
- end
- line = line .. tostring(amnt) .. 'x ' .. recipe.name
- if amnt >= 1 then
- mainMonitor.setTextColor(colors.lime)
- else
- mainMonitor.setTextColor(colors.gray)
- end
- w, h = mainMonitor.getSize()
- local offx = (iRec % (h - 3))
- local offy = math.floor(iRec / (h - 3)) * 22
- mainMonitor.setCursorPos(2 + offx, 1 + offy)
- end
- sleep(0.2)
- end
- end
- function updateSwitchMonitor()
- switchMonitor.setTextScale(5)
- w, h = switchMonitor.getSize()
- if switchMonitor == true then
- switchMonitor.setBackgroundColor(colors.lime)
- switchMonitor = false
- else
- switchMonitor.setBackgroundColor(colors.yellow)
- end
- for iV = 1, h, 1 do
- local ln = ""
- for iH = 1, w, 1 do
- ln = ln .. " "
- end
- switchMonitor.write(ln)
- end
- end
- function updateCraftMonitor()
- craftMonitor.setTextScale(5)
- w, h = craftMonitor.getSize()
- if craftMonitor == true then
- craftMonitor.setBackgroundColor(colors.lime)
- craftMonitor = false
- else
- craftMonitor.setBackgroundColor(colors.yellow)
- end
- for iV = 1, h, 1 do
- local ln = ""
- for iH = 1, w, 1 do
- ln = ln .. " "
- end
- craftMonitor.write(ln)
- end
- end
- -- Click Event
- function onClick()
- while true do
- event, side, x, y = os.pullEvent("monitor_touch")
- print(event .. " / " .. side .. " / " .. x .. " / " .. y)
- end
- end
- parallel.waitForAll(updateEssenceStorage, updateMainMonitor, onClick)
Advertisement
Add Comment
Please, Sign In to add comment