Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Functions
- function fResetTerminal()
- term.clear()
- term.setCursorPos(1, 1)
- end
- function fGetConfig()
- if not fs.exists("items.tbl") then
- tFile = fs.open("items.tbl", "w")
- tFile.write("{}")
- tFile.close()
- end
- tFile = fs.open("items.tbl", "r")
- tConfig = textutils.unserialize(tFile.readAll())
- tFile.close()
- end
- function fSaveConfig()
- tFile = fs.open("items.tbl", "w")
- tFile.write(textutils.serialize(tConfig))
- tFile.close()
- end
- function fGetItemsFromName(sName)
- tAvailable = p.listAvailableItems()
- tReturn = {}
- for i = 1,#tAvailable do
- if tAvailable[i].isCraftable then
- tCurrentItem = {["name"]=tAvailable[i].name,["damage"]=tAvailable[i].damage}
- --print(textutils.serialize(tCurrentItem))
- tCurrentItemObject = p.findItem(tCurrentItem)
- tMeta = tCurrentItemObject.getMetadata()
- print(tMeta.displayName)
- if string.match(string.lower(tMeta.displayName), string.lower(sName)) then
- print("MATCH")
- table.insert(tReturn, tMeta)
- end
- end
- end
- return tReturn
- end
- function fGetItemFromMeta(sName, iDamage)
- tAvailable = p.listAvailableItems()
- for i = 1,#tAvailable do
- if tAvailable[i].name == sName and tAvailable[i].damage == iDamage then
- return tAvailable[i]
- end
- end
- return nil
- end
- function fProcessorAvailable()
- tCpus = p.getCraftingCPUs()
- for i = 1,#tCpus do
- if tCpus[i].busy == false then
- return true
- end
- end
- return false
- end
- --Main Loops
- function fUserInput()
- while true do
- fResetTerminal()
- print("AE2 Autocrafting Stock Program by Fisher")
- print("The Crafting daemon is running in the background of this terminal. This interface is simply to edit what is crafted.")
- print("")
- print("Type a command to start")
- print("1. list")
- print("2. add")
- print("3. remove")
- sInput = read()
- if sInput == "list" then
- end
- if sInput == "add" then
- print("Adding Item.")
- print("Type the namespaced item ID (minecraft:stone)")
- sName = read()
- repeat
- print("Type the damage value of the item (0)")
- sDamage = read()
- if not tonumber(sDamage) then
- print("That is not a number!")
- end
- until(tonumber(sDamage))
- if fGetItemFromMeta(sName, tonumber(sDamage)) then
- tItem = fGetItemFromMeta(sName, tonumber(sDamage))
- if tItem.isCraftable then
- tItemMeta = p.findItem(tItem).getMetadata()
- repeat
- print("How many \"" .. tItemMeta.displayName .. "\" do you wish to keep in stock?")
- sAmount = read()
- if not tonumber(sAmount) then
- print("That is not a number!")
- end
- until(tonumber(sAmount))
- print("Keeping " .. sAmount .. " of \"" .. tItemMeta.displayName .. "\" in stock.")
- tItemMeta["stockAmount"] = tonumber(sAmount)
- table.insert(tConfig, tItemMeta)
- fSaveConfig()
- print("Hit Enter to return to the main menu.")
- read()
- else
- print("This item isn't craftable in your system (no pattern)")
- end
- else
- print("This item isn't in your system at all.")
- read()
- end
- end
- end
- end
- function fCraftingDaemon()
- while true do
- for i = 1,#tConfig do
- if tJobs[tConfig[i].name .. "-" .. tConfig[i].damage] ~= null then
- if tJobs[tConfig[i].name .. "-" .. tConfig[i].damage].isFinished() then
- tJobs[tConfig[i].name .. "-" .. tConfig[i].damage] = nil
- end
- end
- if p.findItem(tConfig[i]).getMetadata().count < tConfig[i].stockAmount then
- if tJobs[tConfig[i].name .. "-" .. tConfig[i].damage] == null then
- if fProcessorAvailable() then
- tCraftingObject = p.findItem(tConfig[i]).craft(1)
- tJobs[tConfig[i].name .. "-" .. tConfig[i].damage] = tCraftingObject
- tSize = {term.getSize()}
- tPrevPos = {term.getCursorPos()}
- term.setCursorPos(1,tSize[2])
- if iColor == colors.gray then
- iColor = colors.lightGray
- else
- iColor = colors.gray
- end
- term.setTextColor(iColor)
- term.write("Crafting 1 " .. tConfig[i].displayName .. ". ")
- term.setTextColor(colors.white)
- term.setCursorPos(tPrevPos[1], tPrevPos[2])
- end
- end
- end
- end
- sleep(0.1)
- end
- end
- --The Main loop
- fGetConfig()
- p = peripheral.wrap("right")
- tJobs = {}
- iColor = colors.gray
- while true do
- parallel.waitForAll(fUserInput, fCraftingDaemon)
- end
Add Comment
Please, Sign In to add comment