Curios slots rendering !
This commit is contained in:
@@ -347,6 +347,7 @@ export class GameServer {
|
||||
|
||||
this.entities.sync();
|
||||
for (const player of this.#players.values()) {
|
||||
this.#sync_worn(player);
|
||||
this.#sync(player);
|
||||
}
|
||||
this.#send_chunks();
|
||||
@@ -728,6 +729,11 @@ export class GameServer {
|
||||
time: this.world.time,
|
||||
});
|
||||
this.#players.set(conn, player);
|
||||
// what they wear themselves, the others get it with player_join
|
||||
player.worn_sent = JSON.stringify(player.worn_list());
|
||||
if (player.worn_sent !== "[]") {
|
||||
this.#send(player, { type: "player_worn", id: player.id, worn: player.worn_list() });
|
||||
}
|
||||
// the chunks come with the next ticks
|
||||
this.#update_view(player);
|
||||
this.#sync(player);
|
||||
@@ -1555,6 +1561,15 @@ export class GameServer {
|
||||
}
|
||||
}
|
||||
|
||||
// what a player wears that shows, to everyone when it changed
|
||||
#sync_worn(player: ServerPlayer) {
|
||||
const worn = player.worn_list();
|
||||
const json = JSON.stringify(worn);
|
||||
if (json === player.worn_sent) return;
|
||||
player.worn_sent = json;
|
||||
this.#broadcast({ type: "player_worn", id: player.id, worn });
|
||||
}
|
||||
|
||||
// tell the player what's really at a position, undoing anything their client guessed
|
||||
#correct(player: ServerPlayer, x: number, y: number, z: number) {
|
||||
if (y < 0 || y >= CHUNK_HEIGHT || !player.chunks.has_block(x, z)) {
|
||||
|
||||
@@ -931,6 +931,12 @@ function player_api(game: GameServer, player: ServerPlayer): Player {
|
||||
send_message(text) {
|
||||
game.send_chat(player, String(text));
|
||||
},
|
||||
set_worn(key, items) {
|
||||
if (typeof key !== "string" || key.length === 0) throw new Error("set_worn needs a key, like \"mymod:hats\"");
|
||||
if (!Array.isArray(items)) throw new Error("set_worn needs a list of items, [] for none");
|
||||
if (items.length === 0) player.worn.delete(key);
|
||||
else player.worn.set(key, items.map(new_stack));
|
||||
},
|
||||
teleport(x, y, z) {
|
||||
game.teleport(player, x, y, z);
|
||||
},
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { PLAYER_EYE_HEIGHT, PLAYER_HEIGHT, PLAYER_WIDTH } from "$/common/constants.ts";
|
||||
import { EverythingRegistry, type ItemRegistry } from "$/common/everything_registry.ts";
|
||||
import { Container, Cursor, ItemData, ItemStack } from "$/common/inventory.ts";
|
||||
import type { GridRecipe } from "$/common/mod_data.ts";
|
||||
import { Menu, PlayerMenu } from "./menu.ts";
|
||||
@@ -66,6 +67,10 @@ export class ServerPlayer extends LivingEntity {
|
||||
menu: Menu | undefined;
|
||||
// the last menu id given out, they go 1 to 100 and around
|
||||
menu_id = 0;
|
||||
// what mods show on them, by each mod's key, see set_worn. not saved, mods set it again when they join
|
||||
worn = new Map<string, ItemStack[]>();
|
||||
// the json of the worn list everyone was last sent, to send it again when it changes
|
||||
worn_sent = "[]";
|
||||
// base64 png, see /skin. undefined is the default skin
|
||||
skin: string | undefined;
|
||||
// the skin is for the model with 3 pixel wide arms
|
||||
@@ -186,9 +191,17 @@ export class ServerPlayer extends LivingEntity {
|
||||
pitch: this.pitch,
|
||||
skin: this.skin,
|
||||
slim: this.slim || undefined,
|
||||
...(this.worn_list().length ? { worn: this.worn_list() } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
// what they wear that shows, every key's in the order they were first set: the items that have a worn model
|
||||
worn_list(): ItemData[] {
|
||||
return [...this.worn.values()].flat()
|
||||
.filter((stack) => EverythingRegistry.get<ItemRegistry>("items", stack.type_id)?.worn)
|
||||
.map((stack) => stack.to_data());
|
||||
}
|
||||
|
||||
save_player(): SavedPlayer {
|
||||
return {
|
||||
x: this.x,
|
||||
|
||||
Reference in New Issue
Block a user