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
+7 -4
View File
@@ -7,12 +7,15 @@ interface TileChestData {
inventory: Inventory;
}
EverythingRegistry.register<BlockRegistry<TileChestData>>("blocks", "bworld:chest", {
EverythingRegistry.register<BlockRegistry>("blocks", "bworld:chest", {
id: "bworld:chest",
textures: "bworld:chest",
has_collision: false,
toughness: 10,
requires_tool: false,
tool_to_break: "axe",
on_interact(dimension, tile) {
has_collision: false,
/*on_interact(dimension, tile) {
const [player] = dimension.world.get_tag("player")!;
const player_component = player.get(PlayerComponent)!;
if (tile.data && tile.data.inventory) {
@@ -21,5 +24,5 @@ EverythingRegistry.register<BlockRegistry<TileChestData>>("blocks", "bworld:ches
},
on_create(_, tile) {
tile.data = { inventory: new Inventory(new Container(9 * 3)) };
},
},*/
});
+3
View File
@@ -6,6 +6,9 @@ const block = EverythingRegistry.register<BlockRegistry>("blocks", "bworld:coal_
textures: "bworld:stone_coal",
has_collision: true,
drop_table: "bworld:coal_ore",
toughness: 5,
requires_tool: true,
tool_to_break: "pickaxe",
});
register_block_item(block);
+3
View File
@@ -6,6 +6,9 @@ const block = EverythingRegistry.register<BlockRegistry>("blocks", "bworld:coppe
textures: "bworld:stone_copper",
has_collision: true,
drop_table: "bworld:copper_ore",
toughness: 5,
requires_tool: true,
tool_to_break: "pickaxe",
});
register_block_item(block);
+5
View File
@@ -7,6 +7,9 @@ const block = EverythingRegistry.register<BlockRegistry>("blocks", "bworld:dirt"
textures: "bworld:dirt",
has_collision: false,
drop_table: "bworld:dirt",
toughness: 2,
requires_tool: false,
tool_to_break: "shovel",
on_interact(dimension, block) {
const [player] = dimension.world.get_tag("player")!;
@@ -14,7 +17,9 @@ const block = EverythingRegistry.register<BlockRegistry>("blocks", "bworld:dirt"
const maybe_item = player_inventory.container.get_item(player_inventory.hotbar_selected);
if (maybe_item && maybe_item.type_id === "bworld:hoe") {
dimension.add_block({ x: block.x, y: block.y, z: block.z, id: "bworld:hoed_dirt" });
return true;
}
return false;
},
});
+3
View File
@@ -123,6 +123,9 @@ const block = EverythingRegistry.register<BlockRegistry>("blocks", "bworld:furna
textures: { front: "bworld:furnace", side: "bworld:stone" },
has_collision: true,
drop_table: "bworld:furnace",
toughness: 5,
requires_tool: true,
tool_to_break: "pickaxe",
on_interact(dimension, block) {
const [player] = dimension.world.get_tag("player")!;
+3
View File
@@ -6,6 +6,9 @@ const block = EverythingRegistry.register<BlockRegistry>("blocks", "bworld:glass
textures: "bworld:glass",
has_collision: true,
transparent: true,
toughness: 3,
requires_tool: false,
tool_to_break: "pickaxe",
});
register_block_item(block);
+3
View File
@@ -6,6 +6,9 @@ const block = EverythingRegistry.register<BlockRegistry>("blocks", "bworld:gold_
textures: "bworld:stone_gold",
has_collision: true,
drop_table: "bworld:gold_ore",
toughness: 5,
requires_tool: true,
tool_to_break: "pickaxe",
});
register_block_item(block);
+3
View File
@@ -6,6 +6,9 @@ EverythingRegistry.register<BlockRegistry>("blocks", "bworld:grass", {
textures: { top: "bworld:grass_top", bottom: "bworld:dirt", "side": "bworld:grass_side" },
has_collision: false,
drop_table: "bworld:dirt",
toughness: 2,
requires_tool: false,
tool_to_break: "shovel",
on_interact(dimension, block) {
const [player] = dimension.world.get_tag("player")!;
+3
View File
@@ -7,6 +7,9 @@ const block = EverythingRegistry.register<BlockRegistry>("blocks", "bworld:hoed_
textures: { side: "bworld:dirt", top: "bworld:hoed_dirt", bottom: "bworld:dirt" },
has_collision: false,
drop_table: "bworld:dirt",
toughness: 5,
requires_tool: false,
tool_to_break: "shovel",
});
register_block_item(block);
+3
View File
@@ -6,6 +6,9 @@ const block = EverythingRegistry.register<BlockRegistry>("blocks", "bworld:iron_
textures: "bworld:stone_iron",
has_collision: true,
drop_table: "bworld:iron_ore",
toughness: 5,
requires_tool: true,
tool_to_break: "pickaxe",
});
register_block_item(block);
+3
View File
@@ -6,6 +6,9 @@ const block = EverythingRegistry.register<BlockRegistry>("blocks", "bworld:leave
textures: "bworld:leaves",
has_collision: true,
transparent: true,
toughness: 3,
requires_tool: false,
tool_to_break: "hoe",
});
register_block_item(block);
+3
View File
@@ -6,6 +6,9 @@ const block = EverythingRegistry.register<BlockRegistry>("blocks", "bworld:log",
textures: { side: "bworld:log_side", top: "bworld:log_top", bottom: "bworld:log_top" },
has_collision: true,
drop_table: "bworld:log",
toughness: 3,
requires_tool: false,
tool_to_break: "axe",
});
register_block_item(block);
+3
View File
@@ -6,6 +6,9 @@ const block = EverythingRegistry.register<BlockRegistry>("blocks", "bworld:plank
textures: "bworld:planks",
has_collision: true,
drop_table: "bworld:log",
toughness: 3,
requires_tool: false,
tool_to_break: "axe",
});
register_block_item(block);
+4 -1
View File
@@ -1,11 +1,14 @@
import { BlockRegistry, EverythingRegistry } from "$/common/everything_registry.ts";
import { register_block_item } from "../../common/utils.ts";
import { register_block_item } from "$/common/utils.ts";
const block = EverythingRegistry.register<BlockRegistry>("blocks", "bworld:sand", {
id: "bworld:sand",
textures: "bworld:sand",
has_collision: true,
drop_table: "bworld:sand",
toughness: 3,
requires_tool: false,
tool_to_break: "shovel",
});
register_block_item(block);
+3
View File
@@ -5,6 +5,9 @@ const block = EverythingRegistry.register<BlockRegistry>("blocks", "bworld:snow"
id: "bworld:snow",
textures: "bworld:snow",
has_collision: true,
toughness: 2,
requires_tool: true,
tool_to_break: "shovel",
});
register_block_item(block);
+3
View File
@@ -6,6 +6,9 @@ const block = EverythingRegistry.register<BlockRegistry>("blocks", "bworld:stone
textures: "bworld:stone",
has_collision: true,
drop_table: "bworld:stone",
toughness: 3,
requires_tool: true,
tool_to_break: "pickaxe",
});
register_block_item(block);
+3
View File
@@ -6,6 +6,9 @@ const block = EverythingRegistry.register<BlockRegistry>("blocks", "bworld:tin_o
textures: "bworld:stone_tin",
has_collision: true,
drop_table: "bworld:tin_ore",
toughness: 5,
requires_tool: true,
tool_to_break: "pickaxe",
});
register_block_item(block);
+4
View File
@@ -13,6 +13,10 @@ export class PlayerComponent extends Component {
screens: GuiScreen[] = [];
render_distance = 6;
breaking_block = false;
break_progress = 0;
break_progress_max = 0;
pop_screen() {
const screen = this.screens.pop();
if (screen) {
+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;
+3
View File
@@ -69,6 +69,9 @@ export interface BlockRegistry {
alpha?: number;
has_collision: boolean;
toughness?: number;
requires_tool?: boolean;
tool_to_break?: string;
drop_table?: string;
on_create?(dimension: Dimension, block: Block): void;