dougbot/bridge/lib/mineflayer/lib/bedrockPlugins/experience.mts
roberts 8f616598fd Fix chat, brain stability, MariaDB reconnect, suppress warnings
- Listen on raw 'text' packet for Bedrock chat (pattern-based chat event
  doesn't fire reliably on Bedrock)
- Brain: add safety reset for stuck pending_status flag
- MariaDB: add retry-on-disconnect for all query methods
- Suppress harmless punycode deprecation warning from Node.js
- Add mineflayer-bedrock lib packages (mineflayer, prismarine-chunk,
  prismarine-registry) for movement support
- Exclude minecraft-data from git (278MB, installed via npm)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 12:33:17 -05:00

23 lines
815 B
TypeScript

import type { BedrockBot } from '../../index.js';
export default function inject(bot: BedrockBot) {
bot.experience = {
level: null,
points: null,
progress: null,
};
bot.on('entityAttributes', (entity) => {
if (entity !== bot.entity) return;
if (!entity.attributes) return;
if ('minecraft:player.level' in entity.attributes) {
bot.experience.level = entity.attributes['minecraft:player.level'].value;
}
if ('minecraft:player.experience' in entity.attributes) {
let attribute = entity.attributes['minecraft:player.experience'];
bot.experience.points = attribute.value;
// something wrong here !
bot.experience.progress = ((attribute.value - attribute.default) / (attribute.max - attribute.default)) * 100;
}
bot.emit('experience');
});
}