Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("button")
- local essentia = {}
- local jars = peripheral.getNames()
- local m = peripheral.wrap("left")
- local ess = {}
- local essCount = {}
- local a = peripheral.find("tt_aspectanalyzer")
- local c = peripheral.find("iron")
- local rowsActive = true
- local monCoord = {}
- local currEssentia
- local fillAmt = 0
- function findEss()
- local tempess = {}
- local notAuram
- for i = 1,49 do
- if c.getStackInSlot(i) then
- c.pushItem("SOUTH", i, 1,1)
- tempess = a.getAspects()
- if tempess[2] then
- if tempess[2] == "auram" then
- notAuram = tempess[1]
- else
- notAuram = tempess[2]
- end
- else
- notAuram = tempess[1]
- end
- c.pullItem("SOUTH", 1,1,i)
- ess[notAuram] = i
- essentia[notAuram] = 0
- essCount[notAuram] = c.getStackInSlot(i)["qty"]
- end
- end
- -- print(ess["terra"])
- -- print(ess["fames"])
- -- print(ess["ignis"])
- -- print(essCount["terra"])
- -- print(essCount["fames"])
- -- print(essCount["arbor"])
- -- print(essCount["iter"])
- end
- function scanEssentia()
- for i,j in ipairs(jars) do
- if peripheral.getType(j) == "tt_aspectContainer" then
- asp = peripheral.call(j, "getAspects")
- countasp = peripheral.call(j, "getAspectCount", asp[1])
- if countasp > 0 then
- essentia[asp[1]] = math.floor(countasp)
- -- print(asp[1]..":"..countasp)
- end
- end
- end
- end
- function sortEss(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
- function printEssentia()
- m.setTextColor(colors.white)
- local x = 1
- local y = 1
- monCoord[x] = {}
- -- for a = 1,17 do
- for i,j in sortEss(essentia) do
- if j<=20 then m.setTextColor(colors.red) end
- if j<40 and j>20 then m.setTextColor(colors.yellow) end
- if j>=40 then m.setTextColor(colors.green) end
- m.setCursorPos(x,y)
- m.write(i)
- m.setCursorPos(x+14,y)
- m.write(tostring(j))
- -- print(j)
- monCoord[x][y] = i
- if y < 17 then
- y = y+1
- else
- y = 1
- x = x+17
- monCoord[x] = {}
- end
- end
- -- end
- m.setTextColor(colors.white)
- end
- function getClick()
- local timerCode = 0
- timerCode = os.startTimer(15)
- local event,side,x,y
- repeat
- event,side,x,y = os.pullEvent()
- --print(event)
- until side == timerCode or event=="monitor_touch"
- if event=="monitor_touch" then
- if button.checkxy(x,y) then
- print("button")
- else
- 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 currEssentia ~= nil then
- if essentia[currEssentia] < 64 then
- fillTable2()
- else
- m.clear()
- button.label(1,10, currEssentia.." is already full. Please choose another.")
- sleep(3)
- refresh()
- end
- end
- end
- end
- else
- refresh()
- end
- end
- function refresh()
- button.flash("Refresh")
- m.clear()
- findEss()
- scanEssentia()
- printEssentia()
- print("Refreshed")
- button.screen()
- end
- function fillTable()
- rowsActive = true
- button.clearTable()
- button.setTable("Refresh", refresh, "", 15, 35, 19, 19)
- button.screen()
- button.setTable("Refill All", refillAll, "", 39,52, 19,19)
- end
- function refillAll()
- for essName,essAmt in pairs(essentia) do
- currEssentia = essName
- print(currEssentia)
- fillAmt = (64-essAmt)
- if fillAmt > (essCount[currEssentia]-1)*2 then fillAmt = (essCount[currEssentia]-1)*2 end
- fillEss2()
- end
- end
- function cancel()
- m.clear()
- fillTable()
- refresh()
- end
- function addEss(num)
- fillAmt = fillAmt + num
- if fillAmt < 0 then fillAmt = 0 end
- if fillAmt > 64-essentia[currEssentia] then fillAmt = 64-essentia[currEssentia] end
- if fillAmt > (essCount[currEssentia]-1)*2 then fillAmt = (essCount[currEssentia]-1)*2 end
- m.clear()
- fillTable2()
- end
- function fillEss2()
- c.pushItem("UP", ess[currEssentia], fillAmt/2)
- m.clear()
- fillTable()
- refresh()
- end
- function fillTable2()
- rowsActive = false
- button.clearTable()
- m.clear()
- button.label(7, 1, "Essentia: "..currEssentia.." contains "..essentia[currEssentia])
- button.label(7, 2, "Available: "..currEssentia.." is: "..(essCount[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-essentia[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
- fillTable()
- refresh()
- while true do getClick() end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement