This commit is contained in:
2026-10-02 11:07:09 -03:00
parent d5015edfa1
commit 9ca717d2d0
18 changed files with 449 additions and 38 deletions
+14 -9
View File
@@ -4,8 +4,6 @@ import {
FACE_OFFSETS,
Faces,
faces,
PLAYER_EYE_HEIGHT,
PLAYER_HEIGHT,
PLAYER_WIDTH,
TICK_DELTA,
TICKS_PER_SECOND,
@@ -437,7 +435,7 @@ export class GameServer {
throw_item(player: ServerPlayer, stack: ItemStack) {
const entity = this.spawn_item(
player.x,
player.y + PLAYER_EYE_HEIGHT - 0.3,
player.y + player.eye_height - 0.3,
player.z,
stack,
PLAYER_DROP_PICKUP_DELAY,
@@ -480,7 +478,7 @@ export class GameServer {
player.teleport_id += 1;
this.#send(player, { type: "teleport", id: player.teleport_id, x, y, z, ...(motion && { motion }) });
this.#update_view(player);
this.#broadcast({ type: "player_move", id: player.id, x, y, z, yaw: player.yaw, pitch: player.pitch }, player);
this.#broadcast(player_move(player), player);
}
set_time(time: number) {
@@ -758,7 +756,8 @@ export class GameServer {
}
this.#on_move(player, x, y, z);
Object.assign(player, { x, y, z, yaw, pitch });
this.#broadcast({ type: "player_move", id: player.id, x, y, z, yaw, pitch }, player);
player.set_swimming(message.swimming === true);
this.#broadcast(player_move(player), player);
this.#update_view(player);
break;
}
@@ -1009,7 +1008,7 @@ export class GameServer {
#occupied(x: number, y: number, z: number) {
return this.players().some((player) =>
box_overlaps_block(
{ x: player.x, y: player.y, z: player.z, width: PLAYER_WIDTH, height: PLAYER_HEIGHT },
{ x: player.x, y: player.y, z: player.z, width: PLAYER_WIDTH, height: player.height },
x,
y,
z,
@@ -1493,7 +1492,7 @@ export class GameServer {
const reach_xz = PLAYER_WIDTH / 2 + PICKUP_REACH_XZ + ITEM_SIZE / 2;
return Math.abs(player.x - entity.x) <= reach_xz && Math.abs(player.z - entity.z) <= reach_xz &&
entity.y + ITEM_SIZE >= player.y - PICKUP_REACH_Y &&
entity.y <= player.y + PLAYER_HEIGHT + PICKUP_REACH_Y;
entity.y <= player.y + player.height + PICKUP_REACH_Y;
}
// as much as fits, the rest stays on the ground
@@ -1629,14 +1628,14 @@ export class GameServer {
#in_reach(player: ServerPlayer, x: number, y: number, z: number) {
const dx = x + 0.5 - player.x;
const dy = y + 0.5 - (player.y + PLAYER_EYE_HEIGHT);
const dy = y + 0.5 - (player.y + player.eye_height);
const dz = z + 0.5 - player.z;
return dx * dx + dy * dy + dz * dz <= MAX_REACH * MAX_REACH;
}
// from the eyes to the closest point of its box
#entity_in_reach(player: ServerPlayer, entity: LivingEntity) {
const eye_y = player.y + PLAYER_EYE_HEIGHT;
const eye_y = player.y + player.eye_height;
const half = entity.width / 2;
const dx = Math.max(entity.x - half - player.x, 0, player.x - entity.x - half);
const dy = Math.max(entity.y - eye_y, 0, eye_y - entity.y - entity.height);
@@ -1779,3 +1778,9 @@ function placed_state(block_id: string, player: ServerPlayer): number | undefine
const facing = ((quarter % 4) + 4) % 4;
return set_state_value(default_block_value(0, info), info, "facing", facing)! >>> 16;
}
// where a player is now, for everyone else
function player_move(player: ServerPlayer): ServerMessage {
const { id, x, y, z, yaw, pitch } = player;
return { type: "player_move", id, x, y, z, yaw, pitch, ...(player.swimming && { swimming: true }) };
}