This commit is contained in:
2026-11-16 13:39:34 -03:00
parent be0770f3cf
commit 5301e0307c
8 changed files with 74 additions and 9 deletions
+19 -5
View File
@@ -1273,8 +1273,8 @@ export class GameServer {
#break_block(player: ServerPlayer, x: number, y: number, z: number) {
const info = this.world.get_block_info(x, y, z);
// air, or something like water that can't be broken
if (!info || info.toughness === undefined || !this.#in_reach(player, x, y, z)) {
// air, or something like water that can't be broken outside creative
if (!info || (info.toughness === undefined && !player.creative) || !this.#in_reach(player, x, y, z)) {
this.#correct(player, x, y, z);
return;
}
@@ -1291,7 +1291,8 @@ export class GameServer {
return;
}
this.destroy_block(x, y, z, player);
// creative breaks drop nothing, since placing doesn't use anything up
this.destroy_block(x, y, z, player, { collect: player.creative });
player.vitals.add_exhaustion(EXHAUSTION.break_block);
this.mods.after.block_break.emit(event);
}
@@ -1537,7 +1538,7 @@ export class GameServer {
if (!place) return;
this.set_block(tx, ty, tz, held.block_id, player, state);
held_slot.amount = held_slot.amount! - 1;
if (!player.creative) held_slot.amount = held_slot.amount! - 1;
this.mods.after.block_place.emit(place);
}
@@ -1559,7 +1560,7 @@ export class GameServer {
z,
set_state_value(this.world.get_block_value(x, y, z), info, "waterlogged", 1)! >>> 16,
);
held_slot.amount = held_slot.amount! - 1;
if (!player.creative) held_slot.amount = held_slot.amount! - 1;
this.mods.after.block_place.emit(place);
}
@@ -1924,6 +1925,17 @@ export class GameServer {
}),
);
// TODO: only let operators do this
register(
literal<ServerCommandSource>("creative")
.describe("Toggles placing blocks without using them up and breaking any block instantly")
.executes((context) => {
const player = context.source.server_player;
player.creative = !player.creative;
context.source.send_message(player.creative ? "You're in creative" : "You're out of creative");
}),
);
// TODO: only let operators do this
register(
literal<ServerCommandSource>("viewdistance").describe("Shows or changes the server's view distance")
@@ -2337,6 +2349,8 @@ export class GameServer {
sync("using_item", using, () => ({ type: "using_item", using }));
const flying = player.flying;
sync("flying", flying, () => ({ type: "flying", flying }));
const creative = player.creative;
sync("creative", creative, () => ({ type: "creative", creative }));
const effects = [...player.effects.values()]
.filter((effect) => effect.show_icon)
.map(({ type, amplifier, duration }) => ({ id: type.id, amplifier, duration }));
+7
View File
@@ -38,6 +38,8 @@ export interface SavedPlayer {
slim?: boolean;
// see /fly
flying?: boolean;
// see /creative
creative?: boolean;
}
// the connection of the player machines use items as, see GameServer.use_item_on. nothing is ever sent to it
@@ -68,6 +70,9 @@ export class ServerPlayer extends LivingEntity {
using: { slot: number; type_id: string; ticks: number; duration: number } | undefined;
// flying, from /fly. their client moves them without gravity, and they don't fall or get hungry from moving
flying = false;
// from /creative: placing doesn't use up what they hold, and breaking is instant and drops nothing. their client
// times breaking, so it only needs to know
creative = false;
inventory = new Container(INVENTORY_SIZE);
// hunger and saturation, health is the entity's
@@ -240,6 +245,7 @@ export class ServerPlayer extends LivingEntity {
skin: this.skin,
slim: this.slim || undefined,
flying: this.flying || undefined,
creative: this.creative || undefined,
};
}
@@ -256,5 +262,6 @@ export class ServerPlayer extends LivingEntity {
this.skin = saved.skin;
this.slim = saved.slim ?? false;
this.flying = saved.flying === true;
this.creative = saved.creative === true;
}
}