Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Program:
- -- aspects
- -- Original program by Direwolf20
- -- Modified by Kzorith
- -- Description:
- -- Manages Thaumcraft 4 aspects stored in
- -- warded or void jars
- -- Hardware requirements:
- -- 1 Advanced Computer
- -- 15 Advanced Monitors (5x3)
- -- 1 Advanced Wireless Turtle
- -- 1 Wireless Modem
- -- 52 Wired Modem
- -- 52 Peripheral Proxy
- -- Network Cable
- -- 1 Golem Connector
- -- 1 Aspectalyzer
- -- Software requirements:
- -- Advanced Computer
- -- this program
- -- button API - pastebin get z0FBM6wd button
- -- Advanced Wireless Turtle
- -- catalogue - pastebin get dEWU3SwC catalogue
- -- Initialization
- -- set this to whatever side the wireless modem is on
- rednet.open("top")
- -- load the api to control the monitor
- os.loadAPI("button")
- -- set this to the turtle's id (command 'id' on the turtle)
- local turtleID = 47
- -- initialize a table for the essentia type and quantity
- local essentia = {}
- -- build a table of all peripherals attached to the computer
- local jars = peripheral.getNames()
- -- set this to whatever side the monitor is on
- -- NOTE: this must also be set the same in the button API
- local m = peripheral.wrap("right")
- -- set this to whatever side the golem connector is on
- --local g = peripheral.wrap("left")
- -- get the current location of the golem,
- -- it should be standing around, waiting for essence
- --local gX, gY, gZ = g.getPosition()
- --print ("Golem home at: "..gX..","..gY..","..gZ)
- -- initialize a table for rows on the monitor
- local monCoord = {}
- -- stores the essentia that was picked on the monitor
- local currEssentia
- -- stores the amount of essentia to be added to the jar
- local fillAmt = 0
- -- determines if the list of aspects is on the screen
- local rowsActive = true
- -- Functions
- -- sortEss - sorts a supplied table alphabetically
- -- Input: table t
- -- Output: a pointer to the function?
- 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
- -- scanEssentia - Reads the jars of essentia via the peripheral proxy
- function scanEssentia()
- -- read in all the peripherals attached to the computer
- jars = peripheral.getNames()
- -- set the quantity of each item in essentia to 0
- for i,j in pairs(essentia) do
- essentia[i] = 0
- end
- -- go through each peripheral attached to the computer
- for i,j in ipairs(jars) do
- -- if the peripheral is a warded jar
- if peripheral.getType(j) == "tt_aspectContainer" then
- -- get the type of essentia in it
- asp = peripheral.call(j, "getAspects")
- -- get the quantity of essentia in it
- countasp = peripheral.call(j, "getAspectCount", asp)
- -- round the quantity down to the nearest whole number if it's more than 0
- -- also ensure that the essentia name is all lower case
- if countasp > 0 then
- essentia[string.lower(asp)] = math.floor(countasp)
- end
- end
- -- if the peripheral is a void jar
- if peripheral.getType(j) == "tilejarvoid" then
- -- get a table with the aspect name and quantity in it
- tmp = peripheral.call(j, "getAspects")
- if tmp[1] ~= nil then
- -- get the quantity of essentia in it
- -- for i,v in ipairs(tmp[1]) do print( i..", "..v) end
- countasp = tmp[1]["quantity"]
- -- get the type of essentia in it
- asp = tmp[1]["name"]
- -- round the quantity down to the nearest whole number
- -- also ensure that the essentia name is all lower case
- if countasp > 0 then
- essentia[string.lower(asp)] = math.floor(countasp)
- end
- end
- end
- end
- end
- -- printEssentia - prints the essentia names and quantities on the monitor
- function printEssentia()
- --set the default text color for the monitor
- m.setTextColor(colors.white)
- -- set the starting coords to write on the screen
- local x = 1
- local y = 1
- -- initialize a table to keep track of where an essentia is on the screen in the first column
- monCoord[x] = {}
- -- go through each essentia in alphabetical order
- for i,j in sortEss(essentia) do
- -- set the text color based on how much essentia there is
- if j==0 then m.setTextColor(colors.purple) end
- if j<20 and j>0 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
- -- set the cursor to a location on the screen
- m.setCursorPos(x,y)
- -- write the essentia name to the screen
- m.write(i)
- -- move the cursor for the quantity based on if it's 1 or 2 digits
- -- this will align the numbers
- if j<10 then
- m.setCursorPos(x+15,y)
- else
- m.setCursorPos(x+14,y)
- end
- -- write the essentia quantity to the screen
- m.write(tostring(j))
- -- make note what essentia is at this location on the screen
- monCoord[x][y] = i
- -- move the cursor down one row if we haven't placed 17 essentia on the screen
- if y < 19 then
- y = y+1
- -- otherwise move the cursor over to the next column and start at the top
- -- initialize a new table to keep track of essentia in this column
- else
- y = 1
- x = x+17
- monCoord[x] = {}
- end
- end
- -- set the default text color to white
- m.setTextColor(colors.white)
- end
- -- getClick - waits for the player to right click on the screen
- function getClick()
- -- wait for something to happen to the computer
- local event,side,x,y = os.pullEvent()
- -- if the monitor was touched..
- if event=="monitor_touch" then
- -- check to see if it was one of the defined buttons
- if button.checkxy(x,y) then
- -- print a message on the computer
- print("button")
- else
- -- if it was elsewhere on the screen and we are displaying essentia
- if rowsActive then
- -- initialize the fill amount
- fillAmt = 0
- -- print the column and essentia that was clicked
- print(x..":"..x-(x%17)+1)
- print(monCoord[x-(x%17)+1][y])
- -- store the essentia name
- currEssentia = monCoord[x-(x%17)+1][y]
- -- if the stored name isn't blank
- if currEssentia ~= nil then
- -- if the quantity is less than 64
- if essentia[currEssentia] < 64 then
- -- display the quantity control screen
- fillTable2()
- else
- -- clear the screen
- m.clear()
- -- display a message that the jar is full
- button.label(1,10, currEssentia.." is already full. Please choose another.")
- -- wait 3 seconds
- sleep(3)
- -- refresh the essentia list and display it
- refresh()
- end
- end
- end
- end
- end
- end
- -- refresh - Scans the jars and displays the essentia list
- function refresh()
- -- show that you clicked the button
- button.flash("Refresh")
- -- clear the monitor
- m.clear()
- -- scan the jars
- scanEssentia()
- -- display the essentia list
- printEssentia()
- -- print that the screen was refreshed to the computer
- print("Refreshed")
- -- display the buttons on the monitor
- button.screen()
- end
- -- fillTable - builds the list of available buttons on the essentia screen
- function fillTable()
- -- set that we are using rows on this screen
- rowsActive = true
- -- clear the list of buttons
- button.clearTable()
- -- build the Refresh button.
- -- button name, function to call, any parameters to the function,
- -- button location left column, top row, right column, bottom row
- button.setTable("Refresh", refresh, "", 8, 25, 21, 25)
- -- build the Fill All button
- button.setTable("Fill All", fillAll, "", 27, 41, 21, 25)
- --display the buttons on the monitor
- button.screen()
- end
- -- addEss - adds a number to the current fill amount
- -- Input: interger num
- function addEss(num)
- -- add the number (which could be negative) to the current fill amount
- fillAmt = fillAmt + num
- -- if it's less than zero, make it zero
- if fillAmt < 0 then fillAmt = 0 end
- -- if the total is more than 64, make it the amount to bring the quantity to 64
- if fillAmt > 64-essentia[currEssentia] then fillAmt = 64-essentia[currEssentia] end
- -- clear the monitor
- m.clear()
- -- display the quantity control screen
- fillTable2()
- end
- -- meltEss - tell the turtle how many mana beans of what type to put in the alembic
- function meltEss()
- -- initialize a table to hold the essentia information
- local essData = {}
- -- store the essentia name
- essData[1] = currEssentia
- -- store the quantity requested to be added
- essData[2] = fillAmt
- -- initialize a string to hold a data stream
- local sendData = ""
- -- put the information into a data stream
- sendData = textutils.serialize(essData)
- -- send the stream to the waiting turtle
- rednet.send(turtleID, sendData)
- -- clear the monitor
- m.clear()
- -- put a message on the monitor saying what's going on
- button.label(7, 10, "Waiting for "..currEssentia.." to finish cooking....")
- -- wait for the turtle to send a message back
- rednet.receive()
- end
- -- waitOnGolem - checks the golems position against it's home position to make sure it's not moving around
- function waitOnGolem()
- -- clear the monitor
- m.clear()
- --put a message on the monitor saying what's going on
- button.label(7, 10, "Waiting for the golum to finish moving...")
- -- if the golem is moving, wait 5 seconds and check again
- while not locateGolem() do
- sleep(5)
- end
- end
- -- fillEss - performs the steps to add essential to jars
- function fillEss()
- -- tell turtle what to put into the alembic
- meltEss()
- -- wait for golem to move the essentia
- waitOnGolem()
- -- clear the screen
- m.clear()
- -- put the buttons on the essentia screen
- fillTable()
- -- scan the jars and display the essentia
- refresh()
- end
- -- fillAll - checks each jar and fills it up to 64 essentia if required
- function fillAll()
- -- show that you clicked the button
- button.flash("Fill All")
- -- get the current quantities in the jars
- scanEssentia()
- -- for each jar in the alphabetized list
- for i,j in sortEss(essentia) do
- -- if there is less than 64 essentia
- if j < 64 then
- -- figure out how much more is needed
- fillAmt = 64-j
- -- store what essentia it is
- currEssentia = i
- -- tell the turtle what to put in the alembic
- meltEss()
- end
- end
- -- wait for the golem to move the essentia
- waitOnGolem()
- -- clear the monitor
- m.clear()
- -- put the buttons on the essentia screen
- fillTable()
- -- scan the jars and display the essentia
- refresh()
- end
- -- cancel - abort adding any essentia to a jar
- function cancel()
- -- clear the monitor
- m.clear()
- -- put the buttons on the essentia screen
- fillTable()
- -- scan the jars and dispaly the essentia
- refresh()
- end
- -- fillTable2 - Builds a list of available buttons on the quantity control screen
- function fillTable2()
- -- set that we are NOT using rows on this screen
- rowsActive = false
- -- clear the list of buttons
- button.clearTable()
- -- clear the monitor
- m.clear()
- -- put a message on the monitor saying what the essentia we are working on and the quantity
- button.label(7, 1, "Essentia: "..currEssentia.." contains "..essentia[currEssentia])
- -- set up the buttons to add or remove essentia
- 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)
- -- set up the button to refill the jar completely
- button.setTable("Refill Jar", addEss, 64-essentia[currEssentia], 8, 42, 10, 10)
- -- set up the button to begin filling the jar
- button.setTable("Execute Fill Request", fillEss, "", 8, 42, 16, 18)
- -- set up the button to abort the fill request
- button.setTable("Cancel", cancel, "", 20, 30, 12, 14)
- -- put a message on the monitor saying how much we currently want to add
- button.label(7, 4, "Currently Adding "..fillAmt.." "..currEssentia.." essentia.")
- -- display the buttons on the quantity control screen
- button.screen()
- end
- -- locateGolem - determines the current location of the golem
- -- Output: a boolean indicating if the golem was moving
- function locateGolem()
- -- return that the golem isn't moving
- return true
- end
- -- put buttons on the essentia screen
- fillTable()
- -- scan the jars and display the essentia
- refresh()
- -- loop forever waiting for a click on the monitor
- while true do getClick() end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement