Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Config
- local chests = {peripheral.wrap("front")}
- local steps = {15}
- local dropoff = peripheral.wrap("back")
- local items = {{
- {'minecraft:obsidian'},
- {'byg:lignite', 'byg:lignite_block'},
- {'minecraft:coal', 'minecraft:coal_block'},
- {'byg:anthracite', 'byg:anthracite_block'},
- {'minecraft:lapis_lazuli', 'minecraft:lapis_block'},
- {'minecraft:redstone', 'minecraft:redstone_block'},
- {'create:copper_nugget', 'create:copper_ingot', 'create:copper_block'},
- {'create:zinc_nugget', 'create:zinc_ingot', 'create:zinc_block'},
- {'minecraft:quartz', 'minecraft:quartz_block'},
- {'minecraft:iron_nugget', 'minecraft:iron_ingot', 'minecraft:iron_block'},
- {'minecraft:gold_nugget', 'minecraft:gold_ingot', 'minecraft:gold_block'},
- {'minecraft:emerald', 'minecraft:emerald_block'},
- {'minecraft:diamond', 'minecraft:diamond_block'},
- {'tconstruct:cobalt_nugget', 'tconstruct:cobalt_ingot', 'tconstruct:cobalt_block'},
- {'minecraft:ancient_debris'}
- }}
- -- Preprocessing
- local mapTo = {}
- for _, chest in ipairs(chests) do
- for col=1, steps[_] do
- local last = nil
- for i=1, math.floor(chest.size()/steps[_]), 2 do
- if items[_] and items[_][col] and items[_][col][i] then
- last = items[_][col][i]
- mapTo[items[_][col][i]] = {_=_, c=col, i=i, s=2}
- table.insert(items[_][col], i, items[_][col][i])
- end
- end
- if last then
- start, e = string.find(last, ":")
- last = string.sub(last, start+1)
- last = 'overloaded_cb:compressed_'..last
- for i=1, math.floor(chest.size()/steps[_])-#items[_][col] do
- table.insert(items[_][col], last..'_'..i)
- mapTo[last..'_'..i] = {_=_, c=col, i=#items[_][col], s=1}
- end
- end
- end
- end
- while(true) do
- -- Item extraction
- for _, chest in ipairs(chests) do
- for col=1, steps[_] do
- for i=1,math.floor(chest.size()/steps[_]) do
- local slot = (i-1)*steps[_]+col
- local item = chest.getItemDetail(slot)
- local pattern = "-"
- if items[_] and items[_][col] and items[_][col][i] then
- pattern = items[_][col][i]
- end
- if item and item.name ~= pattern then
- dropoff.pullItems(peripheral.getName(chest), slot)
- end
- end
- end
- end
- -- Item insertion
- for slot, item in pairs(dropoff.list()) do
- if mapTo[item.name] then
- local p = mapTo[item.name]
- for s=1, p.s do
- chests[p._].pullItems(peripheral.getName(dropoff), slot, 64, (p.i+s-2)*steps[p._]+p.c)
- end
- -- Up-crafting
- local leftover = dropoff.getItemDetail(slot)
- if leftover and leftover.count >= 9 then
- local portion = math.floor(leftover.count/9)
- dropoff.pushItems("bottom", slot, portion*9)
- turtle.select(1)
- turtle.suckDown(portion*9)
- local craftPos = {2, 3, 5, 6, 7, 9, 10, 11}
- for j, cp in ipairs(craftPos) do
- turtle.transferTo(cp, portion)
- end
- turtle.craft()
- turtle.dropDown()
- dropoff.pullItems("bottom", 1)
- end
- dropoff.pullItems(peripheral.getName(dropoff), slot)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment