Cog wheels

This commit is contained in:
2026-10-15 12:01:46 -03:00
parent a0596ed0ef
commit 74c315bdfc
14 changed files with 331 additions and 88 deletions
+3 -2
View File
@@ -67,13 +67,13 @@ export class BlockRules {
// the block's value with the states a player looking at yaw and pitch placing it gets: its defaults facing them
// (default_placement_value), then what its rules' state_for_placement say. states that don't exist or don't fit are
// left alone
// left alone. undefined when a rule says it can't go there
placement_value(
block: BlockRegistry,
yaw: number,
pitch: number,
where: Omit<BlockPlacement, "facing" | "looking">,
): number {
): number | undefined {
let value = default_placement_value(block, yaw);
const placement: BlockPlacement = {
...where,
@@ -87,6 +87,7 @@ export class BlockRules {
`${id} state_for_placement`,
() => rules.state_for_placement!(placement, params),
);
if (states === false) return undefined;
for (const [name, state] of Object.entries(states ?? {})) {
const known = block.states?.find((s) => s.name === name);
if (known && Number.isInteger(state) && state >= 0 && state < 2 ** known.bits) {
+3 -2
View File
@@ -125,8 +125,9 @@ export interface BlockInteraction {
// deno-lint-ignore no-explicit-any
export interface BlockRules<P = any> {
// the states it's placed with when a player places it, like minecraft's getStateForPlacement. states it doesn't
// return keep their defaults, and a 2 bit "facing" faces the player
state_for_placement?(placement: BlockPlacement, params: P): Record<string, number> | void;
// return keep their defaults, and a 2 bit "facing" faces the player. false when it can't go there, so it isn't
// placed, like getStateForPlacement returning null
state_for_placement?(placement: BlockPlacement, params: P): Record<string, number> | false | void;
// a block next to it (on any of the 6 sides) was placed, broken or changed its states, like minecraft's
// updateShape. neighbor is where, and what's there now
on_neighbor_change?(block: SharedBlock, params: P, neighbor: SharedBlock): void;