From 1b06fa29e103756a88ae95d723df929b29747019 Mon Sep 17 00:00:00 2001 From: Paula Date: Tue, 17 Nov 2026 08:09:15 -0300 Subject: [PATCH] Delay between breaking blocks --- client/game_mode.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/client/game_mode.ts b/client/game_mode.ts index b7163d8..65e10a5 100644 --- a/client/game_mode.ts +++ b/client/game_mode.ts @@ -15,6 +15,8 @@ import { RemoteEntity } from "./entity/remote_entity.ts"; import { Player } from "./entity/player.ts"; import type { Entity } from "./entity/entity.ts"; +const CREATIVE_DESTROY_DELAY = 2; + // breaking and using blocks against a server, like minecraft's MultiPlayerGameMode. the client times breaking // and guesses the results so they feel instant, the server decides what really happens export class MultiPlayerGameMode { @@ -24,6 +26,9 @@ export class MultiPlayerGameMode { destroy_pos: { x: number; y: number; z: number } | undefined; destroy_progress = 0; destroy_time = 0; + // ticks left before creative can break another block while the button is held, so holding it doesn't clear a + // line of blocks every tick + destroy_delay = 0; constructor(client: Client) { this.client = client; @@ -36,6 +41,10 @@ export class MultiPlayerGameMode { // called every tick the attack button is held on a block continue_destroy_block(hit: BlockHitResult) { + if (this.destroy_delay > 0) { + this.destroy_delay--; + return; + } const block_info = EverythingRegistry.get_by_id("blocks", hit.block)!; const tool = this.held_item()?.tool; @@ -58,10 +67,13 @@ export class MultiPlayerGameMode { }); this.destroy_progress = 0; this.destroy_time = 0; + if (this.client.player.creative) this.destroy_delay = CREATIVE_DESTROY_DELAY; } } + // letting go also ends the delay, so clicking again breaks right away stop_destroy_block() { + this.destroy_delay = 0; this.destroy_pos = undefined; this.destroy_progress = 0; this.destroy_time = 0;