Curios slots rendering !
This commit is contained in:
@@ -163,6 +163,19 @@ export interface ToolProperties {
|
||||
durability: number;
|
||||
}
|
||||
|
||||
// how an item looks worn on a player, like bedrock's attachables: an entity model (see EntityModelJson) whose bones
|
||||
// named like the player's parts (PLAYER_PARTS) move with them, drawn with a texture from the atlas. the slim ones are
|
||||
// for players with 3 pixel wide arms, the others when not set. see docs/modding/items/index.md
|
||||
export interface WornProperties {
|
||||
model: string;
|
||||
texture: string;
|
||||
slim_model?: string;
|
||||
slim_texture?: string;
|
||||
}
|
||||
|
||||
// the parts of minecraft's player model, the bones of a worn model that move with them
|
||||
export const PLAYER_PARTS = ["head", "body", "right_arm", "left_arm", "right_leg", "left_leg"] as const;
|
||||
|
||||
// what eating an item does, like minecraft's food properties
|
||||
export interface FoodProperties {
|
||||
// hunger points it restores, a bar is 20
|
||||
@@ -187,6 +200,7 @@ export interface ItemRegistry<T = unknown | undefined> {
|
||||
max_stack?: number;
|
||||
lore?: string;
|
||||
food?: FoodProperties;
|
||||
worn?: WornProperties;
|
||||
components?: Record<string, unknown>;
|
||||
|
||||
on_create?(item: ItemStack<T>): void;
|
||||
|
||||
@@ -215,6 +215,9 @@ export interface Player {
|
||||
// what doesn't fit in the inventory drops at their feet
|
||||
give_item(id: Id, count?: number, data?: unknown): void;
|
||||
send_message(text: string): void;
|
||||
// items drawn on them, under a key so each mod keeps its own list, like "bworld:curios". replaces what that key
|
||||
// had, [] clears it. only items whose json has worn show. not saved: set it again when they join
|
||||
set_worn(key: string, items: ItemStack[]): void;
|
||||
teleport(x: number, y: number, z: number): void;
|
||||
// health and hunger, like minecraft: 20 each, saturation is never above hunger. max_health is the
|
||||
// bworld:max_health attribute
|
||||
|
||||
+24
-1
@@ -13,6 +13,7 @@ import {
|
||||
type TagJson,
|
||||
type TagRegistry,
|
||||
} from "./mod_data.ts";
|
||||
import { PLAYER_PARTS } from "./everything_registry.ts";
|
||||
import { BUILTIN_MODELS, type ModelJson } from "./block_models.ts";
|
||||
import { resolve_tags } from "./tags.ts";
|
||||
import { BIOMES } from "./worldgen/overworld.ts";
|
||||
@@ -77,6 +78,7 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
|
||||
const entity_owners = new Map<string, string[]>();
|
||||
const entity_jsons = new Map<string, EntityJson>();
|
||||
const entity_model_owners = new Map<string, string[]>();
|
||||
const entity_model_jsons = new Map<string, EntityModelJson>();
|
||||
const tag_owners = new Map<TagRegistry, Set<string>>();
|
||||
const add = (map: Map<string, string[]>, id: string, mod: string) => map.set(id, [...(map.get(id) ?? []), mod]);
|
||||
|
||||
@@ -93,7 +95,10 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
|
||||
add(entity_owners, json.id, mod.id);
|
||||
entity_jsons.set(json.id, json);
|
||||
}
|
||||
for (const { json } of mod.entity_models) add(entity_model_owners, json.id, mod.id);
|
||||
for (const { json } of mod.entity_models) {
|
||||
add(entity_model_owners, json.id, mod.id);
|
||||
entity_model_jsons.set(json.id, json);
|
||||
}
|
||||
for (const { json } of mod.tags) {
|
||||
if (!tag_owners.has(json.registry)) tag_owners.set(json.registry, new Set());
|
||||
tag_owners.get(json.registry)!.add(json.id);
|
||||
@@ -177,6 +182,24 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
|
||||
for (const texture of Object.values(json.data_textures ?? {})) uses(file, texture, "texture");
|
||||
if (json.places) uses(file, json.places, "block");
|
||||
if (json.food?.returns) uses(file, json.food.returns, "item");
|
||||
if (json.worn) {
|
||||
const { model, texture, slim_model, slim_texture } = json.worn;
|
||||
for (const id of [model, slim_model]) {
|
||||
if (id === undefined) continue;
|
||||
uses(file, id, "entity model");
|
||||
// nothing of it would move with the player
|
||||
const bones = entity_model_jsons.get(id)?.bones;
|
||||
if (bones && !bones.some((bone) => (PLAYER_PARTS as readonly string[]).includes(bone.name))) {
|
||||
warnings.push(
|
||||
`${file}: worn model ${id} has no bone named like a player part (${
|
||||
PLAYER_PARTS.join(", ")
|
||||
})`,
|
||||
);
|
||||
}
|
||||
}
|
||||
uses(file, texture, "texture");
|
||||
if (slim_texture !== undefined) uses(file, slim_texture, "texture");
|
||||
}
|
||||
}
|
||||
for (const { file, json } of mod.recipes) {
|
||||
switch (json.type) {
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
RENDER_LAYERS,
|
||||
type RenderLayer,
|
||||
type ToolProperties,
|
||||
type WornProperties,
|
||||
} from "./everything_registry.ts";
|
||||
import { type BlockVariant, MODEL_FACES, type ModelFace } from "./block_models.ts";
|
||||
import { expand_items, list_matches } from "./tags.ts";
|
||||
@@ -101,6 +102,8 @@ export interface ItemJson {
|
||||
places?: string;
|
||||
max_stack?: number;
|
||||
food?: FoodProperties;
|
||||
// how it looks worn on a player
|
||||
worn?: WornProperties;
|
||||
name?: string;
|
||||
lore?: string;
|
||||
components?: Record<string, unknown>;
|
||||
@@ -309,6 +312,7 @@ export function item_to_json(id: string, item: ItemRegistry): ItemJson {
|
||||
if (item.block_id !== undefined) json.places = item.block_id;
|
||||
if (item.max_stack !== undefined) json.max_stack = item.max_stack;
|
||||
if (item.food !== undefined) json.food = item.food;
|
||||
if (item.worn !== undefined) json.worn = item.worn;
|
||||
if (item.name !== undefined) json.name = item.name;
|
||||
if (item.lore !== undefined) json.lore = item.lore;
|
||||
if (item.components) json.components = item.components;
|
||||
@@ -322,6 +326,7 @@ export function item_from_json(json: ItemJson): ItemRegistry {
|
||||
if (json.places !== undefined) item.block_id = json.places;
|
||||
if (json.max_stack !== undefined) item.max_stack = json.max_stack;
|
||||
if (json.food !== undefined) item.food = json.food;
|
||||
if (json.worn !== undefined) item.worn = json.worn;
|
||||
if (json.name !== undefined) item.name = json.name;
|
||||
if (json.lore !== undefined) item.lore = json.lore;
|
||||
if (json.components) item.components = json.components;
|
||||
@@ -646,6 +651,22 @@ export function validate_item(json: unknown): Problems {
|
||||
if (food.returns !== undefined) problems.push(...validate_id(food.returns, "food.returns"));
|
||||
}
|
||||
}
|
||||
if (json.worn !== undefined) {
|
||||
const worn = json.worn;
|
||||
if (!is_object(worn)) {
|
||||
problems.push("worn must be { model, texture }, an entity model and a texture");
|
||||
} else {
|
||||
problems.push(...validate_id(worn.model, "worn.model"), ...validate_id(worn.texture, "worn.texture"));
|
||||
for (const field of ["slim_model", "slim_texture"]) {
|
||||
if (worn[field] !== undefined) problems.push(...validate_id(worn[field], `worn.${field}`));
|
||||
}
|
||||
for (const field of Object.keys(worn)) {
|
||||
if (!["model", "texture", "slim_model", "slim_texture"].includes(field)) {
|
||||
problems.push(`worn.${field} isn't a field of worn`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return problems;
|
||||
}
|
||||
|
||||
|
||||
+6
-1
@@ -7,7 +7,7 @@ export const AIR_ID = "bworld:air";
|
||||
|
||||
// bump when a client and server of different versions can't play together.
|
||||
// the server rejects a different version before the client downloads anything
|
||||
export const PROTOCOL_VERSION = 16;
|
||||
export const PROTOCOL_VERSION = 17;
|
||||
|
||||
export interface PlayerInfo {
|
||||
id: string;
|
||||
@@ -21,6 +21,8 @@ export interface PlayerInfo {
|
||||
skin?: string;
|
||||
// the skin is for the model with 3 pixel wide arms
|
||||
slim?: boolean;
|
||||
// what they're wearing that shows, see player_worn
|
||||
worn?: ItemData[];
|
||||
}
|
||||
|
||||
// an entity that isn't a player, as the server first sends it. players have their own messages. items on the
|
||||
@@ -156,6 +158,9 @@ export type ServerMessage =
|
||||
| { type: "player_move"; id: string; x: number; y: number; z: number; yaw: number; pitch: number }
|
||||
// a player changed their skin, including the one receiving it. without skin it's back to the default
|
||||
| { type: "player_skin"; id: string; skin?: string; slim?: boolean }
|
||||
// what a player wears that shows changed, to everyone including them: the items whose json has worn, see
|
||||
// ctx's player.set_worn. also sent to a player right after join, for what they wear themselves
|
||||
| { type: "player_worn"; id: string; worn: ItemData[] }
|
||||
| { type: "add_entity"; entity: EntityInfo }
|
||||
| {
|
||||
type: "move_entity";
|
||||
|
||||
Reference in New Issue
Block a user