Basic entity system
This commit is contained in:
+40
-12
@@ -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 = 8;
|
||||
export const PROTOCOL_VERSION = 9;
|
||||
|
||||
export interface PlayerInfo {
|
||||
id: string;
|
||||
@@ -23,15 +23,28 @@ export interface PlayerInfo {
|
||||
slim?: boolean;
|
||||
}
|
||||
|
||||
// an entity that isn't a player, as the server first sends it. players have their own messages
|
||||
export interface EntityInfo {
|
||||
kind: "item";
|
||||
id: string;
|
||||
x: number;
|
||||
y: number;
|
||||
z: number;
|
||||
item: ItemData;
|
||||
}
|
||||
// an entity that isn't a player, as the server first sends it. players have their own messages. items on the
|
||||
// ground have their own kind, everything else is "entity" with its type id
|
||||
export type EntityInfo =
|
||||
| { kind: "item"; id: string; x: number; y: number; z: number; item: ItemData }
|
||||
| {
|
||||
kind: "entity";
|
||||
type: string;
|
||||
id: string;
|
||||
x: number;
|
||||
y: number;
|
||||
z: number;
|
||||
// radians, see the server's Entity
|
||||
yaw: number;
|
||||
pitch: number;
|
||||
// for things whose head turns apart from their body
|
||||
head_yaw?: number;
|
||||
data: EntityData;
|
||||
};
|
||||
|
||||
// what an entity looks like that can change, like minecraft's SynchedEntityData: custom_name, custom_name_visible,
|
||||
// glowing, on_fire, silent, left_handed, equipment (slot to item). only what's set is there
|
||||
export type EntityData = Record<string, unknown>;
|
||||
|
||||
// x, y, z, block id, and its state bits when they aren't 0
|
||||
export type BlockChange = [number, number, number, string, number?];
|
||||
@@ -105,7 +118,7 @@ export type ServerMessage =
|
||||
// the server may change the name asked for, like alice to alice2
|
||||
name: string;
|
||||
players: PlayerInfo[];
|
||||
// items on the ground
|
||||
// the entities within their view distance
|
||||
entities: EntityInfo[];
|
||||
// the server's block id for each of its numeric ids, which level_chunk uses. clients number blocks their own way
|
||||
blocks: string[];
|
||||
@@ -129,7 +142,22 @@ export type ServerMessage =
|
||||
// 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 }
|
||||
| { type: "add_entity"; entity: EntityInfo }
|
||||
| { type: "move_entity"; id: string; x: number; y: number; z: number }
|
||||
| {
|
||||
type: "move_entity";
|
||||
id: string;
|
||||
x: number;
|
||||
y: number;
|
||||
z: number;
|
||||
yaw: number;
|
||||
pitch: number;
|
||||
head_yaw?: number;
|
||||
}
|
||||
// all of an entity's synced data, when any of it changed
|
||||
| { type: "entity_data"; id: string; data: EntityData }
|
||||
// hurt flashes it red, death starts it falling over (it's removed a second later)
|
||||
| { type: "entity_event"; id: string; event: "hurt" | "death" }
|
||||
// what's riding it now, by id
|
||||
| { type: "set_passengers"; id: string; passengers: string[] }
|
||||
// a dropped item's stack changed, like when two stacks merge
|
||||
| { type: "set_entity_item"; id: string; item: ItemData }
|
||||
| { type: "remove_entity"; id: string }
|
||||
|
||||
Reference in New Issue
Block a user