Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local c = component.crafting
- local ic = component.inventory_controller
- local r = require("robot")
- numslot = ic.getInventorySize(1)
- hotslotchest = 0
- if numslot == nil then
- print("Сундук над роботом не найден!")
- else
- print("Всего слотов в сундуке:"..numslot)
- end
- if(ic.getStackInSlot(1,1) ~= nil) then
- if(ic.getStackInSlot(1,1)["label"] == "Diamond Hoe") then
- print("Путь:"..os.getenv("PWD"))
- file = io.open(os.getenv("PWD") .."/curentcraft.txt","w")
- for j = 2, 10 do
- if ic.getStackInSlot(1,j) == nil then
- item = "<empty>"
- else
- item = ic.getStackInSlot(1,j)["label"]
- end
- file:write(item.."\n")
- end
- file:close()
- print("Крафт успешно записан!")
- os.exit()
- end
- end
- file = io.open(os.getenv("PWD") .."/curentcraft.txt","r")
- if file == nil then
- print("Файл крафта не найден!")
- os.exit()
- end
- local arr = {}
- for line in file:lines() do
- table.insert (arr, line);
- end
- file:close()
- setkacrafta = {1,2,3,5,6,7,9,10,11}
- itemforcraft = {arr[1], arr[2], arr[3],arr[4],arr[5],arr[6],arr[7],arr[8],arr[9]}
- r.select(4)
- function craftthis(counts)
- i = 0
- while i < counts do
- c.craft(64)
- r.dropUp(64)
- i = i + 1
- end
- end
- function loadItem(robotslot, chestslot)
- if chestslot == 0 then
- print("В сундуке не найден нужный предмет!")
- unloadallitem()
- else
- ic.suckFromSlot(1,chestslot,64)
- r.transferTo(robotslot,64)
- end
- end
- function unloadallitem()
- for j = 1, 16 do
- r.select(j)
- r.dropUp(64)
- end
- r.select(4)
- end
- function finditem(nameitem)
- onlyfirst = 0
- Cnumslot = numslot
- i = hotslotchest
- ::startfind::
- while i < Cnumslot do
- i = i + 1
- ItemStack = ic.getStackInSlot(1,i)
- if ItemStack ~= nil then
- if ic.getStackInSlot(1,i)["label"] == nameitem then
- hotslotchest = i
- return i
- end
- end
- end
- i = 0
- Cnumslot = hotslotchest
- onlyfirst = onlyfirst + 1
- if onlyfirst == 1 then goto startfind end
- return 0
- end
- doWork = true
- while doWork do
- craftthis(1)
- for j = 1, 9 do
- if itemforcraft[j] ~= "<empty>" then
- if r.count(setkacrafta[j]) < 1 then
- print("Кончилось "..itemforcraft[j].." в слоте "..setkacrafta[j].."...")
- loadItem(setkacrafta[j],finditem(itemforcraft[j]))
- if r.count(setkacrafta[j]) < 1 then
- doWork = false
- break
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement