Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ------------------------------------------------------- Main Code
- ---------------------- Get peripherals
- Output_P = peripheral.find("storagedrawers:controllerslave")
- Input_P = peripheral.find("storagedrawers:controller")
- Furnace_P = peripheral.find("minecraft:tconstruct_seared_furnace")
- Monitor_P = peripheral.find("monitor")
- if Monitor_P then
- term.redirect(Monitor_P)
- Monitor_P.setTextScale(0.5)
- end
- term.setTextColor(colors.green)
- print('\n\n\n\n\n\n\n\n\n\n\n\n\nStarted Up...')
- ------------------------------------------------------------------------------------------------------------------
- ------------------------------------------------------------------------------------------------------------------
- ------------------------------------------------------------------------------------------------------------------
- -------- print peripherals
- for _, X in ipairs (peripheral.getNames()) do
- print (X)
- end
- function printSubTables(DATA)
- if type(DATA) == 'table' then
- for k,v in pairs(DATA) do
- if type(v) == 'table' then
- printSubTables(DATA)
- end
- end
- else
- print(DATA)
- end
- end
- ------- print peripheral methods
- function PrintPeripheralMethods(peripheral_Q)
- for n, METHOD in pairs(peripheral.getMethods(peripheral.getName(peripheral_Q))) do
- print(' -', n, METHOD)
- end
- end
- function DeepPrint (e)
- -- if e is a table, we should iterate over its elements
- if type(e) == "table" then
- for k,v in pairs(e) do -- for every element in the table
- print(' -'..k, ' = ', v)
- DeepPrint(v) -- recursively repeat the same procedure
- end
- end
- end
- function printTableKeysAndValues(Table, Depth)
- for i in pairs(Table) do --For filled every slot in Input Inventory
- TableEntry = Table[i]
- for key, value in pairs(TableEntry) do
- -- Add spaces infront of the text
- TD = Depth or 0
- for x=1,TD,1 do io.write(' ') end
- -- print key and its value
- print('["' .. key .. '"] and value of '.. tostring(value))
- end
- print('')
- end
- end
- -- Monitor_P.setTextColor(colors.green)
- -- print('Output_P Inventory:')
- -- -- PrintPeripheralMethods(Input_P)
- -- DeepPrint(Output_P.list())
- -- Monitor_P.setTextColor(colors.blue)
- -- print('Input_P Inventory:')
- -- -- PrintPeripheralMethods(Input_P)
- -- DeepPrint(Input_P.list())
- -- Monitor_P.setTextColor(colors.red)
- -- print('Input_P Inventory:')
- -- -- PrintPeripheralMethods(Input_P)
- -- DeepPrint(Input_P.list())
- -- Monitor_P.setTextColor(colors.yellow)
- -- print('Furnace_P Inventory:')
- -- -- PrintPeripheralMethods(Input_P)
- -- DeepPrint(Furnace_P.list())
- -- Monitor_P.setTextColor(colors.white)
- function CatchAndPrintError(Func)
- local ran, errorMsg = xpcall(Func, Func)
- if not ran then
- term.setTextColor(colors.red)
- print("\n --ERROR, --->")
- print(tostring(errorMsg))
- print(type(errorMsg))
- print('Terminated.')
- end
- end
- ------------------------------------------------------------------------------------------------------------------
- ------------------------------------------------------------------------------------------------------------------
- ------------------------------------------------------------------------------------------------------------------
- function ValidSmeltable(ItemName)
- if string.find(ItemName, 'Pulverized') or string.find(ItemName, 'Blend') or string.find(ItemName, 'Dust') or string.find(ItemName, 'Grit') then
- return true
- else
- return false
- end
- end
- function ValidOre(ItemName)
- if string.find(ItemName, 'Ore') or string.find(ItemName, 'ore') then
- return true
- else
- return false
- end
- end
- --------------------------------------------------------------------------------
- --------------------------------------------------------------------------------
- --------------------------------------------------------------------------------
- FurnaceItemSlotsCache = {}
- DustsItemSlotsCache = {}
- function SummarizeInventoryTable(TableToSummarize)
- -- print('\n\nSummarizeInventoryTable9000 Reports:')
- local TempCache = {}
- -- check if item type exists in TempCache, if not. add it!
- for T_i in pairs(TableToSummarize) do
- IN = TableToSummarize[T_i][1]
- IA = TableToSummarize[T_i][2]
- IsNewCacheEntry = true
- -- if entry for this item type was found in the Cache, add its value to the given entry.
- for C_i in pairs(TempCache) do
- if IN == TempCache[C_i][1] then
- IsNewCacheEntry = false
- -- print('match Found! Adding Value to existing match!')
- -- print(' + ', IA, IN)
- TempCache[C_i][2] = TempCache[C_i][2] + IA
- end
- end
- -- if no entry for this item type was found in the Cache, add it as a new entry.
- if IsNewCacheEntry then
- NewCacheEntry = {IN, IA}
- table.insert(TempCache, NewCacheEntry)
- end
- end
- -- -- Table Reporter
- -- print('\n - Table Reports:')
- -- for i in pairs(TableToSummarize) do
- -- IN = TableToSummarize[i][1]
- -- IA = TableToSummarize[i][2]
- -- print(' -', IN, IA)
- -- end
- -- -- Cache Reporter
- -- print('\n - Cache Reports:')
- -- for i in pairs(TempCache) do
- -- IN = TempCache[i][1]
- -- IA = TempCache[i][2]
- -- print(' -', IN, IA)
- -- end
- return TempCache
- end
- function HandleFurnaceInventory()
- FurnaceItemSlotsCache = {}
- for SlotNum in pairs(Furnace_P.list()) do --For filled every slot in Input Inventory
- local ItemName = Furnace_P.getItemMeta(SlotNum)['displayName'] -- get the display name of item in slot
- -- if the item name contains a Valid key word
- if string.find(ItemName, 'Ingot') then
- local ItemAmount = Furnace_P.getItemMeta(SlotNum)['count'] -- get the item amount of item in slot
- local MiniData = {ItemName, ItemAmount}
- table.insert(FurnaceItemSlotsCache, MiniData)
- Furnace_P.pushItems(peripheral.getName(Output_P), SlotNum)
- -- print('Sending ', ItemName, ItemAmount, ' into Output')
- io.write('.')
- end
- end
- -- Print Summarization of the Inventory
- print('')
- DATA = SummarizeInventoryTable(FurnaceItemSlotsCache)
- for i in pairs(DATA) do
- IN = DATA[i][1]
- IA = DATA[i][2]
- print(' -'..IA..'- '..IN)
- end
- end
- function HandleDustsInventory()
- DustsItemSlotsCache = {}
- for SlotNum in pairs(Input_P.list()) do --For filled every slot in Input Inventory
- local ItemName = Input_P.getItemMeta(SlotNum)['displayName'] -- get the display name of item in slot
- -- if the item name contains a Valid key word
- if ValidSmeltable(ItemName) then
- local ItemAmount = Input_P.getItemMeta(SlotNum)['count'] -- get the item amount of item in slot
- local MiniData = {ItemName, ItemAmount}
- table.insert(DustsItemSlotsCache, MiniData)
- Input_P.pushItems(peripheral.getName(Furnace_P), SlotNum)
- -- print('Sending ', ItemName, ItemAmount, ' into furnace')
- io.write('.')
- else
- term.setTextColor(colors.red)
- print('\n --ERROR, "'.. ItemName .. '" is not a valid dust type!')
- end
- end
- -- Print Summarization of the Inventory
- print('')
- DATA = SummarizeInventoryTable(DustsItemSlotsCache)
- for i in pairs(DATA) do
- IN = DATA[i][1]
- IA = DATA[i][2]
- print(' -'..IA..'- '..IN)
- end
- end
- -------------------- Run Item Processing Loop
- function RunLoop()
- os.sleep(1)
- term.setTextColor(colors.blue)
- print('\n\n\nExporting Ingots from Furnace...')
- term.setTextColor(colors.lightBlue)
- CatchAndPrintError(HandleFurnaceInventory)
- --HandleFurnaceInventory()
- term.setTextColor(colors.blue)
- print('Done.')
- os.sleep(1)
- term.setTextColor(colors.orange)
- print('\n\n\nInserting Smeltables Into Furnace...')
- term.setTextColor(colors.yellow)
- -- HandleDustsInventory()
- CatchAndPrintError(HandleDustsInventory)
- term.setTextColor(colors.orange)
- print('Done.')
- os.sleep(1)
- term.setTextColor(colors.purple)
- print('\n\n\nCycle Done, Sleeping for 10 seconds. - Elephant\n')
- os.sleep(10)
- end
- while true do
- RunLoop()
- -- term.setTextColor(colors.white)
- -- print('Loop Begun')
- -- CatchAndPrintError(RunLoop)
- -- term.setTextColor(colors.white)
- -- print('Loop End')
- end
- print('Code Finished for an unknown reason, Error(?).')
Advertisement
Add Comment
Please, Sign In to add comment