Fly command

This commit is contained in:
2026-10-02 18:45:08 -03:00
parent 043c526c9c
commit a4fec0681f
7 changed files with 69 additions and 6 deletions
+16
View File
@@ -1283,6 +1283,16 @@ export class GameServer {
),
);
// TODO: only let operators do this
register(
literal<ServerCommandSource>("fly").describe("Toggles flying").executes((context) => {
const player = context.source.server_player;
player.flying = !player.flying;
player.fall_distance = 0;
context.source.send_message(player.flying ? "You can fly" : "You can't fly anymore");
}),
);
register(
literal<ServerCommandSource>("tps").describe("Shows how the game loop keeps up").executes((context) => {
if (!this.loop) {
@@ -1497,6 +1507,10 @@ export class GameServer {
player.fall_distance = 0;
return;
}
if (player.flying) {
player.fall_distance = 0;
return;
}
const vitals = player.vitals;
const in_liquid = this.#in_liquid(x, y, z);
@@ -1649,6 +1663,8 @@ export class GameServer {
);
const attack_speed = player.attribute(ATTRIBUTES.attack_speed);
sync("attack_speed", attack_speed, () => ({ type: "attack_speed", value: attack_speed }));
const flying = player.flying;
sync("flying", flying, () => ({ type: "flying", flying }));
const effects = [...player.effects.values()]
.filter((effect) => effect.show_icon)
.map(({ type, amplifier, duration }) => ({ id: type.id, amplifier, duration }));
+6
View File
@@ -33,6 +33,8 @@ export interface SavedPlayer {
// base64 png, see /skin
skin?: string;
slim?: boolean;
// see /fly
flying?: boolean;
}
// the most ticks the server moves a knocked back player, in case they never land, like in water
@@ -53,6 +55,8 @@ export class ServerPlayer extends LivingEntity {
override eye_height = PLAYER_EYE_HEIGHT;
// lying flat in the short box, as their client says. their client decides, like where they are
swimming = false;
// flying, from /fly. their client moves them without gravity, and they don't fall or get hungry from moving
flying = false;
inventory = new Container(INVENTORY_SIZE);
// hunger and saturation, health is the entity's
@@ -225,6 +229,7 @@ export class ServerPlayer extends LivingEntity {
vitals: { health: this.health, ...this.vitals.save() },
skin: this.skin,
slim: this.slim || undefined,
flying: this.flying || undefined,
};
}
@@ -240,5 +245,6 @@ export class ServerPlayer extends LivingEntity {
this.load_health(saved.vitals?.health ?? this.max_health);
this.skin = saved.skin;
this.slim = saved.slim ?? false;
this.flying = saved.flying === true;
}
}