Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Spot farm, please don't ask why
- local robot_api = require("robot")
- local computer = require("computer")
- local event = require("event")
- fsm = {}
- -- flags
- inventory_used = false
- inventory_overflowed = false
- function checkInventory()
- if inventory_used then
- for i=1,16 do
- if robot_api.space(i) > 0 then
- return true
- end
- end
- return false
- end
- return nil
- end
- function checkInstrument()
- if robot_api.durability() > 0 then
- return true
- end
- return false
- end
- function configureTest()
- inv_size = robot_api.inventorySize()
- if inv_size > 0 then
- inventory_used = true
- print("inventory founded...\n")
- end
- end
- function fsm.storeItemsState()
- robot_api.turnLeft()
- for i=1,16 do
- robot_api.select(i)
- robot_api.drop()
- end
- robot_api.turnRight()
- print("store all items from inventory")
- inventory_overflowed = false
- end
- function fsm:instrumentIssueEvent()
- while not checkInstrument() do
- computer.beep()
- os.sleep(1)
- end
- end
- function killEntity()
- robot_api.swing()
- if not checkInstrument() then
- print("instrument broken")
- fsm:instrumentIssueEvent()
- end
- end
- -- function fsm.chargeState() end
- -- function checkEnergy() end
- timerID = nil
- function fsm.farmState()
- if inventory_overflowed then
- return
- end
- if checkInventory() ~= nil then
- if not checkInventory() then
- print("inventory overflowed...")
- inventory_overflowed = true
- fsm.storeItemsState()
- end
- end
- _, name = robot_api.detect()
- while name == "entity" do
- killEntity()
- end
- end
- function start()
- print("initialize...\n")
- configureTest()
- timerID = event.timer(1, fsm.farmState, math.huge)
- end
- start()
Advertisement
Add Comment
Please, Sign In to add comment