Make server control knockback

This commit is contained in:
2026-09-30 10:54:09 -03:00
parent 4fbcca6851
commit dc70ada7c4
8 changed files with 99 additions and 53 deletions
+3
View File
@@ -64,6 +64,8 @@ export class LocalPlayer extends Player {
// blocks per second, peaks about 1.25 blocks up with the entity's gravity and drag
jump_force = 9.23;
// the last teleport from the server, sent back with every move so the server knows which moves came after it
teleport_id = 0;
#ticks_since_sent = 0;
// counts down every tick, letting go of jump clears it
#jump_delay = 0;
@@ -207,6 +209,7 @@ export class LocalPlayer extends Player {
z: this.z,
yaw: this.yaw,
pitch: this.pitch,
teleport: this.teleport_id,
});
}
}
+14 -7
View File
@@ -221,14 +221,21 @@ export class ClientPacketListener {
}
break;
}
case "teleport":
client.player.set_position(message.x, message.y, message.z);
break;
case "set_motion":
client.player.vx = message.vx;
client.player.vy = message.vy;
client.player.vz = message.vz;
case "teleport": {
const player = client.player;
player.teleport_id = message.id;
if (message.motion) {
// moved by the server, like knockback: drawn easing there, and keeps going until the next one
player.x = message.x;
player.y = message.y;
player.z = message.z;
[player.vx, player.vy, player.vz] = message.motion;
} else {
player.set_position(message.x, message.y, message.z);
player.vx = player.vy = player.vz = 0;
}
break;
}
case "close_screen":
// closed by the server (the block broke), it already put everything back
client.screens = client.screens.filter((s) => !(s instanceof GuiContainer));