Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --# Program Config
- local turtleFromDrawerDirection = "north"
- local turtleFromChestLocation = "south"
- local programRestartInterval = 1.00 -- Program run interval
- local maxEssentiaAmount = 2000
- local maxEssentiaAmountMessages = false
- --### ONLY MODFIY BELOW IF YOU KNOW WHAT YOU ARE DOING
- ---------------------------------------------------------------------------------------------------------------
- --### Static list of items containing specific essentia
- local itemHashList = {
- -- Etheal Essence
- ["f36968d453592c101629ff03dbbfee26"] = "machina",
- ["d5a708b5e6cf0f421e7dc9355d304dae"] = "ira",
- ["9124a2acb4161cb0484ccc06924c8e5c"] = "vinculum",
- ["69f0f950fc1af7fe3b5cd76b96fe2a12"] = "tempus",
- ["951cbfb1ee185cc2a0db21a7ee5c4658"] = "herba",
- ["2e0923f828ce335b6356bf1fde489986"] = "instrumentum",
- ["404d0f64c5aeb1fecc174850bf606a0f"] = "arbor",
- ["aa7b17df81fa0be6959f653e259d6a49"] = "meto",
- ["6a7f52f93c5b4558bdbfe12e52ea0209"] = "fabrico",
- ["7168677549d5906cd2fee78349113047"] = "invidia",
- ["74d6ce35611a333020364e921b5864bf"] = "pannus",
- ["2cf039eb58826a770024b859478bdf13"] = "desidia",
- ["50a0d85a9992ecdb9efce7d8a5fc7b15"] = "vitium",
- ["1100f8a3629369e4bd219f2b30d978ac"] = "messis",
- ["4b3878326e97bda1f0c8f02d43e1f724"] = "limus",
- ["3306eb2763dcd8bee9f4e77aa3a916bc"] = "perfodio",
- ["4058af44332d4a3c020ba28595eafe09"] = "tempestas",
- ["33992e4570fb0c5a46061cfe0a0f1550"] = "volatus",
- ["1e995bd21733e006a757af6511adeb14"] = "motus",
- ["c1266ba6956c8507b976ed0af0fe921c"] = "tenebrae",
- ["2d46425f72b47ee82e008df41fe44ff0"] = "fames",
- ["62ab1d0d4ce536081358faa06507f2a8"] = "superbia",
- ["d428fcfe78d4f204a1b7d7c88c597f4d"] = "lucrum",
- ["8e8405341043a4dc957058fea34f7fde"] = "gula",
- ["96e68bba97a9197b08e8b218f89f6cd1"] = "praecantatio",
- ["4b753601ce070e02ae12c0744afa8b01"] = "sensus",
- ["cc1b1319bed11adb3fb1133cfce0a9fc"] = "auram",
- ["c22f882f5d3ad66818112f7e109ed065"] = "humanus",
- ["1490e650a531f04fb231561dfb3cbc1c"] = "vacuos",
- ["b30a393ba36c2914da2124e0c15ba6c6"] = "metallum",
- ["651ed7f8722d8528927ffeb78c3b36af"] = "lux",
- ["503677942dd95011d466c40d7b305e4e"] = "mortuus",
- ["ef0a022b50093731e91c1775e9a6b2c4"] = "telum",
- ["552c659fd588d96f66fd2ad07a4948c6"] = "luxuria",
- ["b39c13da67e0f8fc6a1b415281dc1eb7"] = "tutamen",
- ["76fca4fc64045eb94d1e8eb9ef6d5721"] = "infernus",
- ["f37ca1c21238fb6d1a803ff3697bae37"] = "iter",
- ["6e496450ecf5f1366f504787abc1a7ce"] = "exanimis",
- ["ec96883e36124223662ee4b55e00ac43"] = "alienis",
- ["1af1aa4c0de6f05411c2921f8ea49ada"] = "cognitio",
- ["2e3aaf69f3b0eb9dc91d649ebfd7a6d6"] = "ordo",
- ["dfb1cc975c8f94b2743ac3d5271869a1"] = "potentia",
- ["665401c955afa0b1d77a63a9b8421b37"] = "perditio",
- ["69e96cbd20cf95621d1194fe3b700c5b"] = "permutatio",
- ["8bd1142ca027f3f3f2a7ea86420a4be7"] = "spiritus",
- ["fa69d331cb2d38384e02086c506eaa43"] = "bestia",
- ["dccfa897b53c2b437372cbb24c6e09b3"] = "sano",
- ["fc82a45802f77b91a76fa9f951de83bd"] = "corpus",
- ["c633bfdcd33be5dd1a75f6aff84d2ecf"] = "ignis",
- ["46239a9297df5f8f6b074e3735706db6"] = "victus",
- ["1cb399bc43c8bc3b7a6e53ee7c4b2652"] = "aqua",
- ["2ec178e9e6aa8958d7df1af5d3203999"] = "venenum",
- ["964fdc73a1032004ae92c5faaff017f0"] = "aer",
- ["7e83cd135885aa779957eda2a7f0778c"] = "gelum",
- ["f85a995d3cb9a4f606140f2191a5afc6"] = "terra",
- ["b9f3d17344cf347090104b28d49cfce0"] = "vitreus",
- }
- ---------------------------------------------------------------------------------------------------------------
- --### Helper Functions
- function firstCharacterUpperCase(str)
- return str:sub(1,1):upper()..str:sub(2)
- end
- function itemInfo(item,slot)
- moveFromDrawerToChest(slot,1)
- for i,v in pairs(item) do
- write(i)
- write(":")
- print(v)
- end
- end
- --### Helper Functions
- ---------------------------------------------------------------------------------------------------------------
- --### EssentiaProvider Functions
- local ep = peripheral.find("EssentiaProvider")
- local essentiaAmount = {}
- if not ep then
- error("\n\nNo EssentiaProvider detected.\nPlace on any side.")
- end
- function checkEssentiaProvider()
- if not ep.isOnline() then
- error("\n\nEssentiaProvider offline.")
- end
- end
- function prepareEssentiaProvider()
- checkEssentiaProvider()
- local success = ep.registerAsWatcher()
- write("registerAsWatcher() ")
- if success then
- print("done")
- else
- print("failed")
- end
- end
- function updateEssentiaAmounts()
- checkEssentiaProvider()
- essentiaAmount = {}
- local tmpLevel = {ep.getAspects()}
- for i=1,#tmpLevel,2 do
- e = tmpLevel[i]
- n = tmpLevel[i+1]
- essentiaAmount[e:lower()] = n
- end
- end
- function getEssentiaAmount(essentia)
- updateEssentiaAmounts()
- return essentiaAmount[essentia] or 0
- end
- function testEssentia(essentia)
- if essentia then
- print(firstCharacterUpperCase(essentia)..":"..getEssentiaAmount(essentia))
- end
- end
- --### EssentiaProvider Functions
- ---------------------------------------------------------------------------------------------------------------
- --### Drawer Functions
- local d = peripheral.find("storagedrawers_container_controller")
- local items = {} -- knows which slot to use for which essentia type
- if not d then
- error("\n\nNo drawer controller detected.\nPlace on any side.")
- end
- function scanDrawerInventory()
- slots = {}
- for slot=1, d.getInventorySize() do -- run through every slot in drawer
- local item = d.getStackInSlot(slot) -- get ItemInformation
- if item then -- item in slot ?
- local hash = item["nbt_hash"] -- get its hash
- local a = itemHashList[hash] -- get essence for that hash
- if a then -- hash in itemHashList?
- local tmp = {["slot"] = slot}
- items[a] = tmp
- else
- print(item["id"].." not in itemHashList !!!") -- that item is not in itemHashList
- itemInfo(item,slot)
- end
- end
- end
- end
- function getSlotOfAspectItem(aspect)
- return items[aspect]["slot"] or -1
- end
- function getAmountOfAspectItem(aspect)
- return d.getStackInSlot(items[aspect]["slot"])["qty"] or 0
- end
- --### Drawer Functions
- ---------------------------------------------------------------------------------------------------------------
- --### Chest Functions
- local c = peripheral.find("chest") or peripheral.find("iron") or peripheral.find("crystal")
- if not c then
- error("\n\nNo output chest detected.\nPlace on any side.")
- end
- function allFromTurtleToChest()
- for i=1,16 do
- c.pullItem(turtleFromChestLocation,i)
- end
- end
- function fromTurtleToChest(slot)
- c.pullItem(turtleFromChestLocation,slot)
- end
- --### Chest Functions
- ---------------------------------------------------------------------------------------------------------------
- --### Program Functions
- function moveFromDrawerToChest(slot, nrOfItems)
- d.pushItem(turtleFromDrawerDirection, slot, nrOfItems)
- --allFromTurtleToChest()
- fromTurtleToChest(1)
- end
- function refillEssentia(aspect, amount)
- local essentiaPerItem = 2 -- 2 hardcoded for etheral essence
- local nrOfItems = math.ceil(amount/essentiaPerItem)
- --print("Try refilling "..amount.." "..firstCharacterUpperCase(aspect).." with "..nrOfItems.." items.")
- print("Try refilling "..amount.." "..firstCharacterUpperCase(aspect))
- local slot = getSlotOfAspectItem(aspect)
- local stored = getAmountOfAspectItem(aspect)
- if slot ~= nil then
- if stored < nrOfItems then
- print("Too less items to restore all "..amount.." essentia. Only "..stored.." available.")
- nrOfItems = stored
- end
- --print("Refilling "..firstCharacterUpperCase(aspect).." with "..nrOfItems.." items. / "..nrOfItems*essentiaPerItem.." essentia")
- print("Refilling "..firstCharacterUpperCase(aspect).." with "..nrOfItems.." items.")
- moveFromDrawerToChest(slot, nrOfItems)
- else
- print("No Item for "..firstCharacterUpperCase(aspect).." found.")
- end
- end
- function checkForEssentiaRefill(aspect,amount)
- local level = getEssentiaAmount(aspect)
- if amount < 0 then
- if level < maxEssentiaAmount then
- refillEssentia(aspect, -1*amount)
- else
- if printMaxEssentiaAmountMessages then
- print("Reached maxEssentiaAmount for "..firstCharacterUpperCase(aspect).." ("..level.."/"..maxEssentiaAmount..")")
- end
- end
- else
- -- print message if
- if level < maxEssentiaAmount then
- print(amount.." "..firstCharacterUpperCase(aspect).." refilled.")
- end
- end
- end
- --### Program Functions
- ---------------------------------------------------------------------------------------------------------------
- --### Default Main Program Functions
- function preRunProgram()
- checkEssentiaProvider()
- end
- function runProgram()
- end
- function postRunProgram()
- end
- local STOP = false
- local PROGRAM_RUN_TIMER = nil
- function handleEvent(event)
- if event[1] == "timer" and event[2] == PROGRAM_RUN_TIMER then
- preRunProgram()
- runProgram()
- postRunProgram()
- PROGRAM_RUN_TIMER = os.startTimer(programRestartInterval)
- return
- end
- if event[1] == "char" and event[2] == "t" then
- STOP = true
- print("Termination Key detected.\n!!! Terminating the program !!!")
- return
- end
- if event[1] == "essentia" then
- if event[2] == 1 then
- --essentia event
- checkForEssentiaRefill(event[3]:lower(), event[4]) -- essentia and amount
- return
- end
- if event[2] == 2 then
- --power event
- if event[3] then
- print("EssentiaProvider disconnected from the network")
- STOP = true
- else
- print("EssentiaProvider connected to the network")
- end
- return
- end
- if event[2] == 3 then
- --detach event
- STOP = true
- print("Lost connection with EssentiaProvider")
- return
- end
- end
- local ignoreList = {"char", "key", "key_up", "mouse_click", "mouse_up", "mouse_drag", "mouse_scroll", "rednet", "turtle_inventory"}
- for i,v in pairs(ignoreList) do
- if event[1] == v then
- return
- end
- end
- print("unhandeled event:")
- for i,v in pairs(event) do
- write(i)
- write(":")
- print(v)
- end
- end
- function preLoop()
- term.clear()
- term.setCursorPos(1,1)
- prepareEssentiaProvider()
- scanDrawerInventory()
- print("EssentiaRefiller started")
- PROGRAM_RUN_TIMER = os.startTimer(0)
- end
- function loop()
- while not STOP do
- handleEvent({os.pullEvent()})
- end
- end
- function postLoop()
- end
- --### Default Main Program Functions
- ---------------------------------------------------------------------------------------------------------------
- preLoop()
- loop()
- postLoop()
Add Comment
Please, Sign In to add comment