Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local FurnaceFillLevel = 2
- local ItemNames={
- arcaneCrystal="forbidden_arcanus:arcane_crystal",
- arcaneCrystalDust="forbidden_arcanus:arcane_crystal_dust",
- emptyBucket="minecraft:bucket",
- lavaBucket="minecraft:lava_bucket"
- }
- local PeripheralTypes={
- basin="create:basin",
- blastFurnace="minecraft:blast_furnace",
- drawer="standardDrawer"
- }
- local FurnaceSlots={
- top=1,
- bottom=2,
- output=3
- }
- local BasinSlots={
- input=1,
- output=10
- }
- local Peripherals={
- basins={},
- furnaces={},
- emptyBucketDrawer=nil,
- lavaBucketDrawer=nil,
- crystalDrawer=nil,
- setCrystalDrawer=function(self,name)
- self.crystalDrawer = self.wrap(name)
- local items = self.crystalDrawer.list()
- for slot,item in pairs(items) do
- if item.name == ItemNames.arcaneCrystal then
- self.crystalDrawer.crystalSlot = slot
- elseif item.name == ItemNames.arcaneCrystalDust then
- self.crystalDrawer.dustSlot = slot
- end
- end
- if self.crystalDrawer.crystalSlot == nil then
- error("Couldn't find slot for arcane crystals")
- elseif self.crystalDrawer.dustSlot == nil then
- error("Couldn't find slot for crystal dust")
- end
- end,
- wrap=function(name)
- local perip = peripheral.wrap(name)
- perip.name = name
- return perip
- end,
- wrapAll=function(self)
- for _,name in ipairs(peripheral.getNames()) do
- local t = peripheral.getType(name)
- if t == PeripheralTypes.blastFurnace then
- table.insert(self.furnaces,self.wrap(name))
- elseif t == PeripheralTypes.basin then
- table.insert(self.basins,self.wrap(name))
- elseif t == PeripheralTypes.drawer then
- local p = self.wrap(name)
- if p.size() == 2 then
- self.crystalDrawer = p
- local items = p.list()
- for slot,item in pairs(items) do
- if item.name == ItemNames.arcaneCrystal then
- self.crystalDrawer.crystalSlot = slot
- elseif item.name == ItemNames.arcaneCrystalDust then
- self.crystalDrawer.dustSlot = slot
- end
- end
- if self.crystalDrawer.crystalSlot == nil then
- error("Couldn't find slot for arcane crystals")
- elseif self.crystalDrawer.dustSlot == nil then
- error("Couldn't find slot for crystal dust")
- end
- else
- local i = p.getItemDetail(1)
- if i ~= nil then
- if i.name == ItemNames.lavaBucket then
- self.lavaBucketDrawer = p
- elseif i.name == ItemNames.emptyBucket then
- self.emptyBucketDrawer = p
- end
- end
- end
- end
- end
- if self.lavaBucketDrawer == nil then
- error("Couldn't find lava bucket drawer")
- elseif self.emptyBucketDrawer == nil then
- error("Couldn't find empty bucket drawer")
- elseif self.crystalDrawer == nil then
- error("Couldn't find arcane crystal drawer")
- elseif #self.basins == 0 then
- error("Couldn't find any basins")
- elseif #self.furnaces == 0 then
- error("Couldn't find any blast furnaces")
- end
- end
- }
- local Processes={
- handleLava=function()
- local emptyFurnace = function(furnace)
- furnace.pushItems(Peripherals.emptyBucketDrawer.name,FurnaceSlots.bottom)
- end
- local addLavaToFurnace = function(furnace)
- Peripherals.lavaBucketDrawer.pushItems(furnace.name,1,1,FurnaceSlots.bottom)
- end
- while true do
- for _,furnace in ipairs(Peripherals.furnaces) do
- local item = furnace.list()[FurnaceSlots.bottom]
- if item == nil or item.count == 0 then
- addLavaToFurnace(furnace)
- elseif item.name == ItemNames.emptyBucket then
- emptyFurnace(furnace)
- addLavaToFurnace(furnace)
- end
- end
- sleep(10)
- end
- end,
- handleCrystals=function()
- local emptyBasin = function(basin)
- basin.pushItems(Peripherals.crystalDrawer.name,BasinSlots.output,nil,Peripherals.crystalDrawer.crystalSlot)
- end
- local fillFurnace = function(f,c)
- if not pcall(function()
- Peripherals.crystalDrawer.pushItems(f.name,Peripherals.crystalDrawer.crystalSlot,c,FurnaceSlots.top)
- end) then
- term.setTextColor(colors.red)
- print("Errored filling furnace "..f.name)
- print("Rewrapping crystal drawer")
- term.setTextColor(colors.white)
- Peripherals:setCrystalDrawer(Peripherals.crystalDrawer.name)
- end
- end
- while true do
- for _,basin in ipairs(Peripherals.basins) do
- emptyBasin(basin)
- end
- for _,furnace in ipairs(Peripherals.furnaces) do
- local items = furnace.list()
- if items[FurnaceSlots.top] == nil or items[FurnaceSlots.top].count < FurnaceFillLevel then
- local fillCount = FurnaceFillLevel
- if items[FurnaceSlots.top] ~= nil then
- fillCount = FurnaceFillLevel - items[FurnaceSlots.top].count
- end
- fillFurnace(furnace,fillCount)
- end
- end
- sleep(.5)
- end
- end,
- handleDust=function()
- local fillBasin = function(basin,count)
- if not pcall(function()
- Peripherals.crystalDrawer.pushItems(basin.name,Peripherals.crystalDrawer.dustSlot,count)
- end) then
- term.setTextColor(colors.red)
- print("Errored filling basin "..basin.name)
- print("Rewrapping crystal drawer")
- term.setTextColor(colors.white)
- Peripherals:setCrystalDrawer(Peripherals.crystalDrawer.name)
- end
- end
- local emptyFurnace = function(furnace)
- furnace.pushItems(Peripherals.crystalDrawer.name,FurnaceSlots.output)
- end
- while true do
- for _,furnace in ipairs(Peripherals.furnaces) do
- emptyFurnace(furnace)
- end
- local dustCount
- if not pcall(function()
- dustCount = Peripherals.crystalDrawer.list()[Peripherals.crystalDrawer.dustSlot].count
- end) then
- term.setTextColor(colors.red)
- print("Errored getting dust count in drawer")
- print("Rewrapping crystal drawer")
- term.setTextColor(colors.white)
- Peripherals:setCrystalDrawer(Peripherals.crystalDrawer.name)
- else
- local dustPerBasin = math.ceil(dustCount / #Peripherals.basins)
- for _,basin in ipairs(Peripherals.basins) do
- local items = basin.list()
- local existingCount = 0
- if items[BasinSlots.input] ~= nil then
- existingCount = items[BasinSlots.input].count
- end
- if existingCount < 64 then
- fillBasin(basin,math.min(
- dustPerBasin,
- 64 - existingCount
- ))
- end
- end
- end
- sleep(.1)
- end
- end
- }
- Peripherals:wrapAll()
- parallel.waitForAll(
- Processes.handleLava,
- Processes.handleCrystals,
- Processes.handleDust
- )
Add Comment
Please, Sign In to add comment