fix positions

This commit is contained in:
Chipmunk 2024-06-03 22:53:42 -04:00
parent a4e605852c
commit a8ce3ecba3
3 changed files with 19 additions and 7 deletions

7
bot.js
View file

@ -88,13 +88,6 @@ function createBot (options = {}) {
bot.emit('login')
})
// position code
bot.position = { x: null, y: null, z: null } // to prevent errors i guess
bot._client.on('position', (packet) => {
bot.position = packet
bot._client.write('teleport_confirm', { teleportId: packet.teleportId })
})
bot._client.on('packet', (data, meta) => {
bot.emit('packet', data, meta);
bot.emit('packet.' + meta.name, data);

19
plugins/position.js Normal file
View file

@ -0,0 +1,19 @@
function inject (bot) {
bot.position = { x: null, y: null, z: null, yaw: null, pitch: null } // to prevent errors i guess
bot._client.on('position', (packet) => {
const oldPos = { ...bot.position }
bot.position.x = packet.x + bot.position.x * !!(packet.flags & 1)
bot.position.y = packet.y + bot.position.y * !!(packet.flags & 2)
bot.position.z = packet.z + bot.position.z * !!(packet.flags & 4)
bot.position.yaw = packet.yaw + bot.position.yaw * !!(packet.flags & 8)
bot.position.pitch = packet.pitch + bot.position.pitch * !!(packet.flags & 16)
bot._client.write('teleport_confirm', { teleportId: packet.teleportId })
bot.emit('move', oldPos)
})
}
module.exports = inject

BIN
test.nbt

Binary file not shown.