Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Todo
- -- - Create and display interface on sorting computer for adding items to be sorted to a sorting database.
- -- -- Should allow adding items to be macerated.
- -- -- Should allow adding items to be furnaced.
- -- -- Should allow editing and deleting of existing items.
- -- my libraries
- -- check dir exists, if not make it
- if not fs.exists("/libs") then--{{{
- fs.makeDir("/libs")
- end--}}}
- function update_lib(pastebin_id, dest_path)--{{{
- if fs.exists(dest_path) then
- fs.delete(dest_path)
- end
- shell.run("pastebin get " .. pastebin_id .. " " .. dest_path)
- os.loadAPI(dest_path)
- end--}}}
- update_lib("qUpykFN4", "libs/ccmisc")
- update_lib("n1S2GpfD", "libs/sorterAPI")
- -- clear library spam
- term.setCursorPos(1,1)
- term.clear()
- -- end my libraries
- Sorter = {--{{{
- delay = 5,
- stackDelay = 2,
- sorter = peripheral.wrap("bottom"),
- maceratorCompID = 86,
- furnaceCompID = 87,
- enderChestSide = 4,
- maceratorSide = 2,
- furnaceSide = 3,
- storageSide = 0,
- modem = rednet.open("top"),
- macerate_items = {--{{{
- --["4,0"] = true, -- Cobblestone
- ["14,0"] = true, -- Gold Ore
- ["15,0"] = true, -- Iron Ore
- ["16,0"] = true, -- Coal Ore
- ["238,0"] = true, -- Iron Ore
- ["248,0"] = true, -- Tin Ore
- ["249,0"] = true, -- Copper Ore
- ["902,0"] = true, -- Certus Quartz Ore
- ["1398,1"] = true, -- Copper Ore
- ["1398,2"] = true, -- Tin Ore
- ["1488,0"] = true, -- Iron Gravel Ore
- ["2001,0"] = true, -- Copper Ore Ore
- ["2001,1"] = true, -- Tin Ore
- ["2001,2"] = true, -- Silver Ore
- ["2001,3"] = true, -- Lead Ore
- ["2001,4"] = true, -- Ferrous Ore
- ["4060,1"] = true, -- Gelena Ore
- ["4060,5"] = true, -- Bauxite Ore
- ["4060,13"] = true, -- Tetrahedrite Ore
- ["4060,14"] = true, -- Cassiterite Ore
- },--}}}
- furnace_items = {--{{{
- ["363,0"] = true, -- Raw Beef
- ["365,0"] = true, -- Raw Chicken
- ["1475,5"] = true, -- Aluminium Ore
- ["1488,4"] = true, -- Aluminium Gravel Ore
- ["2402,0"] = true, -- Cinnabar Ore
- --["5362,8"] = true, -- Iron Dust
- --["5362,9"] = true, -- Gold Dust
- ["5362,20"] = true, -- Basic Processor Assembly
- --["31988","244"] = true, -- Tin Dust
- ["20267,1"] = true, -- Pulverized Gold
- ["20267,32"] = true, -- Pulverized Copper
- ["25286,16"] = true, -- Native Iron Cluster
- ["25286,17"] = true, -- Native Copper Cluster
- ["25286,18"] = true, -- Native Tin Cluster
- ["25286,19"] = true, -- Native Silver Cluster
- ["25286,20"] = true, -- Native Lead Cluster
- ["25286,31"] = true, -- Native Gold Cluster
- },--}}}
- }--}}}
- function Sorter:shouldMacerate(item)--{{{
- idmeta = tostring(item[1]) .. "," .. tostring(item[2])
- if self.macerate_items[idmeta] then
- return true
- end
- return false
- end--}}}
- function Sorter:shouldFurnace(item)--{{{
- idmeta = tostring(item[1]) .. "," .. tostring(item[2])
- if self.furnace_items[idmeta] then
- return true
- end
- return false
- end--}}}
- function Sorter:maceratorHasSpace()--{{{
- return self:hasSpace(self.maceratorCompID, "Macerator")
- end--}}}
- function Sorter:hasSpace(computerID, name)--{{{
- rednet.send(computerID, 'hasSpace')
- local computerid, message = rednet.receive(4)
- if message then
- print("Received: " .. textutils.serialize(message))
- if string.find(message, tostring(computerID)) then
- if string.find(message,"noSpace") then
- print(name .. " has no space")
- return false
- else
- print(name .. " has space")
- return true
- end
- else
- print("Unknown message " .. message)
- end
- else
- print(name .. " message was nil")
- end
- end--}}}
- function Sorter:furnaceHasSpace()--{{{
- return self:hasSpace(self.furnaceCompID, "Furnace")
- end--}}}
- function Sorter:macerateItem(uuid, count)--{{{
- self.sorter.extract(self.enderChestSide, uuid, self.maceratorSide, count)
- end--}}}
- function Sorter:furnaceItem(uuid, count)--{{{
- self.sorter.extract(self.enderChestSide, uuid, self.furnaceSide, count)
- end--}}}
- function Sorter:storeItem(uuid, count)--{{{
- self.sorter.extract(self.enderChestSide, uuid, self.storageSide, count)
- end--}}}
- function Sorter:list()--{{{
- return self.sorter.list(self.enderChestSide)
- end--}}}
- function Sorter:toggleMacerateCobble()--{{{
- if not self.macerate_items["4,0"] then
- print("Macerating cobble to sand")
- self.macerate_items["4,0"] = true
- else
- print("Not macerating cobble to sand")
- self.macerate_items["4,0"] = false
- end
- end--}}}
- function Sorter:mainLoop()--{{{
- os.startTimer(self.delay)
- while true do
- event, param1, param2, param3 = os.pullEvent()
- if event == 'timer' then
- for uuid,count in pairs(self:list()) do
- item = sorterAPI.getID(uuid)
- if self:shouldFurnace(item) then -- check if furnace
- if self:furnaceHasSpace() then
- self:furnaceItem(uuid, 64)
- end
- elseif self:shouldMacerate(item) then -- check if should macerate
- os.sleep(self.stackDelay)
- if self:maceratorHasSpace() then
- self:macerateItem(uuid, 64)
- end
- else -- store
- self:storeItem(uuid, count)
- end
- end
- os.startTimer(self.delay)
- elseif event == 'key' then
- --print(tostring(param1))
- if param1 == 46 then -- 'c'
- self:toggleMacerateCobble()
- end
- end
- end
- end--}}}
- sorter = Sorter
- sorter:mainLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement