Blocks interacting on the world api
This commit is contained in:
@@ -31,7 +31,7 @@ import {
|
||||
} from "$/client/renderer/mod.ts";
|
||||
import { type BlockRegistry, EverythingRegistry, type RenderLayer } from "$/common/everything_registry.ts";
|
||||
import { bake_block, type BakedQuad, FACE_INDEX, looks_by_state, type ModelJson } from "$/common/block_models.ts";
|
||||
import { ID_MASK } from "$/common/constants.ts";
|
||||
import { BREAK_STAGES, ID_MASK } from "$/common/constants.ts";
|
||||
import { type Shape, shape_at } from "$/common/block_shapes.ts";
|
||||
import type { BlockHitResult } from "$/client/level/client_level.ts";
|
||||
import { FACE_GROUPS, UNALIGNED_GROUP } from "$/client/workers/chunk_messages.ts";
|
||||
@@ -157,30 +157,29 @@ export class LevelRenderer {
|
||||
draw_visuals(level.visuals, level.image);
|
||||
}
|
||||
|
||||
// the cracks on the block being broken, drawn over its model's faces like minecraft's crumbling overlay, so a slab
|
||||
// or a plant cracks where it is and not on a whole cube around it
|
||||
// the cracks on the block being broken, and on the ones machines are breaking, drawn over their models' faces like
|
||||
// minecraft's crumbling overlay, so a slab or a plant cracks where it is and not on a whole cube around it
|
||||
render_destroy_progress(level: ClientLevel, game_mode: MultiPlayerGameMode) {
|
||||
for (const { x, y, z, stage } of level.break_progress.values()) this.#draw_cracks(level, x, y, z, stage);
|
||||
const block = game_mode.destroy_pos;
|
||||
if (!block) {
|
||||
return;
|
||||
}
|
||||
|
||||
const progress = Math.max(0, Math.min(1, game_mode.destroy_progress / game_mode.destroy_time));
|
||||
const stage = Math.round(progress * 8);
|
||||
if (Number.isNaN(stage)) {
|
||||
return;
|
||||
}
|
||||
const stage = Math.round(progress * BREAK_STAGES);
|
||||
if (!Number.isNaN(stage)) this.#draw_cracks(level, block.x, block.y, block.z, stage);
|
||||
}
|
||||
|
||||
const value = level.get_block_value(block.x, block.y, block.z);
|
||||
#draw_cracks(level: ClientLevel, x: number, y: number, z: number, stage: number) {
|
||||
const value = level.get_block_value(x, y, z);
|
||||
const info = EverythingRegistry.get_by_id<BlockRegistry>("blocks", value & ID_MASK);
|
||||
if (!info) {
|
||||
return;
|
||||
}
|
||||
|
||||
const tex = AssetManager.instance.get<Texture>("bworld:textures");
|
||||
const region = get_sprite_region(`engine:break_${stage}`);
|
||||
for (const quad of this.#destroy_quads(info, value)) {
|
||||
push_decal_quad(tex, quad, block.x, block.y, block.z, region);
|
||||
push_decal_quad(tex, quad, x, y, z, region);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user