Move curios into the main bworld mod
@@ -289,7 +289,7 @@ export interface ItemApi {
|
||||
// the tool type it is, like "pickaxe" or "shovel", from the item's "tool"
|
||||
tool(id: Id): string | undefined;
|
||||
// the components its json lists and their params, a copy. a mod can read params of its components this way
|
||||
// without a stack, like curios does for curios:attribute_modifiers
|
||||
// without a stack, like the curios slots do for bworld:curio_modifiers
|
||||
components(id: Id): Record<Id, unknown>;
|
||||
}
|
||||
|
||||
@@ -396,7 +396,7 @@ export interface PlayerMenuBuilder {
|
||||
}
|
||||
|
||||
export interface MenuRegistry {
|
||||
// adds slots to every player's own inventory menu, always there while they play, like curios' slots next to the
|
||||
// adds slots to every player's own inventory menu, always there while they play, like the curios slots next to the
|
||||
// inventory. build runs when each player joins. only during setup
|
||||
extend_player_menu(build: (menu: PlayerMenuBuilder, player: Player) => void): void;
|
||||
// like registering a MenuType. the client script gives it a screen with ctx.ui.register_menu_screen
|
||||
|
||||
@@ -85,7 +85,8 @@ player.remove_modifier("bworld:attack_damage", "my_mod:rage");
|
||||
|
||||
The value is the base, plus every `add_value`, plus that times the amount of each `add_multiplied_base`, then times 1
|
||||
plus the amount of each `add_multiplied_total`. A modifier with the same id replaces the old one. Modifiers aren't
|
||||
saved: a mod that gives them should give them again when the player joins, the way Curios does for worn items.
|
||||
saved: a mod that gives them should give them again when the player joins, the way the base game's curios slots do for
|
||||
worn items.
|
||||
|
||||
Like Minecraft, an attack right after the last one, or right after changing the held item, does only a fifth of the
|
||||
damage, rising to full after `20 / attack_speed` ticks. A bar under the crosshair shows it filling up, and the server
|
||||
|
||||
@@ -7,8 +7,8 @@ Menus are how players use [containers](containers.md), like NeoForge's. A GUI ha
|
||||
- The **screen** lives in the client script. It only draws the menu and sends the player's clicks.
|
||||
|
||||
Every click goes to the server, which applies it following the menu's rules, so a modified client can only do what the
|
||||
menu allows. Chests, furnaces, the smithing table and Farmer's Delight's cooking pot are all menus, and Curios adds its
|
||||
slots to [the player's inventory](#the-players-inventory).
|
||||
menu allows. Chests, furnaces, the smithing table and Farmer's Delight's cooking pot are all menus, and the base game's
|
||||
curios slots are part of [the player's inventory](#the-players-inventory).
|
||||
|
||||
## Registering a Menu Type
|
||||
|
||||
@@ -197,7 +197,7 @@ ctx.menus.extend_player_menu((menu, player) => {
|
||||
|
||||
`add_slot` takes the same options as a menu's. `x` and `y` are from the inventory screen's top left, and can be outside
|
||||
it: a negative `x` is left of it. The engine draws a panel behind the slots outside its own, so they need no client
|
||||
code. Curios puts its slots in 2 columns this way.
|
||||
code. The base game puts its curios slots in 2 columns this way, in `mods/bworld/scripts/curios.ts`.
|
||||
|
||||
Shift clicking in the inventory puts a stack into the first of these slots whose `filter` takes it, before moving it
|
||||
between the hotbar and the rest of the inventory. Shift clicking one of them moves its stack back into the inventory.
|
||||
|
||||
@@ -97,7 +97,7 @@ At a block, the block's own [interaction](../blocks/components.md#interacting) c
|
||||
used instead of being placed.
|
||||
|
||||
`ctx.items.components(id)` gives the components an item's JSON lists and their parameters, so a mod can read its
|
||||
components' parameters for an item without a stack, like Curios does for `curios:attribute_modifiers`.
|
||||
components' parameters for an item without a stack, like the base game's curios slots do for `bworld:curio_modifiers`.
|
||||
|
||||
`on_use` doesn't say which block was clicked. For that, pair it with a block component's `on_interact`, the way the
|
||||
watering can uses `bworld:water_source`, or subscribe to the `block_interact` [event](../concepts/events.md).
|
||||
|
||||
@@ -77,6 +77,3 @@ ctx.net.send("copper_tools:reset_stats", {});
|
||||
anything over that without telling anyone.
|
||||
- Everything a client sends is untrusted: check it like a click or a chat message.
|
||||
- A handler that throws is logged under its mod, and the other handlers still run.
|
||||
|
||||
Curios (`mods/curios`) is a small example: its client script's button sends `curios:open`, and its server script opens
|
||||
the curio slots for that player.
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
"texture": "artifacts:feral_claws",
|
||||
"max_stack": 1,
|
||||
"components": {
|
||||
"curios:attribute_modifiers": [
|
||||
"bworld:curio_modifiers": [
|
||||
{ "attribute": "bworld:attack_speed", "amount": 0.3, "operation": "add_multiplied_base" }
|
||||
]
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
"texture": "artifacts:power_glove",
|
||||
"max_stack": 1,
|
||||
"components": {
|
||||
"curios:attribute_modifiers": [
|
||||
"bworld:curio_modifiers": [
|
||||
{ "attribute": "bworld:attack_damage", "amount": 4, "operation": "add_value" }
|
||||
]
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"format_version": 1,
|
||||
"id": "artifacts",
|
||||
"name": "Artifacts",
|
||||
"description": "A port of ochotonida's Artifacts: wearable items worn in Curios slots.",
|
||||
"description": "A port of ochotonida's Artifacts: wearable items worn in the curios slots.",
|
||||
"version": "0.1.0",
|
||||
"authors": [
|
||||
"ochotonida (original)",
|
||||
@@ -13,10 +13,6 @@
|
||||
{
|
||||
"id": "bworld",
|
||||
"version": "*"
|
||||
},
|
||||
{
|
||||
"id": "curios",
|
||||
"version": "*"
|
||||
}
|
||||
],
|
||||
"credits": "CREDITS.md"
|
||||
|
||||
@@ -719,3 +719,26 @@ Textures by Hugh "XSSheep" Rutland (https://www.minecraftforum.net/members/XSShe
|
||||
https://github.com/NovaWostra/Pixel-Perfection-Chorus-Eddit
|
||||
|
||||
license: [Creative Commons Attribution-Share Alike 4.0 International](http://creativecommons.org/licenses/by-sa/4.0/)
|
||||
|
||||
# Curios
|
||||
|
||||
The curios slots (`scripts/curios.ts`) are a port of [Curios](https://github.com/TheIllusiveC4/Curios) by C4. Their slot
|
||||
textures (`textures/empty_*_slot.png`) and game design come from the original, version 17.0.0-beta.2 for NeoForge 26.3,
|
||||
under the GNU Lesser General Public License, version 3 or later:
|
||||
|
||||
```
|
||||
Copyright (C) 2018-2024 C4
|
||||
|
||||
Curios is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published
|
||||
by the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Curios is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with Curios. If not, see <https://www.gnu.org/licenses/>.
|
||||
```
|
||||
|
||||
@@ -5,3 +5,47 @@ item behavior from `scripts/server.ts`, the same way it loads any other mod.
|
||||
|
||||
Some of the base game is still built into the engine: recipe types, the inventory screen and crafting grid, the HUD,
|
||||
`/give` and `/time`, mining rules, and terrain generation. See "The Engine and the Base Game" in `docs/modding_plan.md`.
|
||||
|
||||
## Curios
|
||||
|
||||
`scripts/curios.ts` is a port of [Curios](https://github.com/TheIllusiveC4/Curios): accessory slots, like rings,
|
||||
necklaces and belts, for any mod's items. They're in 2 columns left of the player's inventory, there whenever it's open.
|
||||
Shift clicking a curio in the inventory puts it in the first slot it fits.
|
||||
|
||||
Like the original, it adds no items, and a slot type only shows up once some mod puts an item in its tag.
|
||||
|
||||
### Making an Item a Curio
|
||||
|
||||
Add the item to the slot type's item tag. For a ring, `tags/items/bworld/curios/ring.json` in your mod:
|
||||
|
||||
```json
|
||||
{ "format_version": 1, "tag": { "values": ["jewelry:gold_ring"] } }
|
||||
```
|
||||
|
||||
| Tag | Slot |
|
||||
| ------------------------- | ---------------------- |
|
||||
| `#bworld:curios/curio` | Any slot, and its own. |
|
||||
| `#bworld:curios/head` | Head |
|
||||
| `#bworld:curios/necklace` | Necklace |
|
||||
| `#bworld:curios/back` | Back |
|
||||
| `#bworld:curios/body` | Body |
|
||||
| `#bworld:curios/bracelet` | Bracelet |
|
||||
| `#bworld:curios/hands` | Hands |
|
||||
| `#bworld:curios/ring` | Ring |
|
||||
| `#bworld:curios/belt` | Belt |
|
||||
| `#bworld:curios/feet` | Feet |
|
||||
| `#bworld:curios/charm` | Charm |
|
||||
|
||||
Every player has one slot of each type. Curios drop when the player dies, like the rest of what they carry.
|
||||
|
||||
### Attribute Modifiers
|
||||
|
||||
An item with the `bworld:curio_modifiers` component changes the wearer's
|
||||
[attributes](../../docs/modding/entities/players.md#attributes) while it's in a curio slot, and says so in its tooltip.
|
||||
The Power Glove from Artifacts:
|
||||
|
||||
```json
|
||||
"components": {
|
||||
"bworld:curio_modifiers": [{ "attribute": "bworld:attack_damage", "amount": 4, "operation": "add_value" }]
|
||||
}
|
||||
```
|
||||
|
||||
@@ -1,27 +1,25 @@
|
||||
// curios: accessory slots, in 2 columns left of the player's inventory. each player's curios are a
|
||||
// container of their own, and fall out when they die like the rest of what they carry. items with the
|
||||
// curios:attribute_modifiers component change the wearer's attributes, like curios' attribute modifiers
|
||||
import type { AttributeModifier, Container, Player, ServerContext } from "bworld/server";
|
||||
import { active_slots, fits, SLOTS } from "./slots.ts";
|
||||
// curios, from C4's Curios mod: accessory slots, in 2 columns left of the player's inventory. each player's curios are
|
||||
// a container of their own, and fall out when they die like the rest of what they carry. items with the
|
||||
// bworld:curio_modifiers component change the wearer's attributes, like curios' attribute modifiers
|
||||
import type { AttributeModifier, Container, Player, ServerContext, TagApi } from "bworld/server";
|
||||
|
||||
// where the left column of slots goes, from the inventory screen's left edge. the panel around them ends just left of it
|
||||
const COLUMNS_X = -45;
|
||||
|
||||
// curios:attribute_modifiers' params, a list of these
|
||||
// bworld:curio_modifiers' params, a list of these
|
||||
interface WornModifier {
|
||||
attribute: string;
|
||||
amount: number;
|
||||
operation: AttributeModifier["operation"];
|
||||
}
|
||||
|
||||
export function setup(ctx: ServerContext) {
|
||||
export function register_curios(ctx: ServerContext) {
|
||||
const active = active_slots(ctx.tags);
|
||||
|
||||
ctx.components.register_item<WornModifier[]>("curios:attribute_modifiers", {
|
||||
ctx.components.register_item<WornModifier[]>("bworld:curio_modifiers", {
|
||||
get_lore: (_item, modifiers) => ["When worn:", ...modifiers.map(describe)].join("\n"),
|
||||
});
|
||||
const modifiers_of = (id: string) =>
|
||||
(ctx.items.components(id)["curios:attribute_modifiers"] ?? []) as WornModifier[];
|
||||
const modifiers_of = (id: string) => (ctx.items.components(id)["bworld:curio_modifiers"] ?? []) as WornModifier[];
|
||||
|
||||
// the modifiers each online player's curios gave them, by player id, to take them off again
|
||||
const applied = new Map<string, { attribute: string; id: string }[]>();
|
||||
@@ -29,7 +27,7 @@ export function setup(ctx: ServerContext) {
|
||||
|
||||
// by player name, like the players themselves are saved. undefined until they first join with curios
|
||||
function saved_curios(player: Player): Container | undefined {
|
||||
const id = ctx.storage.get<Record<string, string>>("containers")?.[player.name];
|
||||
const id = ctx.storage.get<Record<string, string>>("curios")?.[player.name];
|
||||
return id ? ctx.containers.get(id) : undefined;
|
||||
}
|
||||
|
||||
@@ -37,8 +35,8 @@ export function setup(ctx: ServerContext) {
|
||||
const existing = saved_curios(player);
|
||||
if (existing) return existing;
|
||||
const container = ctx.containers.create(SLOTS.length);
|
||||
const ids = ctx.storage.get<Record<string, string>>("containers") ?? {};
|
||||
ctx.storage.set("containers", { ...ids, [player.name]: container.id });
|
||||
const ids = ctx.storage.get<Record<string, string>>("curios") ?? {};
|
||||
ctx.storage.set("curios", { ...ids, [player.name]: container.id });
|
||||
watch(player, container);
|
||||
return container;
|
||||
}
|
||||
@@ -57,7 +55,7 @@ export function setup(ctx: ServerContext) {
|
||||
const item = curios.get(index);
|
||||
if (!item || !active.includes(slot)) continue;
|
||||
for (const [i, { attribute, amount, operation }] of modifiers_of(item.id).entries()) {
|
||||
const id = `curios:${slot}/${i}`;
|
||||
const id = `bworld:curio/${slot}/${i}`;
|
||||
player.add_modifier(attribute, { id, amount, operation });
|
||||
now.push({ attribute, id });
|
||||
}
|
||||
@@ -79,7 +77,8 @@ export function setup(ctx: ServerContext) {
|
||||
ctx.menus.extend_player_menu((menu, player) => {
|
||||
if (active.length === 0) return;
|
||||
const curios = curios_of(player);
|
||||
// what's in slot types no item goes in anymore, since the mod that added them was removed, goes back to them
|
||||
// what's in slot types no item goes in anymore, since the mod that put items in them was removed, goes back
|
||||
// to them
|
||||
for (const [index, slot] of SLOTS.entries()) {
|
||||
const item = curios.get(index);
|
||||
if (item && !active.includes(slot)) {
|
||||
@@ -92,7 +91,7 @@ export function setup(ctx: ServerContext) {
|
||||
x: COLUMNS_X + (i % 2) * 18,
|
||||
y: 7 + Math.floor(i / 2) * 18,
|
||||
filter: (item) => fits(ctx.tags, slot, item.id),
|
||||
icon: `curios:empty_${slot}_slot`,
|
||||
icon: `bworld:empty_${slot}_slot`,
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -118,3 +117,30 @@ function describe({ attribute, amount, operation }: WornModifier): string {
|
||||
const value = operation === "add_value" ? `${Math.abs(amount)}` : `${Math.round(Math.abs(amount) * 100)}%`;
|
||||
return `${sign}${value} ${name}`;
|
||||
}
|
||||
|
||||
// the slot types, in curios' order. every player has one of each, at its index here in their curios container, so
|
||||
// slots keep their items when mods come and go
|
||||
const SLOTS = [
|
||||
"curio",
|
||||
"head",
|
||||
"necklace",
|
||||
"back",
|
||||
"body",
|
||||
"bracelet",
|
||||
"hands",
|
||||
"ring",
|
||||
"belt",
|
||||
"feet",
|
||||
"charm",
|
||||
];
|
||||
|
||||
// like curios, a slot type is only there once some item goes in it: something is in its item tag, #bworld:curios/ring
|
||||
// for rings
|
||||
function active_slots(tags: TagApi): string[] {
|
||||
return SLOTS.filter((slot) => tags.get("items", `bworld:curios/${slot}`).length > 0);
|
||||
}
|
||||
|
||||
// curios' tag validator: an item goes in the slot types whose tag it's in, and #bworld:curios/curio items go in any
|
||||
function fits(tags: TagApi, slot: string, id: string): boolean {
|
||||
return tags.has("items", `bworld:curios/${slot}`, id) || tags.has("items", "bworld:curios/curio", id);
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
// the base game's block and item behavior, written against the same api as any other mod
|
||||
import type { BlockRef, Container, EntityRef, Player, ServerContext } from "bworld/server";
|
||||
import { register_curios } from "./curios.ts";
|
||||
|
||||
export function setup(ctx: ServerContext) {
|
||||
register_hoeable(ctx);
|
||||
@@ -8,6 +9,7 @@ export function setup(ctx: ServerContext) {
|
||||
register_smithing_table(ctx);
|
||||
register_farming(ctx);
|
||||
register_fishing(ctx);
|
||||
register_curios(ctx);
|
||||
}
|
||||
|
||||
// right clicking with a type of tool turns the block into another, like any hoe on grass
|
||||
|
||||
|
Before Width: | Height: | Size: 145 B After Width: | Height: | Size: 145 B |
|
Before Width: | Height: | Size: 144 B After Width: | Height: | Size: 144 B |
|
Before Width: | Height: | Size: 152 B After Width: | Height: | Size: 152 B |
|
Before Width: | Height: | Size: 157 B After Width: | Height: | Size: 157 B |
|
Before Width: | Height: | Size: 139 B After Width: | Height: | Size: 139 B |
|
Before Width: | Height: | Size: 140 B After Width: | Height: | Size: 140 B |
|
Before Width: | Height: | Size: 149 B After Width: | Height: | Size: 149 B |
|
Before Width: | Height: | Size: 158 B After Width: | Height: | Size: 158 B |
|
Before Width: | Height: | Size: 157 B After Width: | Height: | Size: 157 B |
|
Before Width: | Height: | Size: 152 B After Width: | Height: | Size: 152 B |
|
Before Width: | Height: | Size: 144 B After Width: | Height: | Size: 144 B |
@@ -1,21 +0,0 @@
|
||||
# Curios
|
||||
|
||||
A bworld port of [Curios](https://github.com/TheIllusiveC4/Curios) by C4. Its slot textures and game design come from
|
||||
the original, version 17.0.0-beta.2 for NeoForge 26.3, under the GNU Lesser General Public License, version 3 or later:
|
||||
|
||||
```
|
||||
Copyright (C) 2018-2024 C4
|
||||
|
||||
Curios is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published
|
||||
by the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Curios is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with Curios. If not, see <https://www.gnu.org/licenses/>.
|
||||
```
|
||||
@@ -1,46 +0,0 @@
|
||||
# Curios
|
||||
|
||||
A port of [Curios](https://github.com/TheIllusiveC4/Curios): accessory slots, like rings, necklaces and belts, for any
|
||||
mod's items. They're in 2 columns left of the player's inventory, there whenever it's open. Shift clicking a curio in
|
||||
the inventory puts it in the first slot it fits.
|
||||
|
||||
Like the original, Curios adds no items and no slots of its own. A slot type only shows up once some mod puts an item in
|
||||
its tag.
|
||||
|
||||
## Making an Item a Curio
|
||||
|
||||
Add the item to the slot type's item tag. For a ring, `tags/items/curios/ring.json` in your mod:
|
||||
|
||||
```json
|
||||
{ "format_version": 1, "tag": { "values": ["jewelry:gold_ring"] } }
|
||||
```
|
||||
|
||||
| Tag | Slot |
|
||||
| ------------------ | ---------------------- |
|
||||
| `#curios:curio` | Any slot, and its own. |
|
||||
| `#curios:head` | Head |
|
||||
| `#curios:necklace` | Necklace |
|
||||
| `#curios:back` | Back |
|
||||
| `#curios:body` | Body |
|
||||
| `#curios:bracelet` | Bracelet |
|
||||
| `#curios:hands` | Hands |
|
||||
| `#curios:ring` | Ring |
|
||||
| `#curios:belt` | Belt |
|
||||
| `#curios:feet` | Feet |
|
||||
| `#curios:charm` | Charm |
|
||||
|
||||
Every player has one slot of each type. Curios drop when the player dies, like the rest of what they carry.
|
||||
|
||||
## Attribute Modifiers
|
||||
|
||||
An item with the `curios:attribute_modifiers` component changes the wearer's
|
||||
[attributes](../../docs/modding/entities/players.md#attributes) while it's in a curio slot, and says so in its tooltip.
|
||||
The Power Glove from Artifacts:
|
||||
|
||||
```json
|
||||
"components": {
|
||||
"curios:attribute_modifiers": [{ "attribute": "bworld:attack_damage", "amount": 4, "operation": "add_value" }]
|
||||
}
|
||||
```
|
||||
|
||||
Depend on `curios` to use it.
|
||||
@@ -1,16 +0,0 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"id": "curios",
|
||||
"name": "Curios",
|
||||
"description": "A port of C4's Curios: accessory slots like rings, necklaces and belts, for any mod's items.",
|
||||
"version": "0.1.0",
|
||||
"authors": [
|
||||
"C4 (original)",
|
||||
"paula (port)"
|
||||
],
|
||||
"game_version": ">=0.1.0",
|
||||
"credits": "CREDITS.md",
|
||||
"scripts": {
|
||||
"server": "scripts/server.ts"
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
// curios' slot types
|
||||
import type { TagApi } from "bworld/server";
|
||||
|
||||
// in curios' order. every player has one of each, at its index here in their curios container, so slots keep their
|
||||
// items when mods come and go
|
||||
export const SLOTS = [
|
||||
"curio",
|
||||
"head",
|
||||
"necklace",
|
||||
"back",
|
||||
"body",
|
||||
"bracelet",
|
||||
"hands",
|
||||
"ring",
|
||||
"belt",
|
||||
"feet",
|
||||
"charm",
|
||||
];
|
||||
|
||||
// like curios, a slot type is only there once some item goes in it: something is in its item tag, #curios:ring for
|
||||
// rings
|
||||
export function active_slots(tags: TagApi): string[] {
|
||||
return SLOTS.filter((slot) => tags.get("items", `curios:${slot}`).length > 0);
|
||||
}
|
||||
|
||||
// curios' tag validator: an item goes in the slot types whose tag it's in, and #curios:curio items go in any
|
||||
export function fits(tags: TagApi, slot: string, id: string): boolean {
|
||||
return tags.has("items", `curios:${slot}`, id) || tags.has("items", "curios:curio", id);
|
||||
}
|
||||
@@ -202,7 +202,7 @@ export class GameServer {
|
||||
if (entity instanceof ServerPlayer) this.#kill(entity, source);
|
||||
},
|
||||
});
|
||||
this.mods.storage = saved?.mod_storage ?? {};
|
||||
this.mods.storage = upgrade_mod_storage(saved?.mod_storage ?? {});
|
||||
if (saved) {
|
||||
this.world.load_chunks(save?.chunks ?? [], saved.worldgen);
|
||||
}
|
||||
@@ -1700,6 +1700,17 @@ interface SavedLevelV4 extends Omit<SavedLevel, "version" | "entities"> {
|
||||
}[];
|
||||
}
|
||||
|
||||
// curios was a mod of its own before it became part of the base game: which container is each player's curios moves
|
||||
// into the base game's storage
|
||||
function upgrade_mod_storage(storage: Record<string, Record<string, unknown>>) {
|
||||
const curios = storage.curios?.containers;
|
||||
if (curios !== undefined && storage.bworld?.curios === undefined) {
|
||||
(storage.bworld ??= {}).curios = curios;
|
||||
delete storage.curios;
|
||||
}
|
||||
return storage;
|
||||
}
|
||||
|
||||
function upgrade_v4_entities(entities: SavedLevelV4["entities"]): SavedEntity[] {
|
||||
return (entities ?? []).map((entity): SavedItemEntity => ({
|
||||
id: ITEM_ENTITY_TYPE,
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
// curios: accessory slots for items in the curios tags, next to the player's inventory, see mods/curios
|
||||
// curios: accessory slots for items in the curios tags, next to the player's inventory, see
|
||||
// mods/bworld/scripts/curios.ts
|
||||
import { assertEquals } from "@std/assert";
|
||||
import { PLAYER_MENU_EXTRA } from "$/common/protocol.ts";
|
||||
import { copy_dir, test_game } from "./helpers.ts";
|
||||
import type { WorldSave } from "$/server/game/saves.ts";
|
||||
|
||||
// deno-lint-ignore no-explicit-any
|
||||
type Msg = any;
|
||||
@@ -9,22 +11,27 @@ type Msg = any;
|
||||
const last_container = (messages: Msg[], container: string) =>
|
||||
messages.filter((m) => m.type === "container" && m.container === container).at(-1)?.items;
|
||||
|
||||
// the base game, curios, and a mod with a ring and an amulet that goes in any slot
|
||||
async function setup() {
|
||||
// the base game, and a mod with a ring and an amulet that goes in any slot
|
||||
async function setup(save?: WorldSave) {
|
||||
const dir = Deno.makeTempDirSync({ prefix: "bworld_curios_" });
|
||||
copy_dir("mods/bworld", `${dir}/bworld`);
|
||||
copy_dir("mods/curios", `${dir}/curios`);
|
||||
const write = (path: string, json: unknown) => {
|
||||
Deno.mkdirSync(`${dir}/jewelry/${path}`.replace(/\/[^/]+$/, ""), { recursive: true });
|
||||
Deno.writeTextFileSync(`${dir}/jewelry/${path}`, JSON.stringify(json));
|
||||
};
|
||||
write("manifest.json", { format_version: 1, id: "jewelry", name: "Jewelry", version: "1.0.0" });
|
||||
write("manifest.json", {
|
||||
format_version: 1,
|
||||
id: "jewelry",
|
||||
name: "Jewelry",
|
||||
version: "1.0.0",
|
||||
dependencies: [{ id: "bworld", version: "*" }],
|
||||
});
|
||||
write("items/ring.json", { format_version: 1, item: { id: "jewelry:ring", texture: "bworld:coal" } });
|
||||
write("items/amulet.json", { format_version: 1, item: { id: "jewelry:amulet", texture: "bworld:coal" } });
|
||||
write("tags/items/curios/ring.json", { format_version: 1, tag: { values: ["jewelry:ring"] } });
|
||||
write("tags/items/curios/curio.json", { format_version: 1, tag: { values: ["jewelry:amulet"] } });
|
||||
write("tags/items/bworld/curios/ring.json", { format_version: 1, tag: { values: ["jewelry:ring"] } });
|
||||
write("tags/items/bworld/curios/curio.json", { format_version: 1, tag: { values: ["jewelry:amulet"] } });
|
||||
|
||||
const t = await test_game(dir);
|
||||
const t = await test_game(dir, save);
|
||||
t.join(1, "alice");
|
||||
for (const id of ["jewelry:ring", "jewelry:amulet", "bworld:coal"]) {
|
||||
t.send(1, { type: "chat", text: `/give ${id}` });
|
||||
@@ -33,7 +40,7 @@ async function setup() {
|
||||
return t;
|
||||
}
|
||||
|
||||
// what's in the curios slots, the ones curios added to the player's own menu, as last synced
|
||||
// what's in the curios slots, the ones the base game added to the player's own menu, as last synced
|
||||
const curios_items = (messages: Msg[]) => last_container(messages, "extra");
|
||||
|
||||
Deno.test("the slot types some item goes in are in 2 columns left of the inventory, with their icons", async () => {
|
||||
@@ -41,8 +48,8 @@ Deno.test("the slot types some item goes in are in 2 columns left of the invento
|
||||
t.game.on_disconnect(1);
|
||||
const join = t.join(1, "alice");
|
||||
assertEquals(join.player_menu, [
|
||||
{ x: -45, y: 7, icon: "curios:empty_curio_slot" },
|
||||
{ x: -27, y: 7, icon: "curios:empty_ring_slot" },
|
||||
{ x: -45, y: 7, icon: "bworld:empty_curio_slot" },
|
||||
{ x: -27, y: 7, icon: "bworld:empty_ring_slot" },
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -50,7 +57,7 @@ Deno.test("items only go in the slots they fit, and fall out when the player die
|
||||
const t = await setup();
|
||||
|
||||
// coal fits nowhere so it moves to the rest of the inventory, the ring only goes in the ring slot, and
|
||||
// #curios:curio items in any slot, the curio slot first
|
||||
// #bworld:curios/curio items in any slot, the curio slot first
|
||||
for (const slot of [2, 0, 1]) t.send(1, { type: "click", menu: 0, slot, button: 0, shift: true });
|
||||
const messages = t.take(1);
|
||||
assertEquals(last_container(messages, "inventory").slice(0, 3), [null, null, null]);
|
||||
@@ -69,3 +76,20 @@ Deno.test("items only go in the slots they fit, and fall out when the player die
|
||||
t.game.tick();
|
||||
assertEquals(curios_items(t.take(1)), [null, null]);
|
||||
});
|
||||
|
||||
Deno.test("curios worn when curios was a mod of its own are still worn", async () => {
|
||||
const t = await setup();
|
||||
t.send(1, { type: "click", menu: 0, slot: 0, button: 0, shift: true });
|
||||
t.game.on_disconnect(1);
|
||||
|
||||
// how a save from then kept which container is each player's curios
|
||||
const save = t.game.save();
|
||||
const level = JSON.parse(save.level);
|
||||
level.mod_storage.curios = { containers: level.mod_storage.bworld.curios };
|
||||
delete level.mod_storage.bworld.curios;
|
||||
|
||||
const loaded = await setup({ ...save, level: JSON.stringify(level) });
|
||||
const [ring] = loaded.game.players()[0].inventory_menu.extra.slice(1);
|
||||
assertEquals(ring.container.get_item(ring.index)?.to_data(), { id: "jewelry:ring", count: 1 });
|
||||
assertEquals(loaded.game.mods.storage.curios, undefined);
|
||||
});
|
||||
|
||||
@@ -31,7 +31,6 @@ Deno.test("welcome lists what to download, and nothing happens until ready", asy
|
||||
assertEquals(welcome.type, "welcome");
|
||||
assertEquals(welcome.mods.map((m: { id: string }) => m.id), [
|
||||
"bworld",
|
||||
"curios",
|
||||
"artifacts",
|
||||
"farmersdelight",
|
||||
"recipe_viewer",
|
||||
|
||||