Proper directional blocks
This commit is contained in:
@@ -26,7 +26,14 @@ import type { ModListing, RecipeBook } from "$/common/mod_loader.ts";
|
||||
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 { can_place, can_stand_on, display_name, placement_target } from "$/common/utils.ts";
|
||||
import {
|
||||
can_place,
|
||||
can_stand_on,
|
||||
default_block_value,
|
||||
display_name,
|
||||
placement_target,
|
||||
set_state_value,
|
||||
} from "$/common/utils.ts";
|
||||
import { EXHAUSTION, MAX_HEALTH } from "./vitals.ts";
|
||||
import { ModRuntime, run_guarded, type ServerCommandSource } from "./mod_runtime.ts";
|
||||
import {
|
||||
@@ -879,7 +886,7 @@ export class GameServer {
|
||||
return;
|
||||
}
|
||||
|
||||
this.set_block(tx, ty, tz, held.block_id, player);
|
||||
this.set_block(tx, ty, tz, held.block_id, player, placed_state(held.block_id, player));
|
||||
held_slot.amount = held_slot.amount! - 1;
|
||||
this.mods.after.block_place.emit(place);
|
||||
}
|
||||
@@ -1602,3 +1609,15 @@ function death_message(name: string, cause: string) {
|
||||
return `${name} died`;
|
||||
}
|
||||
}
|
||||
|
||||
// the states a block is placed with: its defaults, and a "facing" state turned towards whoever placed it, like
|
||||
// minecraft's getStateForPlacement with getHorizontalDirection().getOpposite(). facing is 0 north, 1 east, 2 south,
|
||||
// 3 west, and variants turn the model with it (its north side is the front, like engine:cube's). they look along
|
||||
// (-sin yaw, -cos yaw), so the way back to them is (sin yaw, cos yaw)
|
||||
function placed_state(block_id: string, player: ServerPlayer): number | undefined {
|
||||
const info = EverythingRegistry.get<BlockRegistry>("blocks", block_id);
|
||||
if (!info?.states?.some((state) => state.name === "facing" && state.bits >= 2)) return undefined;
|
||||
const quarter = Math.round((Math.PI - player.yaw) / (Math.PI / 2));
|
||||
const facing = ((quarter % 4) + 4) % 4;
|
||||
return set_state_value(default_block_value(0, info), info, "facing", facing)! >>> 16;
|
||||
}
|
||||
|
||||
@@ -763,9 +763,6 @@ function player_api(game: GameServer, player: ServerPlayer): Player {
|
||||
get position() {
|
||||
return { x: player.x, y: player.y, z: player.z };
|
||||
},
|
||||
get yaw() {
|
||||
return player.yaw;
|
||||
},
|
||||
inventory,
|
||||
get selected_slot() {
|
||||
return player.selected_slot;
|
||||
|
||||
Reference in New Issue
Block a user