Skip to content

Commit f4bd38f

Browse files
committed
use more reliable bot entity instead of player.entity
1 parent 5adbce3 commit f4bd38f

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

Diff for: src/mineflayer/playerState.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ export class PlayerStateManager implements IPlayerState {
7777

7878
// #region Movement and Physics State
7979
private updateState () {
80-
if (!bot.player?.entity || this.disableStateUpdates) return
80+
if (!bot?.entity || this.disableStateUpdates) return
8181

82-
const { velocity } = bot.player.entity
82+
const { velocity } = bot.entity
8383
const isOnGround = bot.entity.onGround
8484
const VELOCITY_THRESHOLD = 0.01
8585
const SPRINTING_VELOCITY = 0.15
@@ -138,7 +138,7 @@ export class PlayerStateManager implements IPlayerState {
138138
}
139139

140140
getPosition (): Vec3 {
141-
return bot.player?.entity.position ?? new Vec3(0, 0, 0)
141+
return bot.entity?.position ?? new Vec3(0, 0, 0)
142142
}
143143
// #endregion
144144

Diff for: src/sounds/botSoundSystem.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@ subscribeKey(miscUiState, 'gameLoaded', async () => {
132132

133133
let lastStepSound = 0
134134
const movementHappening = async () => {
135-
if (!bot.player || !soundMap) return // no info yet
135+
if (!bot.entity || !soundMap) return // no info yet
136136
const VELOCITY_THRESHOLD = 0.1
137-
const { x, z, y } = bot.player.entity.velocity
137+
const { x, z, y } = bot.entity.velocity
138138
if (bot.entity.onGround && Math.abs(x) < VELOCITY_THRESHOLD && (Math.abs(z) > VELOCITY_THRESHOLD || Math.abs(y) > VELOCITY_THRESHOLD)) {
139139
// movement happening
140140
if (Date.now() - lastStepSound > 300) {

0 commit comments

Comments
 (0)