Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --local modem = peripheral.wrap("right") modem.open(1)
- local terminalBridge = peripheral.wrap("back") terminalBridge.clear()
- local sysBridge = peripheral.wrap("right")
- local controller = peripheral.wrap("bottom")
- local modem = peripheral.wrap("top") for i=1, 51 do modem.open(i) end
- -- AE Storage
- calcUsage = (controller.getUsedBytes()) / (controller.getTotalBytes())
- calcDisplay = math.floor(calcUsage * 75)
- calcPercent = math.floor(calcUsage * 100)
- -- addBox(x,y,width,height,hexcolor,opacity)
- -- addText(x,y,text,color)
- function displayAE()
- terminalBridge.clear()
- local meter = terminalBridge.addBox(calcDisplay, 244, 1, 7, 0x000000, 1.0)
- local box = terminalBridge.addBox(5, 245, 75, 5, 0xB3150C, 0.5)
- box.setGradient(2)
- box.setColor2(0x1A991C)
- local meter = terminalBridge.addBox(calcDisplay, 244, 1, 7, 0x000000, 1.0)
- local percentDisplay = terminalBridge.addText(83, 244, "" ..tostring(calcPercent).. "%", 0xFFFFFF)
- end
- -- Converts 1000 into 1,000 for example
- function formatNumber(userInput)
- local formatted = userInput
- while true do
- formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
- if (k==0) then break end
- end
- return formatted
- --print("Function result: " ..tostring(formatted))
- end
- ---------------------------------------------------
- ----------------[[ Item System ]]------------------
- ---------------------------------------------------
- itemIndex = {}
- -- itemIndex[name] = id
- idIndex = {}
- -- idIndex[id] = name
- itemStock = {}
- -- itemStock[id] = number
- function retrieveCrafts()
- canCraft = sysBridge.listCraft()
- end
- function retrieveStorage()
- itemStock = sysBridge.listItems()
- end
- function retrieveIDs()
- fileRead = fs.open("itemIndex", "r")
- lineText = fileRead.readLine()
- while lineText ~= nil do
- _, _, key, value = string.find(lineText, "(%a+)%s*=%s*(%d+)")
- itemIndex[key]= tonumber(value)
- _, _, key, value = string.find(lineText, "(%a+)%s*=%s*(%d+)")
- idIndex[tonumber(value)]=key
- lineText = fileRead.readLine()
- end
- fileRead.close()
- end
- retrieveIDs()
- function isIndexed(itemID)
- if itemIndex[itemID] == nil then return false
- else return true end
- end
- function craftItem(reqID, reqQty, transfer)
- sysBridge.craft(reqID, reqQty)
- if idIndex[reqID] ~= nil then
- sysStatus = "Crafting.."
- displayText("Crafting " ..tostring(reqQty).. " " ..tostring(idIndex[reqID]).. "...")
- else
- sysStatus = "Crafting.."
- displayText("Crafting " ..tostring(reqQty).. " " ..tostring(reqID).. "...")
- end
- if transfer ~= "n" then
- print("Transfer command")
- transferItem(reqID,reqQty, false)
- end
- end
- function indexID(itemName, itemID)
- if itemIndex[itemName] == nil then
- fileWrite = fs.open("itemIndex", "a")
- fileWrite.writeLine(tostring(itemName).. "=" ..tonumber(itemID))
- displayText("Item '" ..tostring(itemName).. "' indexed (" ..tostring(itemID) .. ").")
- fileWrite.close()
- retrieveIDs()
- elseif itemIndex[itemName] ~= nil and itemID == itemIndex[itemName] then
- displayText("Item already exists.")
- end
- end
- --[[
- function removeID(itemName)
- if itemIndex[itemName] ~= nil then
- print("Getting ready to look for the value.")
- fileWrite = fs.open("itemIndex", "w")
- --print("Alright, here we go. Looking for: '"..itemName=itemID.."'.")
- findValue = ""..tostring(itemName).."="..tostring(itemIndex[itemName])
- print(findValue)
- --repeat lineText = fileWrite.readLine() until lineText == findValue
- lineText = fileWrite.readLine()
- --while not lineText == findValue do fileWrite.readLine() end
- while not fileWrite.readLine() == findValue do fileWrite.readLine()
- print("I could remove this: " ..tostring(lineText))
- elseif itemIndex[itemName] == nil then
- print("That item doesn't exist.")
- end
- fileWrite.close()
- end
- ]]--
- --[[
- function displayText(textInput)
- sysStatus = "dispText" terminalBridge.clear() displayAE()
- stringL = math.floor(terminalBridge.getStringWidth(tostring(textInput)))
- boxW = stringL + 10
- -- addBox x, y, w, h, color, opacity
- -- Fade In
- dispLine = terminalBridge.addBox(7, 7, 1, 15, 0x347D0A, 0.0)
- for i = 0, 1, 0.00003 do dispLine.setOpacity(i) end
- dispBox = terminalBridge.addGradientBox(8, 7, boxW, 15, 0x000000, 0.0, 0x000000, 0.0, 2)
- for i = 0, boxW, boxW/30000 do dispBox.setWidth(i) dispBox.setOpacity2((i/dispBox.getWidth())/2.5) end
- dispText = terminalBridge.addText(13, 11, tostring(textInput), 0xFFFFFF)
- dispText.setZIndex(1)
- --sleep(2)
- --print("About to start the timer.")
- end
- ]]--
- function fadeIn(textInput)
- sysStatus = "dispText" terminalBridge.clear() displayAE()
- stringL = math.floor(terminalBridge.getStringWidth(tostring(textInput)))
- boxW = stringL + 10
- dispLine = terminalBridge.addBox(7, 7, 1, 15, 0x347D0A, 0.0)
- for i = 0, 1, 0.00005 do dispLine.setOpacity(i) end
- --for i = 0, 1, 0.001 do dispLine.setOpacity(i) end
- dispBox = terminalBridge.addGradientBox(8, 7, boxW, 15, 0x000000, 0.0, 0x000000, 0.0, 2)
- for i = 0, boxW, boxW/15000 do dispBox.setWidth(i) dispBox.setOpacity2((i/dispBox.getWidth())/2.5) end
- dispText = terminalBridge.addText(13, 11, tostring(textInput), 0xFFFFFF)
- dispText.setZIndex(1)
- end
- function fadeOut(opacity)
- print("fadeOut")
- dispText.setText("")
- for i = dispBox.getOpacity2(), 0, -0.00006 do dispBox.setOpacity2(i*2) dispLine.setOpacity(i*2) end
- sysStatus = "idle""", 0xFFFFFF)
- dispLine = terminalBridge.addBox(7, 7, 1, 15, 0x347D0A, 0.0)
- if textInput ~= dispText.getText() then --What we're displaying isn't updated.
- if dispLine.getOpacity2() == 0 then --Our display isn't up.
- print("The display isn't up!")
- fadeIn(textInput)
- else --Our display is up, but not with the right text.
- print("The display is up!")
- fadeOut()
- fadeIn(textInput)
- end
- elseif textInput == dispText.getText() then -- Our text is correct.
- print("Our text is correct! Fade.")
- end
- if os.pullEvent("timer") or os.pullEvent("chat_command") then
- fadeOut()
- elseif os.pullEvent("chat_command") then
- fadeOut()
- getInput(p1)
- end
- --if event == "timer" or event == "chat_command" then
- -- fadeOut()
- --end
- end
- --[[
- sysStatus = "dispText" terminalBridge.clear() displayAE()
- stringL = math.floor(terminalBridge.getStringWidth(tostring(textInput)))
- boxW = stringL + 10
- -- addBox x, y, w, h, color, opacity
- -- Fade In
- dispLine = terminalBridge.addBox(7, 7, 1, 15, 0x347D0A, 0.0)
- for i = 0, 1, 0.00003 do dispLine.setOpacity(i) end
- dispBox = terminalBridge.addGradientBox(8, 7, boxW, 15, 0x000000, 0.0, 0x000000, 0.0, 2)
- for i = 0, boxW, boxW/30000 do dispBox.setWidth(i) dispBox.setOpacity2((i/dispBox.getWidth())/2.5) end
- dispText = terminalBridge.addText(13, 11, textInput, 0xFFFFFF)
- dispText.setZIndex(1)
- --sleep(2)
- os.startTimer(2)
- print("fadeOut")
- dispText.setText("")
- for i = 1, 0, -0.00003 do dispBox.setOpacity2(i/2.5) dispLine.setOpacity(i) end
- ]]--
- function transferItem(itemID, itemQty, doCraft)
- retrieveStorage()
- if doCraft then
- if itemStock[itemID] == nil then storedItems = 0 else storedItems = itemStock[itemID] end
- neededItems = itemQty - storedItems
- orderedCraft = false
- if neededItems > 0 then -- We'll need to craft some items.
- if not orderedCraft then
- sysBridge.craft(itemID, itemQty)
- orderedCraft = true
- fadeIn("Crafting "..tostring(neededItems).." of "..tostring(itemQty).." '"..tostring(idIndex[itemID]).."'...")
- while neededItems > 0 do -- Already ordered crafting. Waiting.
- retrieveStorage()
- if itemStock[itemID] == nil then storedItems = 0 else storedItems = itemStock[itemID] end
- neededItems = itemQty - storedItems
- print(storedItems)
- sleep(.5)
- end
- -- Once we get here, we have enough items.
- sysBridge.retrieve(itemID, itemQty, 4)
- --displayText("Finished crafting, moved "..tostring(itemQty).." '"..tostring(idIndex[itemID]).."'.")
- fadeOut()
- fadeIn("Finished crafting, moved "..tostring(itemQty).." '"..tostring(idIndex[itemID]).."'.")
- sysStatus = "dispText"
- os.startTimer(2)
- fadeOut()
- end
- else -- No need to craft, we have enough.
- sysBridge.retrieve(itemID, itemQty, 4)
- fadeIn("Moved "..tostring(itemQty).. " '"..tostring(idIndex[itemID]).."'.")
- sysStatus = "dispText"
- os.startTimer(2)
- local event = os.pullEvent()
- if event == "timer" or event == "chat_command" then fadeOut() end
- --displayText("Moved "..tostring(itemQty).. " '"..tostring(idIndex[itemID]).."'.")
- end
- else
- itemsMoved = sysBridge.retrieve(itemID, 1728, 4)
- displayText("Moved "..tostring(itemsMoved).." '"..tostring(idIndex[itemID]).."'.")
- end
- end
- retrieveIDs()
- retrieveCrafts()
- retrieveStorage()
- -------------
- while true do
- -------------
- local event, p1, p2, p3, p4 = os.pullEvent()
- displayAE()
- --[[ Input Handling ]]--
- --[[
- local chatEvent, input = os.pullEvent("chat_command")
- local userInput = {}
- for i in string.gmatch(input, "%S+") do
- table.insert(userInput, i)
- end
- ]]--
- function getInput(msg)
- for i in string.gmatch(p1, "%S+") do
- table.insert(userInput, i)
- end
- end
- local userInput = {}
- if event == "chat_command" then
- for i in string.gmatch(p1, "%S+") do
- table.insert(userInput, i)
- end
- elseif event == "timer" then
- fadeOut()
- end
- --[[
- if event == "timer" and sysStatus == "dispText" then
- fadeOut()
- end]]--
- --[[ Crafting Handling ]]--
- if userInput[1] == "craft" or userInput[1] == "make" then
- -- userInput[2] is quantity
- -- userInput[3] is item
- -- userInput[4] is optional, for transferring items
- if not tonumber(userInput[3]) then -- Received text input
- if itemIndex[userInput[3]] ~= nil then
- craftItem(tonumber(itemIndex[userInput[3]]), tonumber(userInput[2]), userInput[4])
- else
- displayText("Item '" ..tostring(userInput[3]).. "' not recognized.")
- end
- else
- craftItem(tonumber(userInput[3]), tonumber(userInput[2]), userInput[4])
- end
- --[[ Transfer Handling ]]--
- --[[ Item Transferring ]]
- elseif userInput[1] == "transfer" or userInput[1] == "move" then
- -- userInput[2] is quantity, or all
- -- userInput[3] is item name
- if not tonumber(userInput[3]) then -- Received text input
- if itemIndex[userInput[3]] ~= nil then
- if userInput[2] == "all" then
- transferItem(tonumber(itemIndex[userInput[3]]), tonumber(userInput[2]), false)
- elseif tonumber(userInput[2]) then
- transferItem(tonumber(itemIndex[userInput[3]]), tonumber(userInput[2]), true)
- end
- else
- displayText("Item '" ..tostring(userInput[3]).. "' not recognized.")
- end
- else
- transferItem(tonumber(userInput[3]), tonumber(userInput[2]), true)
- end
- --[[ Manual Item Indexing ]]--
- --[[ Item Indexing ]]--
- elseif userInput[1] == "index" then
- -- userInput[2] is name
- -- userInput[3] is ID
- -- userInput[4] is metadata
- if tonumber(userInput[2]) then displayText("Wrong format, second input should be the item name.")
- elseif not tonumber(userInput[3]) then displayText("Wrong format, third input should be the item ID.")
- elseif not tonumber(userInput[4]) and userInput[4] ~= nil then displayText("Wrong format, fourth input should be (optional) metadata.")
- elseif userInput[4] == nil then
- indexID(userInput[2],tonumber(userInput[3]))
- retrieveIDs()
- elseif userInput[4] ~= nil then
- indexID(userInput[2], (tonumber(userInput[4]) * 32768)+userInput[3])
- retrieveIDs()
- --else
- --indexID(userInput[2],tonumber(userInput[3]))
- --retrieveIDs()
- end
- --[[ Index Removal ]]--
- elseif userInput[1] == "unindex" or userInput[1] == "remove" then
- -- userInput[2] is the item name
- print("I'll look for the value of "..tostring(userInput[2]))
- removeID(userInput[2])
- --[[ Storage Checking ]]--
- elseif userInput[1] == "check" or userInput[1] == "num" or userInput[1] == "stock" then
- -- userInput[2] is name or ID
- retrieveStorage()
- if not tonumber(userInput[2]) then -- Received text
- if isIndexed(userInput[2]) then
- displayText("Currently " ..tostring(itemStock[itemIndex[userInput[2]]]).. " '" ..tostring(userInput[2]).. "' stored.")
- else
- displayText("Item '" ..tostring(userInput[2]).. "' not recognized.")
- end
- end
- --[[ Multiplacation ]]--
- elseif userInput[1] == "math" then
- local eval, error = loadstring("return " ..userInput[2])
- if error then
- displayText("Error processing '" ..tostring(userInput[2]).. "'.")
- else
- displayText(tostring(formatNumber(eval())))
- end
- --[[ Display Request ]]--
- elseif userInput[1] == "display" then
- for i in string.gmatch(p1, "display(.+)") do
- --fadeIn(i, 15)
- displayText(i)
- end
- elseif userInput[1] == "img" then
- drawImage(cobble, userInput[3], userInput[4], 1, 1, 0xFFFFFF)
- --[[ Modem Handling ]]--
- elseif userInput[1] == "toggle" or userInput[1] == "t" then
- modem.transmit(50, 50, tostring(userInput[2]))
- local modemMessage, p1, p2, p3, p4 = os.pullEvent("modem_message")
- if p4 then spawnerStatus = "off" else spawnerStatus = "on" end
- displayText("Toggled '"..tostring(userInput[2]).."' to "..tostring(spawnerStatus)..".")
- --[[ Enderchest Clear ]]--
- elseif userInput[1] == "clear" or userInput[1] == "empty" then
- modem.transmit(51, 51, "go")
- displayText("Clearing, please wait for a few seconds...")
- sleep(.5)
- modem.transmit(51, 51, "stop")
- local modemMessage, p1, p2, p3, p4 = os.pullEvent("modem_message")
- if p4 == "cleared" then displayText("Cleared the enderchest.") end
- retrieveStorage()
- elseif userInput[1] == "format" then
- formatNumber(userInput[2])
- end -- End of first if
- ---
- end
- ---
Advertisement
Add Comment
Please, Sign In to add comment