Better block models !

This commit is contained in:
2026-10-03 15:57:47 -03:00
parent ecc0295f6d
commit 24fe7cdede
23 changed files with 678 additions and 122 deletions
+6 -4
View File
@@ -4,7 +4,8 @@ import type { Client } from "./client.ts";
import type { BlockHitResult } from "./level/client_level.ts";
import type { Container } from "$/common/inventory.ts";
import { AIR_ID } from "$/common/protocol.ts";
import { box_overlaps_block, can_place, placement_target } from "$/common/utils.ts";
import { box_overlaps_block, can_place, default_block_value, placement_target } from "$/common/utils.ts";
import { shape_at } from "$/common/block_shapes.ts";
import type { EntityJson } from "$/common/mod_data.ts";
import { RemoteEntity } from "./entity/remote_entity.ts";
import { Player } from "./entity/player.ts";
@@ -77,7 +78,7 @@ export class MultiPlayerGameMode {
place_block,
current === AIR ? undefined : EverythingRegistry.get_by_id<BlockRegistry>("blocks", current),
below_id,
) && !(place_block?.has_collision && this.#occupied(target.x, target.y, target.z));
) && !(place_block?.has_collision && this.#occupied(target.x, target.y, target.z, place_block));
if (!block_info.interactive && place_id && placeable) {
level.add_block({ ...target, id: place_id });
const slot = this.#held_slot();
@@ -117,13 +118,14 @@ export class MultiPlayerGameMode {
// whether a mob's or player's collision box overlaps the block, the server doesn't let solid blocks go there. mobs
// are the mod entities that aren't scripted, players are this one and the others
#occupied(x: number, y: number, z: number) {
#occupied(x: number, y: number, z: number, block: BlockRegistry) {
const shape = shape_at(block, default_block_value(0, block));
for (const entity of this.client.level.entities.values()) {
const json = entity instanceof RemoteEntity
? EverythingRegistry.get<EntityJson>("entities", entity.type)
: undefined;
const blocks = entity instanceof Player || (json !== undefined && json.behavior !== "scripted");
if (blocks && box_overlaps_block(entity, x, y, z)) return true;
if (blocks && box_overlaps_block(entity, x, y, z, shape)) return true;
}
return false;
}