Proper directional blocks
This commit is contained in:
+16
-18
@@ -56,7 +56,8 @@ const cube_face = (texture: string, cullface: ModelFace): ModelFaceJson => ({ te
|
||||
|
||||
// the engine's own models
|
||||
export const BUILTIN_MODELS: Record<string, ModelJson> = {
|
||||
// a full block. "textures" can be one texture, { top, bottom, side } or { front, side }
|
||||
// a full block. "textures" can be one texture, { top, bottom, side } or { front, side }. the front is north, like
|
||||
// minecraft's furnace, so a facing state turns it towards whoever placed it
|
||||
"engine:cube": {
|
||||
id: "engine:cube",
|
||||
textures: { top: "#side", bottom: "#side", front: "#side" },
|
||||
@@ -66,8 +67,8 @@ export const BUILTIN_MODELS: Record<string, ModelJson> = {
|
||||
faces: {
|
||||
top: cube_face("#top", "top"),
|
||||
bottom: cube_face("#bottom", "bottom"),
|
||||
north: cube_face("#side", "north"),
|
||||
south: cube_face("#front", "south"),
|
||||
north: cube_face("#front", "north"),
|
||||
south: cube_face("#side", "south"),
|
||||
west: cube_face("#side", "west"),
|
||||
east: cube_face("#side", "east"),
|
||||
},
|
||||
@@ -141,24 +142,21 @@ export function texture_variables(reference: string, textures: BlockTextures | u
|
||||
return variables;
|
||||
}
|
||||
|
||||
// the block's model and textures for a value with state bits, from the first variant whose conditions match
|
||||
// the block's model, textures and turn for a value with state bits. each comes from the first variant whose conditions
|
||||
// match that sets it, so "lit=1" can change the textures and "facing=1" the turn of the same block
|
||||
export function block_variant(block: BlockRegistry, states?: Record<string, number>): Required<BlockVariant> {
|
||||
const variant: Required<BlockVariant> = {
|
||||
model: block.model ?? DEFAULT_MODEL,
|
||||
textures: block.textures,
|
||||
y: 0,
|
||||
};
|
||||
if (!block.variants || !states) return variant;
|
||||
for (const [condition, override] of Object.entries(block.variants)) {
|
||||
if (variant_matches(condition, states)) {
|
||||
return {
|
||||
model: override.model ?? variant.model,
|
||||
textures: override.textures ?? variant.textures,
|
||||
y: override.y ?? 0,
|
||||
};
|
||||
let model: string | undefined;
|
||||
let textures: BlockTextures | undefined;
|
||||
let y: number | undefined;
|
||||
if (block.variants && states) {
|
||||
for (const [condition, override] of Object.entries(block.variants)) {
|
||||
if (!variant_matches(condition, states)) continue;
|
||||
model ??= override.model;
|
||||
textures ??= override.textures;
|
||||
y ??= override.y;
|
||||
}
|
||||
}
|
||||
return variant;
|
||||
return { model: model ?? block.model ?? DEFAULT_MODEL, textures: textures ?? block.textures, y: y ?? 0 };
|
||||
}
|
||||
|
||||
// "age=7" or "age=7,facing=2", "" matches everything
|
||||
|
||||
@@ -207,8 +207,6 @@ export interface Player {
|
||||
readonly id: string;
|
||||
readonly name: string;
|
||||
readonly position: Readonly<Position>;
|
||||
// where they look, in radians. 0 is north (-z), going up turning west
|
||||
readonly yaw: number;
|
||||
readonly inventory: Container; // 36 slots, hotbar is 0-8
|
||||
readonly selected_slot: number;
|
||||
readonly held_item: ItemStack | undefined;
|
||||
|
||||
Reference in New Issue
Block a user