rkinasz

altar.lua

Feb 7th, 2022 (edited)
1,299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 20.79 KB | None | 0 0
  1. --TO DO
  2.  
  3. --[[
  4.  CREATE an advanced mode that can handle crafting larger stack sizes (e.g 16 slates at once)
  5.  Calculate LP drain per item
  6.  Calculate LP gain in altar
  7.  Calculate crafting speed
  8.  calculate max stack size for requested item
  9. ]]
  10.  
  11. --variables
  12.  
  13. confFile  = "altar.conf" -- config file location. used to save info on the crafting mode and which recipe to craft
  14. recipeFile = "slates.conf" -- file which holds all recipes
  15.  
  16. delay = 0.1 -- delay between crafts /  checks
  17. enableAdvancedMode = true
  18.  
  19. -- your current altar setup -- currently only used in advanced mode except for the capacity runes which are used for the bloodbar
  20. altarRunes = {
  21.   Capacity = 5,
  22.   AugmentedCapacity = 0,
  23.   Sacrifice = 0,
  24.   SelfSacrifice = 0,
  25.   Speed = 0,
  26.   Acceleration = 0,
  27.   Charging = 0,
  28.   Displacement = 24,
  29.   Orb = 0
  30. }
  31.  
  32. --extra blood needed in altar to craft (lag may cause it to insert item too soon otherwise)
  33. --set this to 0 if using max altar capacity and cannot add runes of capacity
  34. threshold = 100
  35. altarBaseCapacity = 10000
  36.  
  37. enableMonitor = true -- set to false if not using monitor
  38. enableOutput = true -- set this to true if output should go into output chest rather then back into the input chest
  39. enableOrbContainer = true -- set to true if orbs have their own container
  40.  
  41. --change this to storage container used for slates / materials - use peripheral.getType(side) for the correct name
  42. outputContainerPeripheral = "entangled:tile_3" -- altar output items
  43. containerPeripheral = "entangled:tile_0" -- main input
  44. orbContainerPeripheral = "entangled:tile_2" -- container for storing orbs
  45. altarPeripheral = "entangled:tile_1"
  46.  
  47. --list of available recipes, feel free to add recipes make sure to use exact item names
  48. --edit to your packs needs
  49. slates = {
  50.     blankSlate = {
  51.      amount = 1229,
  52.      item = "botania:livingrock",
  53.      result = "bloodmagic:blankslate"
  54.     },
  55.  
  56.     reinforcedSlate = {
  57.      amount =  2000,
  58.      item = "bloodmagic:blankslate",
  59.      result = "bloodmagic:reinforcedslate"
  60.     },
  61.  
  62.     lifeBucket = {
  63.         amount = 1000,
  64.         item = "minecraft:bucket",
  65.         result = "bloodmagic:life_essence_bucket"
  66.     },
  67.  
  68.     imbuedSlate = {
  69.      amount = 5000,
  70.      item = "bloodmagic:reinforcedslate",
  71.      result = "bloodmagic:infusedslate"
  72.      },
  73.  
  74.      demonicSlate = {
  75.       amount = 15000,
  76.       item = "bloodmagic:infusedslate",
  77.       result = "bloodmagic:demonslate"
  78.      },
  79.  
  80.      Weakcrystal = {
  81.          amount = 10000,
  82.          item = "bloodmagic:lavacrystal",
  83.          result = "bloodmagic:activationcrystalweak"
  84.      },
  85.  
  86.      Water = {
  87.          amount = 1000,
  88.          item = "minecraft:lapis_block",
  89.          result = "bloodmagic:waterscribetool"
  90.      },
  91.  
  92.      Earth = {
  93.          amount = 1000,
  94.          item = "minecraft:obsidian",
  95.          result = "bloodmagic:earthscribetool"
  96.      },
  97.  
  98.      Air = {
  99.          amount = 1000,
  100.          item = "minecraft:ghast_tear",
  101.          result = "bloodmagic:airscribetool"
  102.      },
  103.  
  104.      Fire = {
  105.          amount = 1000,
  106.          item = "minecraft:magma_cream",
  107.          result = "bloodmagic:firescribetool"
  108.      },
  109.  
  110.      etherealSlate = {
  111.       amount = 20000,
  112.       item = "bloodmagic:demonslate",
  113.       result = "bloodmagic:etherealslate"
  114.     },
  115.  
  116.     steel =  {
  117.       amount = 1000,
  118.       item = "minecraft:iron_ingot",
  119.       result = "emendatusenigmatica:steel_ingot"
  120.     },
  121.  
  122.     chargedCertusQuartzAE2 = {
  123.       amount = 2904,
  124.       item = "appliedenergistics2:certus_quartz_crystal",
  125.       result = "appliedenergistics2:charged_certus_quartz_crystal"
  126.     },
  127.  
  128.     chargedCertusQuartzEnig = {
  129.       amount = 2904,
  130.       item = "emendatusenigmatica:certus_quartz_gem",
  131.       result = "emendatusenigmatica:charged_certus_quartz_gem"
  132.     },
  133.  
  134.  
  135.     eliteCoil = {
  136.       amount = 2000,
  137.       item = "mekanism:alloy_reinforced",
  138.       result = "ironjetpacks:elite_coil"
  139.     },
  140.  
  141.     ultimateCoil = {
  142.       amount = 3000,
  143.       item = "botania:terrasteel_ingot",
  144.       result = "ironjetpacks:ultimate_coil"
  145.     },
  146.  
  147.     photovoltaicCell = {
  148.       amount = 2000,
  149.       item = "solarflux:photovoltaic_cell_2",
  150.       result  = "solarflux:photovoltaic_cell_3"
  151.     },
  152.  
  153.     basicCoil = {
  154.       amount = 1000,
  155.       item = "mekanism:enriched_iron",
  156.       result = "ironjetpacks:basic_coil"
  157.     },
  158.  
  159.     soulSnare = {
  160.       amount = 500,
  161.       item = "minecraft:string",
  162.       result = "bloodmagic:soulsnare"
  163.     },
  164.    
  165.     hopGraphiteDust = {
  166.       amount = 2000,
  167.       item = "emendatusenigmatica:coke_dust",
  168.       result = "immersiveengineering:dust_hop_graphite"
  169.     },
  170.  
  171.  
  172. }
  173.  
  174. --highest priority orb should be listed first
  175. orbs = {
  176.   "bloodmagic:masterbloodorb",
  177.   "bloodmagic:magicianbloodorb",
  178.   "bloodmagic:apprenticebloodorb",
  179.   "bloodmagic:weakbloodorb"
  180. }
  181.  
  182. -------------------------------------------------------------------------------
  183.  
  184. --- DO NOT EDIT BEYOND THIS POINT
  185.  
  186. --------------------------------------------------------------------------------
  187.  
  188. os.loadAPI("API/UIUtils.lua")
  189. os.loadAPI("API/itemUtils.lua")
  190. os.loadAPI("API/peripheralUtils.lua")
  191.  
  192. --default slate
  193. currentSlate = "blankSlate"
  194.  
  195. craftingModes = {"Any", "Recursive", "Exact"}
  196. currentCraftingMode = craftingModes[1]
  197.  
  198. altarCapacity =  math.floor(((1 + 0.20 * altarRunes.Capacity) * math.pow(1.1, altarRunes.AugmentedCapacity * math.pow(0.99, math.abs(altarRunes.AugmentedCapacity - altarRunes.Capacity)))) * altarBaseCapacity)
  199.  
  200. altar = nil
  201. monitor = nil
  202. chest = nil
  203. outputChest = nil
  204. orbChest = nil
  205.  
  206. --lists of buttons on monitor
  207. pageSize = 9
  208.  
  209. paused = false
  210. enableOrb = true -- set to true if bloodorb should be put in altar when no crafting available
  211.  
  212.  
  213. UI = UIUtils.UIClass.new()
  214. CalibrateUI = UIUtils.UIClass.new()
  215.  
  216. altarLog = UIUtils.LogClass.new()
  217. navBar = UIUtils.NavbarClass.new()
  218. nextButton = UIUtils.ButtonClass.new()
  219. previousButton = UIUtils.ButtonClass.new()
  220.  
  221. calibrationProgressBar = UIUtils.ProgressBarClass.new()
  222. calibrationLabel = UIUtils.TextClass.new()
  223. calibrationSelectButton = UIUtils.ButtonClass.new()
  224.  
  225. pauseButton = UIUtils.ButtonClass.new()
  226. pauseText = UIUtils.TextClass.new()
  227.  
  228. orbButton = UIUtils.ButtonClass.new()
  229.  
  230. currentUI = UI
  231.  
  232. --sets the current slate to config
  233. function writeToConfig ()
  234.     file = io.open(confFile,"w")
  235.     file:write ("currentSlate:" .. currentSlate .. "\n")
  236.     file:write ("currentMode:" .. currentCraftingMode .. "\n")
  237.     file:write ("paused:" .. tostring(paused) .. "\n")
  238.     file:write ("orbMode:" .. tostring(enableOrb) .. "\n")
  239.     file:close()
  240. end
  241.  
  242. --reads the current slate form config
  243. function readFromConfig ()
  244.     file = fs.open(confFile, "r")
  245.     config = {}
  246.  
  247.     --generate first time file
  248.     if not file then
  249.       writeToConfig()
  250.       file = fs.open(confFile, "r")
  251.     end
  252.  
  253.     for line in file.readLine do
  254.         for k, v in string.gmatch(line, "(%w+):(%w+)") do
  255.           config[k] = v
  256.         end
  257.     end
  258.     file:close()
  259.     currentSlate = config["currentSlate"]
  260.     currentCraftingMode = config["currentMode"]
  261.     paused = (config["paused"] == "true")
  262.     enableOrb = (config["orbMode"] == "true")
  263.     if not currentCraftingMode then currentCraftingMode = craftingModes[1] end
  264.     if not currentSlate then currentSlate = "blankSlate" end
  265. end
  266.  
  267. --changes the slate type and updates the config
  268. function setSlate (slate)
  269.   currentSlate = slate
  270.   term.setTextColor(colors.blue)
  271.   term.write("Setting recipe to: ")
  272.   if enableMonitor then
  273.     altarLog.addMessage("Set recipe: " .. slate, 4)
  274.     navBar.options[2] = slate
  275.   end
  276.   term.setTextColor(colors.white)
  277.   print(slate)
  278.   writeToConfig()
  279. end
  280.  
  281. function setCraftMode (mode)
  282.   currentCraftingMode = mode
  283.   term.setTextColor(colors.blue)
  284.   term.write("setting craftingMode to: ")
  285.   if enableMonitor then
  286.     altarLog.addMessage("Set mode:  " .. mode, 4)
  287.     navBar.options[1] = mode
  288.   end
  289.   term.setTextColor(colors.white)
  290.   print(mode)
  291.   writeToConfig()
  292. end
  293.  
  294. function setupPeripherals()
  295.   altar = peripheralUtils.wrapPeripheral(altarPeripheral, true)
  296.   chest = peripheralUtils.wrapPeripheral(containerPeripheral, true)
  297.   if enableMonitor then
  298.     monitor = peripheralUtils.wrapPeripheral("monitor", true)
  299.   end
  300.   if enableOutput then
  301.     outputChest = peripheralUtils.wrapPeripheral(outputContainerPeripheral, true)
  302.   end
  303.   if enableOrb and enableOrbContainer then
  304.     orbChest = peripheralUtils.wrapPeripheral(orbContainerPeripheral, true)
  305.   end
  306. end
  307.  
  308. --checks if there are any orbs available
  309. function findOrb(container)
  310.   for k,v in pairs(orbs) do
  311.     if itemUtils.findItem(container, v) then
  312.       return v
  313.     end
  314.   end
  315. end
  316.  
  317. function hasNoItemsToCraft ()
  318.   if currentCraftingMode == craftingModes[1] then
  319.     for k,v in pairs(slates) do
  320.       if hasItemForCraft(v) then
  321.         return false
  322.       end
  323.     end
  324.     return true
  325.   elseif currentCraftingMode == craftingModes[2] then
  326.     if itemUtils.findItem(chest, slates[currentSlate]["item"]) then
  327.       return false
  328.     else
  329.       r = findCraftRequirement(slates[currentSlate])
  330.       while r do
  331.         slot = itemUtils.findItem(chest, r["item"])
  332.         if slot then
  333.           return false
  334.         else
  335.           r = findCraftRequirement(r)
  336.         end
  337.       end
  338.     end
  339.   elseif currentCraftingMode == craftingModes[3] then
  340.     if itemUtils.findItem(chest, slates[currentSlate]["item"]) then
  341.       return false
  342.     end
  343.   else
  344.     return true
  345.   end
  346.   return true
  347. end
  348.  
  349. function pullOrbFromAltar ()
  350.   local o = findOrb(altar)
  351.   if o then
  352.     if enableOrbContainer then
  353.       itemUtils.pushItems(altar, orbChest, itemUtils.findItem(altar, o),1)
  354.     else
  355.       itemUtils.pushItems(altar, chest, itemUtils.findItem(altar, o),1)
  356.     end
  357.   end
  358. end
  359.  
  360. function insertOrbInAltar ()
  361.   if enableOrbContainer then
  362.     if findOrb(orbChest) then
  363.       itemUtils.pushItems(orbChest, altar,itemUtils.findItem(orbChest, findOrb(orbChest)),1)
  364.     end
  365.   else
  366.     if findOrb(chest) then
  367.       itemUtils.pushItems(chest, altar,itemUtils.findItem(chest, findOrb(chest)),1)
  368.     end
  369.   end
  370. end
  371.  
  372. --inserts item into altar
  373. function insertItemToAltar (item, amount)
  374.   itemUtils.pushItems(chest, altar,  itemUtils.findItem(chest, item), amount)
  375. end
  376.  
  377. --removes item from altar
  378. function pullItemFromAltar (item, amount, isRecursive)
  379.   if enableOutput and ((currentCraftingMode == craftingModes[1] or item == slates[currentSlate]["result"]) or not isRecursive) then
  380.     itemUtils.pushItems(altar, outputChest, itemUtils.findItem(altar, item), amount)
  381.   else
  382.     itemUtils.pushItems(altar, chest, itemUtils.findItem(altar, item), amount)
  383.   end
  384. end
  385.  
  386. --returns the amount of blood in altar
  387. function getBlood ()
  388.   t = altar.tanks()
  389.   if table.getn(t) > 0 then
  390.     if t[1] then
  391.       return t[1]["amount"]
  392.     end
  393.   end
  394.   return 0;
  395. end
  396.  
  397. --checks if item and blood to craft recipe
  398. function canCraft(slate)
  399.   if itemUtils.findItem(chest, slate["item"]) and getBlood() >= (slate["amount"] + threshold) then
  400.     return true
  401.   else
  402.     return false
  403.   end
  404. end
  405.  
  406. --checks if the item needed for recipe is available in chest
  407. function hasItemForCraft (slate)
  408.   if itemUtils.findItem(chest, slate["item"]) then
  409.     return true
  410.   else
  411.     return false
  412.   end
  413. end
  414.  
  415. --checks the list of slates for available item
  416. function findCraftRequirement (slate)
  417.   for k,v in pairs(slates) do
  418.     if v["result"] == slate["item"] then
  419.       return v
  420.     end
  421.   end
  422.   return nil
  423. end
  424.  
  425. --attempts to craft a recipe, and if not possible attempts to craft needed items
  426. function craftRecursive (slate, isRecursive)
  427.   if hasItemForCraft(slate) then
  428.     craft(slate, isRecursive)
  429.   else
  430.     requirement = findCraftRequirement(slate)
  431.     if requirement then
  432.       craftRecursive(requirement, true)
  433.     end
  434.   end
  435. end
  436.  
  437. --crafts a specific recipe
  438. function craft(slate, isRecursive)
  439.   if canCraft(slate) then
  440.     --inserts the item
  441.  
  442.     insertItemToAltar(slate["item"],1)
  443.     local startTime = os.time()
  444.     --crafting
  445.     term.setTextColor(colors.green)
  446.     term.write("crafting: ")
  447.     if enableMonitor then
  448.       altarLog.addMessage("Crafting: " .. slate["result"],1)
  449.     end
  450.     term.setTextColor(colors.white)
  451.     print(slate["result"])
  452.  
  453.     done = false
  454.     local endTime = startTime
  455.     while not done do
  456.       if itemUtils.findItem(altar, slate["result"]) then
  457.         done = true
  458.         endTime = os.time()
  459.       else
  460.         os.sleep(delay)
  461.       end
  462.     end
  463.     --extract result
  464.     pullItemFromAltar(slate["result"],1, isRecursive)
  465.     if enableMonitor then
  466.       altarLog.addMessage("Finished crafting: " .. slate["result"], 3)
  467.     end
  468.     --print(endTime - startTime)
  469.     return true
  470.   else
  471.     return false
  472.   end
  473. end
  474.  
  475. --checks the list for any available crafts
  476. function craftAny()
  477.   for k,v in pairs (slates) do
  478.     if canCraft(v) then
  479.       craft(v)
  480.       break
  481.     end
  482.   end
  483. end
  484.  
  485. function handleCrafting ()
  486.   while true do
  487.     if not paused then
  488.       if hasNoItemsToCraft() and enableOrb then
  489.         if not findOrb(altar) then
  490.           insertOrbInAltar()
  491.         end
  492.       else
  493.         if enableOrb and findOrb(altar) then
  494.           pullOrbFromAltar()
  495.         end
  496.         if currentCraftingMode == craftingModes[1] then
  497.           craftAny()
  498.         elseif currentCraftingMode == craftingModes[2] then
  499.           craftRecursive(slates[currentSlate])
  500.         elseif currentCraftingMode == craftingModes[3] then
  501.           craft(slates[currentSlate])
  502.         end
  503.         os.sleep(delay)
  504.       end
  505.     else
  506.       os.sleep(refreshRate)
  507.  
  508.     end
  509.  
  510.   end
  511. end
  512.  
  513. function getTableSize (t)
  514.   local s = 0
  515.   for k,v in pairs(t) do
  516.     s = s + 1
  517.   end
  518.   return s
  519. end
  520.  
  521. function getMCTicks ()
  522.   return (os.time() * 1000 + 18000)%24000
  523. end
  524.  
  525. function calibrateBloodGain ()
  526.   paused = true
  527.   pauseButton.active = paused
  528.  
  529.   local startingBlood = getBlood()
  530.   local prevTicks = getMCTicks()
  531.   local ticksPassed = 0
  532.   local calibrating = true
  533.   local maxCalibrationDuration = 60 * 20
  534.  
  535.   calibrationProgressBar.visible = true
  536.   calibrationLabel.visible = true
  537.  
  538.   while calibrating do
  539.     local bloodAmount = getBlood()
  540.     if bloodAmount >= altarCapacity or ticksPassed >= maxCalibrationDuration then
  541.       calibrating = false
  542.     end
  543.  
  544.     local altarFilled = bloodAmount / altarCapacity
  545.     local timepassed =  ticksPassed / maxCalibrationDuration
  546.     if timepassed > altarFilled then
  547.       calibrationProgressBar.data = timepassed
  548.     else
  549.       calibrationProgressBar.data = altarFilled
  550.     end
  551.  
  552.     local currentTicks = getMCTicks()
  553.     local passed = currentTicks - prevTicks
  554.     if currentTicks < prevTicks then
  555.       passed = currentTicks + prevTicks - 24000
  556.     end
  557.     ticksPassed = ticksPassed + passed
  558.     prevTicks = currentTicks
  559.   end
  560.  
  561.   calibrationLabel.visible = false
  562.   calibrationProgressBar.visible = false
  563.  
  564.   return (altarCapacity - startingBlood) / ticksPassed
  565. end
  566.  
  567. function calibrateLPConsumption (slate)
  568.  
  569. end
  570.  
  571. function toggleOrbMode ()
  572.   enableOrb = not enableOrb
  573.   orbButton.active = enableOrb
  574.   writeToConfig()
  575.   altarLog.addMessage("Set orbmode to: " .. tostring(enableOrb), 4)
  576.   if not enableOrb and findOrb(altar) then
  577.     pullOrbFromAltar()
  578.   end
  579. end
  580.  
  581. function togglePause()
  582.   paused = not paused
  583.   pauseButton.active = paused
  584.   writeToConfig()
  585.   if paused then
  586.     altarLog.addMessage("Paused Altar", 2)
  587.   else
  588.     altarLog.addMessage("Resumed Altar", 3)
  589.   end
  590.   if paused and findOrb(altar) then
  591.     pullOrbFromAltar()
  592.   end
  593. end
  594.  
  595. function setupUI ()
  596.   local monw, monh = monitor.getSize()
  597.   local slateButtons = UIUtils.generateButtons(monitor, getTableSize(slates), 3, 3, (monw / 2 ) - 2, monh - 3, 3,3, colors.green, colors.red, colors.black, setSlate)
  598.  
  599.   local size = getTableSize(slates)
  600.   local current = 1
  601.  
  602.   for k,v in pairs(slates) do
  603.     slateButtons[current].text = k
  604.     slateButtons[current].data = k
  605.     slateButtons[current].isRadio  = true
  606.     slateButtons[current].radioTag = "slate"
  607.     if k == currentSlate then
  608.       slateButtons[current].active = true
  609.     end
  610.     current = current + 1
  611.   end
  612.  
  613.   current = 1
  614.   local craftButtons = UIUtils.generateButtons(monitor, #craftingModes, 4, monh - 1, monw - 9, monh , #craftingModes, 1, colors.orange, colors.blue, colors.white, setCraftMode )
  615.   local size = getTableSize(craftingModes)
  616.   for k,v in pairs(craftingModes) do
  617.     craftButtons[current].text = v
  618.     craftButtons[current].data = v
  619.     craftButtons[current].page = 0
  620.     if v == currentCraftingMode then
  621.       craftButtons[current].active = true
  622.     end
  623.     craftButtons[current].isRadio = true
  624.     craftButtons[current].radioTag = "craft"
  625.     current = current + 1
  626.   end
  627.  
  628.   local bloodBar = UIUtils.ProgressBarClass.new()
  629.   bloodBar.horizontal = false
  630.   bloodBar.width = 5
  631.   bloodBar.height = monh - 5
  632.   bloodBar.setPos(monw - bloodBar.width - 1, 3)
  633.   bloodBar.dataSource = function () return getBlood() / altarCapacity end
  634.  
  635.   local bloodBarLabel = UIUtils.TextClass.new()
  636.   bloodBarLabel.dataSource = function () return getBlood() .. "MB" end
  637.   bloodBarLabel.text = function () return getBlood() .. "MB" end
  638.   bloodBarLabel.setPos(monw - (#tostring(altarCapacity) + 2), monh)
  639.   bloodBarLabel.textColor = colors.white
  640.   bloodBarLabel.primaryColor = colors.black
  641.  
  642.   navBar.setPos(1,1)
  643.   navBar.primaryColor = colors.black
  644.   navBar.textColor = colors.white
  645.   navBar.width = monw
  646.  
  647.   navBar.options[1] = currentCraftingMode
  648.   navBar.options[2] = currentSlate
  649.   navBar.height = 1
  650.  
  651.   altarLog.setPos(monw / 2, 2)
  652.   altarLog.primaryColor  = colors.black
  653.   altarLog.textColor = colors.white
  654.   altarLog.height = monh - 6
  655.   altarLog.width = monw / 2 - 8
  656.  
  657.   nextButton.width = 1
  658.   nextButton.height = 2
  659.   nextButton.setPos(monw / 2 -1 ,(monh / 2) - (nextButton.height / 2))
  660.   nextButton.text = ">>"
  661.   nextButton.secondaryColor = colors.black
  662.   nextButton.textColor= colors.white
  663.   if getTableSize(slates) <= pageSize then
  664.     nextButton.visible = false
  665.   end
  666.   nextButton.onClick = function ()  UI.page = UI.page + 1 if UI.page >= math.ceil(getTableSize(slates) / pageSize) then nextButton.visible=false end if UI.page ~= 1 then previousButton.visible = true end end
  667.  
  668.   previousButton.width = 1
  669.   previousButton.height = 2
  670.   previousButton.setPos(1 ,(monh / 2) - (previousButton.height / 2))
  671.   previousButton.text = "<<"
  672.   previousButton.secondaryColor = colors.black
  673.   previousButton.textColor= colors.white
  674.   if UI.page == 1 then
  675.     previousButton.visible = false
  676.   end
  677.   previousButton.onClick = function () UI.page = UI.page - 1 if UI.page == 1 then previousButton.visible = false end if  UI.page < math.ceil(getTableSize(slates) / pageSize) then nextButton.visible=true end end
  678.  
  679.   orbButton.width = 5
  680.   orbButton.active = enableOrb
  681.   orbButton.height = 0
  682.   orbButton.text = "orb"
  683.   orbButton.primaryColor = colors.orange
  684.   orbButton.secondaryColor = colors.blue
  685.   orbButton.textColor = colors.white
  686.   orbButton.setPos(monw - orbButton.width -1,1 )
  687.   orbButton.visible = true
  688.   orbButton.onClick = toggleOrbMode
  689.  
  690.   pauseButton.width = 6
  691.   pauseButton.active = paused
  692.   pauseButton.height = 0
  693.   pauseButton.text = "pause"
  694.   pauseButton.primaryColor = colors.orange
  695.   pauseButton.secondaryColor = colors.blue
  696.   pauseButton.textColor = colors.white
  697.   pauseButton.setPos(monw - pauseButton.width - 8,1 )
  698.   pauseButton.visible = true
  699.   pauseButton.onClick = togglePause
  700.  
  701.   UI.addObject(navBar)
  702.   UI.addObject(altarLog)
  703.   UI.addObject(bloodBarLabel)
  704.   UI.addObject(bloodBar)
  705.   UI.addObjects(slateButtons)
  706.   UI.addObjects(craftButtons)
  707.   UI.addObject(previousButton)
  708.   UI.addObject(nextButton)
  709.   UI.addObject(orbButton)
  710.   UI.addObject(pauseButton)
  711. end
  712.  
  713. --setup function
  714. function setup()
  715.   readFromConfig()
  716.   setupPeripherals()
  717.  
  718.   term.clear()
  719.   term.setCursorPos(1,1)
  720.   term.setTextColor(colors.red)
  721.   print("--- Auto-altar V1.0 ---")
  722.   term.setTextColor(colors.yellow)
  723.   term.write("InputChest side: ")
  724.   term.setTextColor(colors.white)
  725.   print(peripheral.getName(chest))
  726.  
  727.   if enableOutput then
  728.     term.setTextColor(colors.yellow)
  729.     term.write("OutputChest side: ")
  730.     term.setTextColor(colors.white)
  731.     print(peripheral.getName(outputChest))
  732.   end
  733.  
  734.   if enableOrbContainer then
  735.     term.setTextColor(colors.yellow)
  736.     term.write("orbchest side: ")
  737.     term.setTextColor(colors.white)
  738.     print(peripheral.getName(orbChest))
  739.   end
  740. end
  741.  
  742. function handleMonitor ()
  743.   while true do
  744.       event, side, x, y = os.pullEvent("monitor_touch")
  745.       UI.handler(UI, event, side, x, y, UI.page)
  746.   end
  747. end
  748.  
  749. function redrawMonitor ()
  750.   while true do
  751.     UI.update()
  752.     local prev = term.redirect(monitor)
  753.     term.setBackgroundColor(colors.black)
  754.     term.clear()
  755.     UI.draw()
  756.     term.redirect(prev)
  757.     os.sleep(refreshRate)
  758.   end
  759. end
  760.  
  761. setup()
  762.  
  763. if enableMonitor then
  764.   setupUI()
  765.   UI.page = 1
  766.   parallel.waitForAll(redrawMonitor, handleMonitor, handleCrafting)
  767. else
  768.   handleCrafting()
  769. end
Advertisement
Add Comment
Please, Sign In to add comment