Delay between breaking blocks
This commit is contained in:
@@ -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<BlockRegistry>("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;
|
||||
|
||||
Reference in New Issue
Block a user