fix positions
This commit is contained in:
parent
a4e605852c
commit
a8ce3ecba3
3 changed files with 19 additions and 7 deletions
7
bot.js
7
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);
|
||||
|
|
19
plugins/position.js
Normal file
19
plugins/position.js
Normal 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
BIN
test.nbt
Binary file not shown.
Loading…
Reference in a new issue