Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- vos.loadApi('ui.api')
- local alveary = Peripheral.wrap("alveary_0")
- Peripheral.wrap("wireless_modem")
- Relay.find()
- local queenCount = 0
- local beeResources = Util.readTable('.beeResources')
- if not beeResources then
- error('could not read .beeResources')
- end
- function insertQueen(res)
- -- check if we are currently producing something
- for _,v in pairs(beeResources) do
- if turtle.getItemCount(v.slot) == 0 or
- turtle.getItemCount(v.slot + 1) == 0 then
- return
- end
- end
- sleep(10)
- Logger.debug("inserting %s from slot %d:", res.bee, res.slot)
- turtle.select(res.slot)
- turtle.drop(1)
- --alveary.pullItem("west", slot, 1)
- turtle.select(res.slot+1)
- turtle.drop(1)
- --alveary.pullItem("west", slot+1, 1)
- end
- Message.addHandler('resourceCounts', function(h, id, msg)
- local resources = msg.contents
- for _, res in pairs(resources) do
- for _,beeResource in pairs(beeResources) do
- if res.name == beeResource.name then
- beeResource.qty = res.qty
- break
- end
- end
- end
- local producing
- local status
- for _, res in ipairs(beeResources) do
- if turtle.getItemCount(res.slot) == 0 then
- status = "Producing " .. res.name .. " " .. res.qty .. " of " .. res.level
- producing = true
- break
- end
- end
- if not producing then
- for key, res in ipairs(beeResources) do
- if res.qty < res.level then
- status = "Producing " .. res.name .. " " .. res.qty .. " of " .. res.level
- insertQueen(res)
- Logger.debug(status)
- producing = true
- break
- end
- end
- end
- if status then
- Logger.debug(status)
- Relay.send('panelUpdate', {
- uid = 'bees',
- type = 'message',
- message = status,
- })
- end
- Relay.send('panelUpdate', {
- uid = 'alveary',
- type = 'radio',
- text = 'Alveary 1',
- active = producing
- })
- end)
- Event.addHandler('heartbeat', function()
- Relay.send('getResourceCounts', beeResources)
- end)
- os.queueEvent('heartbeat')
- Event.heartbeat(60)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement