Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PrismarineJS
GitHub Repository: PrismarineJS/mineflayer
Path: blob/master/lib/plugins/breath.js
1467 views
1
module.exports = inject
2
3
function inject (bot) {
4
if (bot.supportFeature('mcDataHasEntityMetadata')) {
5
// this is handled inside entities.js. We don't yet have entity metadataKeys for all versions but once we do
6
// we can delete the numerical checks here and in entities.js https://github.com/extremeheat/mineflayer/blob/eb9982aa04973b0086aac68a2847005d77f01a3d/lib/plugins/entities.js#L469
7
return
8
}
9
bot._client.on('entity_metadata', (packet) => {
10
if (!bot.entity) return
11
if (bot.entity.id !== packet.entityId) return
12
for (const metadata of packet.metadata) {
13
if (metadata.key === 1) {
14
bot.oxygenLevel = Math.round(metadata.value / 15)
15
bot.emit('breath')
16
}
17
}
18
})
19
}
20
21