69 lines
1.6 KiB
TypeScript
69 lines
1.6 KiB
TypeScript
import { Client } from 'minecraft-protocol'
|
|
import Module from './Module'
|
|
|
|
export default class Life extends Module {
|
|
|
|
private _health!: number
|
|
public get health() {
|
|
return this._health
|
|
}
|
|
|
|
private _food!: number
|
|
public get food() {
|
|
return this._food
|
|
}
|
|
|
|
private _saturation!: number
|
|
public get saturation() {
|
|
return this._saturation
|
|
}
|
|
|
|
public get alive() {
|
|
return this.health > 0
|
|
}
|
|
|
|
private _experienceBar!: number
|
|
public get experienceBar() {
|
|
return this._experienceBar
|
|
}
|
|
|
|
private _level!: number
|
|
public get level() {
|
|
return this._level
|
|
}
|
|
|
|
private _totalExperience!: number
|
|
public get totalExperience() {
|
|
return this._totalExperience
|
|
}
|
|
|
|
public mount() {
|
|
this.client.on('update_health', data => {
|
|
if (this._health == null) {
|
|
setTimeout(this.respawn.bind(this), 500)
|
|
}
|
|
this._health = data.health
|
|
this._food = data.food
|
|
this._saturation = data.foodSaturation
|
|
if (this.health > 5) {
|
|
this.logger.info('health: %s', this.health)
|
|
} else {
|
|
this.logger.warn('low health: %s', this.health)
|
|
}
|
|
})
|
|
this.client.on('experience', data => {
|
|
this._experienceBar = data.experienceBar
|
|
this._level = data.level
|
|
this._totalExperience = data.totalExperience
|
|
})
|
|
}
|
|
|
|
public respawn() {
|
|
this.logger.info('respawn')
|
|
this.client.write('client_command', { action: 1 })
|
|
}
|
|
|
|
//TODO: send client settings
|
|
|
|
}
|