Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --автокрафт
- local robot = component.proxy(component.list("robot")())
- local inv = component.proxy(component.list("inventory_controller")())
- local crafting = component.proxy(component.list("crafting")())
- local db = component.proxy(component.list("database")())
- local slots = {
- [1] = {database = 1, inventory = 1},
- [2] = {database = 2, inventory = 2},
- [3] = {database = 3, inventory = 3},
- [4] = {database = 4, inventory = 5},
- [5] = {database = 5, inventory = 6},
- [6] = {database = 6, inventory = 7},
- [7] = {database = 7, inventory = 9},
- [8] = {database = 8, inventory = 10},
- [9] = {database = 9, inventory = 11},
- }
- local frontsize = inv.getInventorySize(3)
- local buffer = tonumber(robot.name()) or 64
- local real = {}
- function getSlots() -- put database info into variable
- for i = 1,9 do
- local t = db.get(slots[i].database)
- if t then
- real[slots[i].inventory] = t.label
- end
- end
- end
- function suckSlot(slot) -- sucks appropriate item into slot, returns true if sucked all
- local toSuck = buffer - robot.count(slot)
- if toSuck > 0 then
- robot.select(slot)
- for i = 1,frontsize do
- local ttt = inv.getStackInSlot(3,i)
- if ttt then
- if ttt.label == real[slot] then
- if ttt.size >= toSuck then
- inv.suckFromSlot(3,i,toSuck)
- toSuck = 0
- return true
- else
- inv.suckFromSlot(3,i,ttt.size)
- toSuck = toSuck - ttt.size
- end
- end
- end
- end
- else
- return true
- end
- end
- function keysLeft(table)
- for k,_ in pairs(table) do
- computer.pullSignal(2)
- return true
- end
- return false
- end
- function suck() -- makes sure everything is in place to start crafting
- local left = {}
- for k,_ in pairs(real) do
- left[k] = 1
- end
- repeat
- for k,_ in pairs(left) do -- sucks only into slots that arent full yet
- if suckSlot(k) == true then
- left[k] = nil
- end
- end
- until keysLeft(left) == false
- end
- function craft()
- robot.select(13)
- crafting.craft(buffer)
- for i = 13,16 do
- robot.select(i)
- robot.drop(3,buffer)
- end
- end
- --
- getSlots()
- while true do
- suck()
- craft()
- end
Advertisement
Add Comment
Please, Sign In to add comment