Better block models !
This commit is contained in:
@@ -23,6 +23,7 @@ import type { WorldgenSetup } from "$/common/generation.ts";
|
||||
import { MAX_VIEW_DISTANCE, MIN_VIEW_DISTANCE } from "$/common/chunk_streaming.ts";
|
||||
import { CYCLE_TICKS, format_clock, time_of_day, TIMES_OF_DAY } from "$/common/time.ts";
|
||||
import {
|
||||
block_value,
|
||||
box_overlaps_block,
|
||||
can_place,
|
||||
can_stand_on,
|
||||
@@ -31,6 +32,7 @@ import {
|
||||
placement_target,
|
||||
set_state_value,
|
||||
} from "$/common/utils.ts";
|
||||
import { type Shape, shape_at } from "$/common/block_shapes.ts";
|
||||
import { EXHAUSTION } from "./vitals.ts";
|
||||
import { ModRuntime, run_guarded, type ServerCommandSource } from "./mod_runtime.ts";
|
||||
import {
|
||||
@@ -1007,10 +1009,10 @@ export class GameServer {
|
||||
return;
|
||||
}
|
||||
// solid blocks can't go where a mob or player is, the one placing it included, like minecraft
|
||||
if (
|
||||
EverythingRegistry.get<BlockRegistry>("blocks", held.block_id)?.has_collision &&
|
||||
this.#occupied(tx, ty, tz)
|
||||
) {
|
||||
const state = placed_state(held.block_id, player);
|
||||
const placing = EverythingRegistry.get<BlockRegistry>("blocks", held.block_id);
|
||||
const value = state === undefined ? default_block_value(0, placing) : block_value(0, state);
|
||||
if (placing?.has_collision && this.#occupied(tx, ty, tz, shape_at(placing, value))) {
|
||||
this.#correct(player, tx, ty, tz);
|
||||
return;
|
||||
}
|
||||
@@ -1028,22 +1030,23 @@ export class GameServer {
|
||||
return;
|
||||
}
|
||||
|
||||
this.set_block(tx, ty, tz, held.block_id, player, placed_state(held.block_id, player));
|
||||
this.set_block(tx, ty, tz, held.block_id, player, state);
|
||||
held_slot.amount = held_slot.amount! - 1;
|
||||
this.mods.after.block_place.emit(place);
|
||||
}
|
||||
|
||||
// whether a mob's or player's collision box overlaps the block at x, y, z
|
||||
#occupied(x: number, y: number, z: number) {
|
||||
// whether a mob's or player's collision box overlaps a block with that shape at x, y, z
|
||||
#occupied(x: number, y: number, z: number, shape: Shape) {
|
||||
return this.players().some((player) =>
|
||||
box_overlaps_block(
|
||||
{ x: player.x, y: player.y, z: player.z, width: PLAYER_WIDTH, height: player.height },
|
||||
x,
|
||||
y,
|
||||
z,
|
||||
shape,
|
||||
)
|
||||
) || this.entities.entities_near(x + 0.5, y, z + 0.5, 3).some((entity) =>
|
||||
entity instanceof Mob && box_overlaps_block(entity, x, y, z)
|
||||
entity instanceof Mob && box_overlaps_block(entity, x, y, z, shape)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user