From a8ce3ecba308534e30472ead97e8a67f10177201 Mon Sep 17 00:00:00 2001 From: Chipmunk <65827213+ChipmunkMC@users.noreply.github.com> Date: Mon, 3 Jun 2024 22:53:42 -0400 Subject: [PATCH] fix positions --- bot.js | 7 ------- plugins/position.js | 19 +++++++++++++++++++ test.nbt | Bin 26 -> 0 bytes 3 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 plugins/position.js delete mode 100644 test.nbt diff --git a/bot.js b/bot.js index 543b9db..e93a26c 100644 --- a/bot.js +++ b/bot.js @@ -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); diff --git a/plugins/position.js b/plugins/position.js new file mode 100644 index 0000000..fda43f3 --- /dev/null +++ b/plugins/position.js @@ -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 diff --git a/test.nbt b/test.nbt deleted file mode 100644 index f84472a2ecc1f8dc4a760966ee4b4643f8431291..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 26 hcmd;LVBlb3C`m0Y;brhh&B@8vQ7F$Z%1KdV002la25kTU