Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local f, err = loadfile('apis.lua')
- if not f then
- error(err)
- end
- setfenv(f, getfenv(1))
- f()
- local alveary = Peripheral.wrap({ side = 'top' })
- Logger.filter('event')
- Peripheral.wrap("wireless_modem")
- --Message.enableWirelessLogging()
- Relay.find()
- local status
- local queenCount = 0
- local beeResources = {
- { name = "Ender Pearl",
- bee = 'Enderman',
- level = 128,
- qty = 128,
- slot = 1 },
- { name = "Bone",
- bee = 'Skeleton',
- level = 256,
- qty = 256,
- slot = 2 },
- { name = "Blaze Rod",
- bee = 'Blaze',
- level = 128,
- qty = 128,
- slot = 3 },
- { name = 'Slimeball',
- bee = 'Slime',
- level = 256,
- qty = 256,
- slot = 4 },
- { name = 'Cooked Chicken',
- bee = 'Chicken',
- level = 128,
- qty = 128,
- slot = 5 },
- { name = 'Ghast Tear',
- bee = 'Ghast',
- level = 32,
- qty = 32,
- slot = 6 },
- }
- function insertQueen(res)
- -- check if we are currently producing something
- for _,v in pairs(beeResources) do
- if turtle.getItemCount(v.slot) == 0 then
- return
- end
- end
- Logger.debug("inserting %s from slot %d:", res.bee, res.slot)
- turtle.select(res.slot)
- turtle.dropUp(1)
- --alveary.pullItem("west", slot+1, 1)
- end
- --Event.addHandler('heartbeat', function()
- function heartbeat()
- while true do
- updateStatus()
- Relay.send('getResourceCounts', beeResources)
- os.sleep(15)
- end
- end
- Message.addHandler('resourceCounts', function(h, id, msg)
- local resources = msg.contents
- print('got counts')
- 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 = false
- status = nil
- for _, res in ipairs(beeResources) do
- if turtle.getItemCount(res.slot) == 0 then
- if res.qty >= res.level then
- turtle.select(res.slot)
- turtle.suckUp()
- Logger.debug('removing ' .. res.name)
- status = ''
- else
- status = "Producing " .. res.name .. " " .. res.qty .. " of " .. res.level
- producing = true
- end
- 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
- Relay.send('panelUpdate', {
- uid = 'grinder',
- text = 'Grinder',
- type = 'radio',
- active = producing,
- })
- local tankInfo = alveary.getTankInfo('unknown')[1]
- tankInfo.amount = tankInfo.amount or 0
- local enable = tankInfo.amount >= tankInfo.capacity
- rs.setOutput('left', enable)
- print('setting rs to ' .. tostring(enable))
- end)
- function updateStatus()
- if status then
- Logger.debug(status)
- Relay.send("status", status)
- Relay.send('panelUpdate', {
- uid = 'grinder',
- type = 'message',
- message = status,
- })
- end
- end
- parallel.waitForAny(Event.pullEvents, heartbeat)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement