Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- автоматизация фарма дерева
- -- конфигурация запуска: робот смотрит в точку гед саженец, робот должен иметь сундук сверху
- -- для складывания надамаженного инструмента, снизу сундук где будет починеный инструмент
- -- при запуске инструмент должен быть в инвентаре робота
- --
- local r = require("robot")
- local component = require("component")
- local sides = require("sides")
- local inv = component.inventory_controller
- local toolLabel = "Hoe of Growth" -- название инструмента
- local repairWaitingSleepTime = 4 -- время ожидания повторной проверки починки инструмента (в сек.)
- local durThreshold = 0.05 -- процент инструмента для начала починки
- local rInvSize = r.inventorySize()
- function criticalError(str)
- print("ERROR: "..str)
- os.exit()
- end
- function findHoe()
- local a
- local found = false
- print("finding hoe...")
- if not found and not r.durability() then
- for i = 1,rInvSize do
- a = inv.getStackInInternalSlot(i)
- if a and a.label == toolLabel then
- found = true
- r.select(i)
- break
- end
- end
- end
- if not found then
- r.select(1)
- inv.equip()
- a = inv.getStackInInternalSlot(1)
- if a and a.label == toolLabel then
- found = true
- end
- end
- if not found then
- criticalError("cannot find "..toolLabel)
- end
- r.transferTo(1)
- r.select(1)
- inv.equip()
- end
- function init()
- findHoe()
- if not inv.getInventoryName(sides.bottom) then
- criticalError("cannot find bottom inventory for repaired "..toolLabel)
- end
- if not inv.getInventoryName(sides.top) then
- criticalError("cannot find top inventory for damaged "..toolLabel)
- end
- end
- function isDamaged()
- return r.durability() <= durThreshold
- end
- function placeForRepair()
- inv.equip()
- print("placing "..toolLabel.." for repair")
- if not inv.dropIntoSlot(sides.top,1) then
- criticalError("cannot place "..toolLabel.." into top inventory")
- end
- end
- function waitForRepair()
- local a = nil
- while not a do
- print("waiting for "..toolLabel.." repairing")
- os.sleep(repairWaitingSleepTime)
- a = inv.getStackInSlot(sides.bottom,1)
- end
- if a.label ~= toolLabel then
- criticalError("wrong item in bottom chest")
- end
- if not inv.suckFromSlot(sides.bottom,1) then
- criticalError("cannot suck "..toolLabel.." from bottom inventory")
- end
- inv.equip()
- end
- -- main
- init()
- while true do
- local flag,block = r.detect()
- if block == "solid" then
- print("block is solid")
- os.sleep(0.5)
- else
- print("using "..toolLabel)
- r.use()
- if isDamaged() then
- placeForRepair()
- os.sleep(1)
- waitForRepair()
- end
- os.sleep(0.01)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement