18 lines
699 B
JavaScript
18 lines
699 B
JavaScript
// Keeps a protocol-only client synchronized like a stationary game client.
|
|
function addMovement(client, version) {
|
|
let timer;
|
|
const usesFlags = Number(version.split(".")[2] || 0) >= 2;
|
|
client.on("position", packet => {
|
|
if (Number.isInteger(packet.teleportId)) {
|
|
client.write("teleport_confirm", { teleportId: packet.teleportId });
|
|
}
|
|
if (!timer) {
|
|
const ground = usesFlags ? { flags: { onGround: true, hasHorizontalCollision: false } } : { onGround: true };
|
|
timer = setInterval(() => client.write("flying", ground), 150);
|
|
}
|
|
});
|
|
client.on("end", () => clearInterval(timer));
|
|
}
|
|
|
|
module.exports = { addMovement };
|