Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Aspects program, adapted from Direwolf20 Season 7 Episode 64 Let's Play
- --
- -- Hopefully a little cleaned up and easier to understand by Senseidragon.
- os.loadAPI("button")
- local jars = peripheral.getNames()
- -- if monitor is not on left of computer, change this
- local monitor = peripheral.wrap("left")
- local essenceIndex = {}
- local aspectLevel = {}
- local essenceCount = {}
- -- direction of the Aspectalyzer from the iron chest.
- local analyzerFacing = "SOUTH"
- local analyzer = peripheral.find("tt_aspectanalyzer")
- -- coded to look for an iron chest (from Iron Chests mod)
- local chest = peripheral.find("iron")
- local rowsActive = true
- local monCoord = {}
- local currEssentia
- local fillAmt = 0
- -- Size should be 54 for an iron chest.
- local chestSize = chest.getInventorySize()
- -- This function will go through the iron chest to determine
- -- what ethereal essences are in which slot. Only ethereal
- -- essences should be in this chest, no more than 1 stack each
- function locateEssences()
- local sampleEssence = {}
- local aspectName
- -- iterate through all the slots in the chest
- for idx = 1,chestSize do
- -- If there is an item in this slot
- if chest.getStackInSlot(idx) then
- -- push one of it into the Aspectalyzer
- chest.pushItem(analyzerFacing, idx, 1, 1)
- -- Get the aspects from this item
- sampleEssence = analyzer.getAspects()
- -- if there are 2 essentia entries for an essence, get the non-auram one
- if sampleEssence[2] then
- if sampleEssence[2] == "auram" then
- aspectName = sampleEssence[1]
- else
- aspectName = sampleEssence[2]
- end
- else
- -- otherwise, get the name
- aspectName = sampleEssence[1]
- end
- -- Tell the chest to suck the item back from the Aspectalyzer into its
- -- original slot
- chest.pullItem(analyzerFacing, 1, 1, idx)
- -- Store the chest slot where the essence can be found
- essenceIndex[aspectName] = idx
- -- Set our initial level of this aspect (in the jars) to zero
- aspectLevel[aspectName] = 0
- -- Set how many Ethereal Essences we have available for this aspect
- essenceCount[aspectName] = chest.getStackInSlot(idx)["qty"]
- end
- end
- end
- -- This function scans and records the current aspect levels in all of your void jars
- function scanAspects()
- local aspectName
- local tempLevel
- -- iterate through everything attached to a Proxy Peripheral
- for i,j in ipairs(jars) do
- -- is it connected to a Void Jar?
- if peripheral.getType(j) == "tt_aspectContainer" then
- -- Get the name and count of the aspect in the jar
- aspectName = peripheral.call(j, "getAspects")
- tempLevel = peripheral.call(j, "getAspectCount", aspectName[1])
- -- If the jar is not empty
- if tempLevel > 0 then
- -- Record the amount of this aspect
- aspectLevel[aspectName[1]] = math.floor(tempLevel)
- end
- end
- end
- end
- -- A generic sorting function to sort aspects alphabetically
- function sortEssentia(t)
- local keys = {}
- for k in pairs(t) do keys[#keys+1] = k end
- table.sort(keys)
- local i = 0
- return function()
- i = i+1
- if keys[i] then
- return keys[i], t[keys[i]]
- end
- end
- end
- -- Sometimes blank screens can be unsettling
- function printWaitMessage()
- monitor.clear()
- button.label(1,10, "Calculating aspect levels. One moment...")
- end
- -- Print out the big list of all aspects in the jars and their current levels
- function printEssentia()
- monitor.setTextColor(colors.white)
- local x = 1
- local y = 1
- monCoord[x] = {}
- for i,j in sortEssentia(aspectLevel) do
- -- Aspects with 20 or less show in red
- if j<=20 then monitor.setTextColor(colors.red) end
- -- Aspects between 21-39 inclusive show in yellow
- if j<40 and j>20 then monitor.setTextColor(colors.yellow) end
- -- Aspects with 40 or more show in green
- if j>=40 then monitor.setTextColor(colors.green) end
- monitor.setCursorPos(x,y)
- monitor.write(i)
- monitor.setCursorPos(x+14,y)
- monitor.write(tostring(j))
- monCoord[x][y] = i
- if y < 17 then
- y = y+1
- else
- y = 1
- x = x+17
- monCoord[x] = {}
- end
- end
- monitor.setTextColor(colors.white)
- end
- -- The main event handling routine
- -- Waits for the user to click something, or for a 10 second timer to elapse
- function getClick()
- local timerCode = 0
- -- Set the interval timer to 10 seconds
- timerCode = os.startTimer(10)
- local event,side,x,y
- repeat
- event,side,x,y = os.pullEvent()
- -- Keep waiting until you get a monitor click or the timer expires
- until side == timerCode or event=="monitor_touch"
- -- If they touched the monitor, figure out where they touched it
- if event=="monitor_touch" then
- if button.checkxy(x,y) then
- -- Buttons know how to handle themselves, so we just print "button"
- -- to the console to let us know we saw a click.
- print("button")
- else
- -- They didn't click a button, let's see what aspect they clicked on
- if rowsActive then
- fillAmt = 0
- print(x..":"..x-(x%17)+1)
- print(monCoord[x-(x%17)+1][y])
- currEssentia = monCoord[x-(x%17)+1][y]
- -- If they clicked on an aspect, go to the "fill it up" screen
- if currEssentia ~= nil then
- -- if it isn't already full, that is
- if aspectLevel[currEssentia] < 64 then
- print("aLvl: "..aspectLevel[currEssentia])
- fillTable2()
- else
- -- They clicked a full aspect, tell them they derped
- monitor.clear()
- button.label(1,10, currEssentia.." is already full. Please choose another.")
- sleep(3)
- refresh()
- end
- end
- end
- end
- else
- -- The 10 second timer expired, refresh the screen with updated values
- refresh()
- end
- end
- -- This updates the main screen and recalculates all the values. It is a
- -- rather slow function, so don't call it too frequently
- function refresh()
- fillTable()
- button.flash("Refresh")
- -- Recalculate all the essences in the chest
- locateEssences()
- -- Recalculate all the aspect levels in the jars
- scanAspects()
- monitor.clear()
- -- Display everything
- printEssentia()
- print("Refreshed")
- button.screen()
- end
- function fillTable()
- -- Show the buttons on the main screen
- rowsActive = true
- button.clearTable()
- button.setTable("Refresh", refresh, "", 30, 38, 19,19)
- button.screen()
- button.setTable("Refill All", refillAll, "", 40,50, 19,19)
- end
- -- Iterate through every aspect you have already calculated
- -- and if they are not already full, try to fill them
- function refillAll()
- printWaitMessage()
- for essName,essAmt in pairs(aspectLevel) do
- currEssentia = essName
- fillAmt = (64-essAmt)
- if essenceCount[currEssentia] ~= nil then
- if fillAmt > (essenceCount[currEssentia]-1)*2 then fillAmt = (essenceCount[currEssentia]-1)*2 end
- fillEss2()
- else
- print("Supply chest needs more "..currEssentia)
- end
- end
- fillTable()
- end
- -- Poorly named function. Shoot Direwolf20, not me.
- function cancel()
- monitor.clear()
- fillTable()
- refresh()
- end
- -- A function used when telling the program how much essence to burn.
- -- Don't let the player burn more than what would fill the jar
- function addEss(num)
- fillAmt = fillAmt + num
- if fillAmt < 0 then fillAmt = 0 end
- if fillAmt > 64-aspectLevel[currEssentia] then fillAmt = 64-aspectLevel[currEssentia] end
- if fillAmt > (essenceCount[currEssentia]-1)*2 then fillAmt = (essenceCount[currEssentia]-1)*2 end
- monitor.clear()
- fillTable2()
- end
- -- Send some essence to the ender chest to get burned
- function fillEss2()
- printWaitMessage()
- chest.pushItem("UP", essenceIndex[currEssentia], fillAmt/2)
- end
- -- Display the "fill it up" screen
- function fillTable2()
- rowsActive = false
- button.clearTable()
- monitor.clear()
- -- If you don't have any essence in the chest to fill this aspect
- -- then set the count to zero
- local count
- if essenceCount[currEssentia] == nil then
- count = 0
- print("No essenceCount entry for "..currEssentia)
- else
- count = essenceCount[currEssentia] - 1
- print(currEssentia..": "..count)
- end
- -- We never take the last essence from the chest, thus the reason for the -1.
- if count < 1 then
- button.label(1,10, currEssentia.." is out of stock. Please choose another.")
- sleep(3)
- cancel()
- else
- button.label(7, 1, "Essentia: "..currEssentia.." contains "..aspectLevel[currEssentia])
- button.label(7, 2, "Available: "..currEssentia.." is: "..(essenceCount[currEssentia]-1)*2)
- button.setTable("+2", addEss, 2, 8, 18, 6,6)
- button.setTable("+6", addEss, 6, 20, 30, 6, 6)
- button.setTable("+10", addEss, 10, 32, 42, 6, 6)
- button.setTable("-2", addEss, -2, 8, 18, 8, 8)
- button.setTable("-6", addEss, -6, 20, 30, 8, 8)
- button.setTable("-10", addEss, -10, 32, 42, 8 ,8)
- button.setTable("Refill Jar", addEss, 64-essenceIndex[currEssentia], 8, 42, 10, 10)
- button.setTable("Execute Fill Request", fillEss2, "", 8, 42, 16, 18)
- button.setTable("Cancel", cancel, "", 20, 30, 12, 14)
- button.label(7, 4, "Currently Adding "..fillAmt.." "..currEssentia.." essentia.")
- button.screen()
- end
- end
- print("This program is written for a 5x3 Advanced Monitor placed on the LEFT side of an Advanced Computer. If you mess with the monitor blocks, you may need to stop/start the game to get the monitor to display correctly again.")
- print("Remember, this program is written to process ethereal essences only.")
- printWaitMessage()
- fillTable()
- refresh()
- while true do getClick() end
Advertisement
Add Comment
Please, Sign In to add comment