Bad breaking blocks code (unfinished i need to work on something first

This commit is contained in:
2026-03-27 20:10:24 -03:00
parent d17d5185d6
commit 43b00b556e
21 changed files with 86 additions and 10 deletions
+19 -4
View File
@@ -17,7 +17,7 @@ export class PlayerControlsSystem extends System {
super();
}
update(world: ClientWorld, _delta: number): void {
update(world: ClientWorld, delta: number): void {
const [player] = world.get_tag("player")!;
const velocity = player.get(Velocity)!;
const controls = player.get(PlayerControls)!;
@@ -110,13 +110,28 @@ export class PlayerControlsSystem extends System {
InputManager.set_mouse_grabbed(player_component.screens.length === 0);
if (InputManager.is_mouse_down(0) && player_component.screens.length === 0) {
player_component.breaking_block = true;
} else {
player_component.breaking_block = false;
player_component.break_progress_max = 0;
player_component.break_progress = 0;
}
const block = world.dimension.get_looked_block(world.dimension, camera);
if (block && player_component.screens.length === 0) {
if (InputManager.is_mouse_pressed(0)) {
world.dimension.break_block(block.x, block.y, block.z);
const block_info = EverythingRegistry.get_by_id<BlockRegistry>("blocks", block.block)!;
if (player_component.breaking_block) {
player_component.break_progress_max = block_info.toughness ?? 9999;
player_component.break_progress += delta;
if (player_component.break_progress >= player_component.break_progress_max) {
world.dimension.break_block(block.x, block.y, block.z);
player_component.break_progress_max = 0;
player_component.break_progress = 0;
}
} else if (InputManager.is_mouse_pressed(2)) {
// interact if possible
const block_info = EverythingRegistry.get_by_id<BlockRegistry>("blocks", block.block);
const interacted = block_info?.on_interact?.(world.dimension, {
x: block.x,
y: block.y,
+2 -1
View File
@@ -2,7 +2,8 @@ import { SLOT_SIZE } from "$/common/constants.ts";
import { AssetManager } from "$/client/assets.ts";
import { PlayerInventory } from "../../inventory.ts";
import { draw_item, draw_nine_slice } from "./render_utils.ts";
import { canvas, draw_rect_stroke, Texture } from "$/client/renderer/mod.ts";
import { canvas, draw_rect_stroke, push_back_face, Texture } from "$/client/renderer/mod.ts";
import { PlayerComponent } from "../../player.ts";
const PADDING = 10;