Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rednet.open("right")
- os.loadAPI("button")
- local turtleID = 98
- -- essentia is an array. The array elements are defined by the name of the aspect. The value of that element is the amount
- -- of essentia in a jar. For example: essentia["ordo"]=21 means the ordo jar has 21 essentia
- local essentia = {}
- -- ejar is an array of the jars and essentia type for each jar location. For example: ejar["tilejar_102"]="ordo"
- local ejar = {}
- -- Temp/testing var
- local tmp
- local jars = peripheral.getNames()
- local m = peripheral.wrap("top")
- local monCoord = {}
- local currEssentia
- local fillAmt = 0
- local rowsActive = true
- 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
- -- This function will do the initial scan all of the jars and store the values in the array essentia & ejar
- function initScan()
- print("Starting inital scan")
- for i,j in ipairs(jars) do
- if peripheral.getType(j) == "tilejar" then
- pw = peripheral.wrap(j)
- asp = pw.getEssentiaType('front')
- ejar[j] = asp
- --print(" "..j.." = "..ejar[j])
- countasp = pw.getEssentiaAmount('front')
- if countasp > 0 then
- essentia[asp] = math.floor(countasp)
- else
- essentia[asp] = 0
- end
- end
- end
- --print(" tilejar_178 = "..ejar["tilejar_178"])
- end
- -- This function will scan all of the jars and store the value in the array essentia
- function scanEssentia()
- print("Starting scan function")
- --print(" tilejar_183 = "..ejar["tilejar_183"])
- for i,j in pairs(ejar) do
- --print(" "..i.." = "..j)
- pw = peripheral.wrap(i)
- --asp = pw.getEssentiaType('front')
- countasp = pw.getEssentiaAmount('front')
- --print(" "..j.." = "..countasp)
- if countasp > 0 then
- essentia[j] = math.floor(countasp)
- else
- essentia[j] = 0
- end
- end
- end
- function printEssentia()
- m.setTextColor(colors.white)
- local x = 1
- local y = 1
- monCoord[x] = {}
- 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))
- monCoord[x][y] = i
- if y < 17 then
- y = y+1
- else
- y = 1
- x = x+17
- monCoord[x] = {}
- end
- end
- m.setTextColor(colors.white)
- end
- function getClick()
- local event,side,x,y = os.pullEvent()
- 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
- end
- end
- function refresh()
- button.flash("Refresh")
- m.clear()
- scanEssentia()
- printEssentia()
- print("Refreshed")
- button.screen()
- end
- -- This function will fill all empty jars to 64
- function fillAll()
- m.clear()
- button.label(7, 8, " Now filling all jars")
- button.label(7, 10, "Wait for aspects to finish cooking......")
- button.label(7, 12, "Don't forget to refresh the screen after")
- button.label(7, 13, "the golems are done moving the essentia.")
- local essData = {}
- button.flash("Fill All")
- for i,j in ipairs(jars) do
- if peripheral.getType(j) == "tilejar" then
- pw = peripheral.wrap(j)
- asp = ejar[j]
- countasp = pw.getEssentiaAmount('front')
- if countasp > 0 then
- essentia[asp] = math.floor(countasp)
- else
- essentia[asp] = 0
- end
- if essentia[asp] >= 64 then
- print(asp.." is full")
- else
- print(asp.." needs "..64-essentia[asp])
- essData[1] = asp
- essData[2] = 64-essentia[asp]
- local sendData = ""
- sendData = textutils.serialize(essData)
- print("turtleID = "..turtleID..", sendData = "..sendData)
- rednet.send(turtleID, sendData)
- rednet.receive()
- end
- end
- end
- m.clear()
- fillTable()
- printEssentia()
- refresh()
- end
- function fillTable()
- rowsActive = true
- button.clearTable()
- button.setTable("Fill All", fillAll, "", 5, 23, 19, 19)
- button.setTable("Refresh", refresh, "", 27, 46, 19, 19)
- button.screen()
- 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
- m.clear()
- fillTable2()
- end
- function fillEss()
- local essData = {}
- essData[1] = currEssentia
- essData[2] = fillAmt
- local sendData = ""
- sendData = textutils.serialize(essData)
- print("turtleID = "..turtleID..", sendData = "..sendData)
- rednet.send(turtleID, sendData)
- m.clear()
- button.label(7, 10, "Waiting for aspects to finish cooking....")
- button.label(7, 12, "Don't forget to refresh the screen after")
- button.label(7, 13, "the golem is done moving the essentia.")
- rednet.receive()
- m.clear()
- fillTable()
- printEssentia()
- --refresh()
- end
- function cancel()
- m.clear()
- fillTable()
- refresh()
- end
- function fillTable2()
- rowsActive = false
- button.clearTable()
- m.clear()
- button.label(7, 1, "Essentia: "..currEssentia.." contains "..essentia[currEssentia])
- button.setTable("+1", addEss, 1, 8, 18, 6,6)
- button.setTable("+5", addEss, 5, 20, 30, 6, 6)
- button.setTable("+10", addEss, 10, 32, 42, 6, 6)
- button.setTable("-1", addEss, -1, 8, 18, 8, 8)
- button.setTable("-5", addEss, -5, 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", fillEss, "", 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()
- initScan()
- refresh()
- while true do getClick() end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement