Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1fc92a7b00 | ||
|
|
a7835261e1 |
@@ -56,8 +56,9 @@ const NO_INPUT: MoveInput = { x: 0, z: 0, jump: false, sprint: false, sneak: fal
|
||||
export class LocalPlayer extends Player {
|
||||
client: Client;
|
||||
inventories = new ClientInventories();
|
||||
// what the server says, see server/game/vitals.ts. out of 20
|
||||
// what the server says, see server/game/vitals.ts. food out of 20, health out of max_health
|
||||
health = 20;
|
||||
max_health = 20;
|
||||
food = 20;
|
||||
saturation = 5;
|
||||
// the attack speed attribute the server sent, and when they last attacked or switched slots, for the indicator
|
||||
|
||||
@@ -12,11 +12,14 @@ const HOTBAR_HEIGHT = 22;
|
||||
// each slot is 20 across, the item sits 3 in from its corner and the selection 1 out
|
||||
const HOTBAR_CELL = 20;
|
||||
const HOTBAR_ITEM_INSET = 3;
|
||||
// hearts and hunger: 10 icons each, 8 apart, above the hotbar's top
|
||||
// hearts and hunger: 10 icons each, 8 apart, above the hotbar's top. more max health stacks more rows of hearts above,
|
||||
// 10 apart, closer together when there are many, like minecraft
|
||||
const ICON_SIZE = 9;
|
||||
const ICON_SPACING = 8;
|
||||
const ICONS_ABOVE_HOTBAR = 17;
|
||||
const MAX_VITAL = 20;
|
||||
const ICONS_PER_ROW = 10;
|
||||
const HEART_ROW_SPACING = 10;
|
||||
const MIN_HEART_ROW_SPACING = 3;
|
||||
// how long the held item's name shows above the hotbar after it changes, and the last part of that it fades out in
|
||||
const HELD_NAME_MS = 2000;
|
||||
const HELD_NAME_FADE_MS = 500;
|
||||
@@ -40,9 +43,10 @@ export class Hud {
|
||||
render(client: Client) {
|
||||
this.#render_hotbar(client.player.inventories);
|
||||
this.#render_vitals(client);
|
||||
this.#render_held_name(client.player.inventories);
|
||||
const top = icons_y() - heart_rows_height(client.player.max_health);
|
||||
this.#render_held_name(client.player.inventories, top);
|
||||
this.#render_crosshair(client);
|
||||
client.chat.render(false, icons_y() - HELD_NAME_GAP);
|
||||
client.chat.render(false, top - HELD_NAME_GAP);
|
||||
}
|
||||
|
||||
#render_hotbar(inventories: ClientInventories) {
|
||||
@@ -63,7 +67,8 @@ export class Hud {
|
||||
}
|
||||
|
||||
// like minecraft: switching slots, or a different item ending up in the selected one, shows its name for a bit
|
||||
#render_held_name(inventories: ClientInventories) {
|
||||
// top is the top of the hearts
|
||||
#render_held_name(inventories: ClientInventories, top: number) {
|
||||
const item = inventories.inventory.get_item(inventories.hotbar_selected);
|
||||
const held = item ? `${inventories.hotbar_selected} ${item.type_id}` : "";
|
||||
const now = performance.now();
|
||||
@@ -79,7 +84,7 @@ export class Hud {
|
||||
const alpha = Math.min(1, (HELD_NAME_MS - shown_for) / HELD_NAME_FADE_MS);
|
||||
const name = display_name(item.type_id);
|
||||
const x = (canvas.width - measure_text(name, TEXT_SCALE)) / 2;
|
||||
const y = icons_y() - HELD_NAME_GAP - TEXT_HEIGHT * TEXT_SCALE;
|
||||
const y = top - HELD_NAME_GAP - TEXT_HEIGHT * TEXT_SCALE;
|
||||
// a shadow so it reads over bright sky and snow
|
||||
draw_text(name, x + TEXT_SCALE, y + TEXT_SCALE, TEXT_SCALE, [0.15, 0.15, 0.15, alpha]);
|
||||
draw_text(name, x, y, TEXT_SCALE, [1, 1, 1, alpha]);
|
||||
@@ -96,14 +101,19 @@ export class Hud {
|
||||
const food = Math.ceil(player.food);
|
||||
const saturation = Math.min(player.saturation, player.food);
|
||||
|
||||
for (let i = 0; i < MAX_VITAL / 2; i++) {
|
||||
const heart_x = left + i * ICON_SPACING * GUI_SCALE;
|
||||
draw_gui_sprite("heart_container", heart_x, y);
|
||||
const hearts = Math.ceil(player.max_health / 2);
|
||||
const row_spacing = heart_row_spacing(player.max_health) * GUI_SCALE;
|
||||
for (let i = 0; i < hearts; i++) {
|
||||
const heart_x = left + (i % ICONS_PER_ROW) * ICON_SPACING * GUI_SCALE;
|
||||
const heart_y = y - Math.floor(i / ICONS_PER_ROW) * row_spacing;
|
||||
draw_gui_sprite("heart_container", heart_x, heart_y);
|
||||
const heart = icon_fill(health, i);
|
||||
if (heart) {
|
||||
draw_gui_sprite(heart === "full" ? "heart_full" : "heart_half", heart_x, y);
|
||||
draw_gui_sprite(heart === "full" ? "heart_full" : "heart_half", heart_x, heart_y);
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = 0; i < ICONS_PER_ROW; i++) {
|
||||
// hunger goes right to left
|
||||
const food_x = right - (i * ICON_SPACING + ICON_SIZE) * GUI_SCALE;
|
||||
draw_gui_sprite("food_empty", food_x, y);
|
||||
@@ -149,7 +159,19 @@ function icons_y() {
|
||||
return hotbar_position().y - ICONS_ABOVE_HOTBAR * GUI_SCALE;
|
||||
}
|
||||
|
||||
// whether icon i of a 0 to 20 value is full, half or empty
|
||||
// how far apart rows of hearts are, in gui pixels
|
||||
function heart_row_spacing(max_health: number) {
|
||||
const rows = Math.ceil(max_health / 2 / ICONS_PER_ROW);
|
||||
return Math.max(HEART_ROW_SPACING - (rows - 2), MIN_HEART_ROW_SPACING);
|
||||
}
|
||||
|
||||
// how much higher the rows of hearts past the first go, on the canvas
|
||||
function heart_rows_height(max_health: number) {
|
||||
const rows = Math.ceil(max_health / 2 / ICONS_PER_ROW);
|
||||
return Math.max(0, rows - 1) * heart_row_spacing(max_health) * GUI_SCALE;
|
||||
}
|
||||
|
||||
// whether icon i of a value, 2 points an icon, is full, half or empty
|
||||
function icon_fill(value: number, i: number): "full" | "half" | undefined {
|
||||
if (value >= i * 2 + 2) return "full";
|
||||
if (value === i * 2 + 1) return "half";
|
||||
|
||||
@@ -76,6 +76,7 @@ export class ClientPacketListener {
|
||||
break;
|
||||
case "vitals":
|
||||
client.player.health = message.health;
|
||||
client.player.max_health = message.max_health;
|
||||
client.player.food = message.food;
|
||||
client.player.saturation = message.saturation;
|
||||
break;
|
||||
|
||||
@@ -216,7 +216,8 @@ export interface Player {
|
||||
give_item(id: Id, count?: number, data?: unknown): void;
|
||||
send_message(text: string): void;
|
||||
teleport(x: number, y: number, z: number): void;
|
||||
// health and hunger, like minecraft: 20 each, saturation is never above hunger
|
||||
// health and hunger, like minecraft: 20 each, saturation is never above hunger. max_health is the
|
||||
// bworld:max_health attribute
|
||||
readonly health: number;
|
||||
readonly max_health: number;
|
||||
readonly food: number;
|
||||
@@ -289,7 +290,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 +397,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
|
||||
|
||||
@@ -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 = 15;
|
||||
export const PROTOCOL_VERSION = 16;
|
||||
|
||||
export interface PlayerInfo {
|
||||
id: string;
|
||||
@@ -211,8 +211,8 @@ export type ServerMessage =
|
||||
| { type: "time"; time: number }
|
||||
// answers suggest: start is where in the text the suggestions replace from, up to the caret
|
||||
| { type: "suggestions"; id: number; start: number; suggestions: { text: string; tooltip?: string }[] }
|
||||
// the player's own health, hunger and saturation, when they change
|
||||
| { type: "vitals"; health: number; food: number; saturation: number }
|
||||
// the player's own health, max health, hunger and saturation, when they change
|
||||
| { type: "vitals"; health: number; max_health: number; food: number; saturation: number }
|
||||
// the player's own attack speed attribute, when it changes, for the attack indicator under the crosshair
|
||||
| { type: "attack_speed"; value: number }
|
||||
// a mod's server script talking to its client script, see ctx.net
|
||||
|
||||
@@ -29,7 +29,7 @@ interface Player {
|
||||
teleport(x: number, y: number, z: number): void;
|
||||
|
||||
readonly health: number; // out of max_health
|
||||
readonly max_health: number; // 20
|
||||
readonly max_health: number; // 20, or what the bworld:max_health attribute makes it
|
||||
readonly food: number; // hunger, out of 20
|
||||
readonly saturation: number; // never above food
|
||||
|
||||
@@ -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,48 @@ 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.
|
||||
|
||||
A slot type only shows up once some item is in its tag. The base game's one curio is the giant chestplate, a body curio
|
||||
that gives 20 more max health while worn, so the body slot is always there.
|
||||
|
||||
### 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" }]
|
||||
}
|
||||
```
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"item": {
|
||||
"id": "bworld:giant_chestplate",
|
||||
"texture": "bworld:giant_chestplate",
|
||||
"max_stack": 1,
|
||||
"components": {
|
||||
"bworld:curio_modifiers": [
|
||||
{ "attribute": "bworld:max_health", "amount": 20, "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,9 +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 });
|
||||
watch(player, container);
|
||||
const ids = ctx.storage.get<Record<string, string>>("curios") ?? {};
|
||||
ctx.storage.set("curios", { ...ids, [player.name]: container.id });
|
||||
return container;
|
||||
}
|
||||
|
||||
@@ -57,7 +54,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 });
|
||||
}
|
||||
@@ -65,21 +62,21 @@ export function setup(ctx: ServerContext) {
|
||||
applied.set(player.id, now);
|
||||
}
|
||||
|
||||
ctx.events.after.player_join.subscribe(({ player }) => {
|
||||
const curios = saved_curios(player);
|
||||
if (curios) watch(player, curios);
|
||||
});
|
||||
ctx.events.after.player_leave.subscribe(({ player }) => {
|
||||
stop_watching.get(player.id)?.();
|
||||
stop_watching.delete(player.id);
|
||||
applied.delete(player.id);
|
||||
});
|
||||
|
||||
// the slot types in 2 columns left of the inventory, always there while it's open. the engine draws their panel
|
||||
// the slot types in 2 columns left of the inventory, always there while it's open. the engine draws their panel.
|
||||
// this runs as they join, before their health is checked against their max health, so what their curios give them
|
||||
// comes back first
|
||||
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
|
||||
watch(player, curios);
|
||||
// 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 +89,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 +115,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
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"tag": {
|
||||
"values": ["bworld:giant_chestplate"]
|
||||
}
|
||||
}
|
||||
|
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 |
|
After Width: | Height: | Size: 388 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);
|
||||
}
|
||||
@@ -104,6 +104,12 @@ export abstract class LivingEntity extends Entity {
|
||||
this.#health = Math.min(this.max_health, Math.max(0, value));
|
||||
}
|
||||
|
||||
// health from a save. it can be over max_health until the next tick, so max_health modifiers given back while
|
||||
// loading, like worn curios', keep it
|
||||
load_health(value: number) {
|
||||
this.#health = Math.max(0, value);
|
||||
}
|
||||
|
||||
get dead() {
|
||||
return this.#health <= 0;
|
||||
}
|
||||
@@ -439,6 +445,8 @@ export abstract class LivingEntity extends Entity {
|
||||
}
|
||||
|
||||
tick_effects() {
|
||||
// like minecraft, losing max health, like a max_health modifier going away, takes the health over it
|
||||
if (this.#health > this.max_health) this.#health = this.max_health;
|
||||
for (const effect of [...this.effects.values()]) {
|
||||
if (this.effects.get(effect.type.id) !== effect) continue;
|
||||
const result = effect.tick(this);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -1372,6 +1372,7 @@ export class GameServer {
|
||||
}
|
||||
player.vitals.tick(
|
||||
player.health,
|
||||
player.max_health,
|
||||
(amount) => this.heal_player(player, amount),
|
||||
(amount) => this.damage_player(player, amount, "starve"),
|
||||
);
|
||||
@@ -1533,9 +1534,15 @@ export class GameServer {
|
||||
sync("extra", items, () => ({ type: "container", container: "extra", items }));
|
||||
}
|
||||
|
||||
// like minecraft, losing max health, like a curio's modifier going away, takes the health over it
|
||||
if (player.health > player.max_health) player.health = player.max_health;
|
||||
const { food, saturation } = player.vitals;
|
||||
const health = player.health;
|
||||
sync("vitals", [health, food, saturation], () => ({ type: "vitals", health, food, saturation }));
|
||||
const { health, max_health } = player;
|
||||
sync(
|
||||
"vitals",
|
||||
[health, max_health, food, saturation],
|
||||
() => ({ type: "vitals", health, max_health, food, saturation }),
|
||||
);
|
||||
const attack_speed = player.attribute(ATTRIBUTES.attack_speed);
|
||||
sync("attack_speed", attack_speed, () => ({ type: "attack_speed", value: attack_speed }));
|
||||
|
||||
@@ -1700,6 +1707,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,
|
||||
|
||||
@@ -45,7 +45,6 @@ import { AIR_ID } from "$/common/protocol.ts";
|
||||
import type { GameServer } from "./game_server.ts";
|
||||
import type { ServerPlayer } from "./player.ts";
|
||||
import { Menu, type MenuSlot } from "./menu.ts";
|
||||
import { MAX_HEALTH } from "./vitals.ts";
|
||||
import type { Entity } from "./entity/entity.ts";
|
||||
import { create_entity } from "./entity/entity_types.ts";
|
||||
import { attribute_type, type AttributeType, MODIFIER_OPERATIONS } from "./entity/attributes.ts";
|
||||
@@ -938,7 +937,9 @@ function player_api(game: GameServer, player: ServerPlayer): Player {
|
||||
get health() {
|
||||
return player.health;
|
||||
},
|
||||
max_health: MAX_HEALTH,
|
||||
get max_health() {
|
||||
return player.max_health;
|
||||
},
|
||||
get food() {
|
||||
return player.vitals.food;
|
||||
},
|
||||
|
||||
@@ -213,7 +213,7 @@ export class ServerPlayer extends LivingEntity {
|
||||
this.selected_slot = saved.selected_slot;
|
||||
this.inventory.load(saved.inventory);
|
||||
this.vitals.load(saved.vitals);
|
||||
this.health = saved.vitals?.health ?? this.max_health;
|
||||
this.load_health(saved.vitals?.health ?? this.max_health);
|
||||
this.skin = saved.skin;
|
||||
this.slim = saved.slim ?? false;
|
||||
}
|
||||
|
||||
@@ -56,9 +56,9 @@ export class Vitals {
|
||||
return this.food < MAX_FOOD;
|
||||
}
|
||||
|
||||
// one tick, for someone with that much health. heal and hurt go through the game server, which fires events and
|
||||
// handles dying
|
||||
tick(health: number, heal: (amount: number) => void, hurt: (amount: number) => void) {
|
||||
// one tick, for someone with that much health out of max_health. heal and hurt go through the game server, which
|
||||
// fires events and handles dying
|
||||
tick(health: number, max_health: number, heal: (amount: number) => void, hurt: (amount: number) => void) {
|
||||
if (this.exhaustion > EXHAUSTION_PER_POINT) {
|
||||
this.exhaustion -= EXHAUSTION_PER_POINT;
|
||||
if (this.saturation > 0) {
|
||||
@@ -68,7 +68,7 @@ export class Vitals {
|
||||
}
|
||||
}
|
||||
|
||||
const hurt_some = health < MAX_HEALTH;
|
||||
const hurt_some = health < max_health;
|
||||
if (this.saturation > 0 && hurt_some && this.food >= MAX_FOOD) {
|
||||
if (++this.#timer >= FAST_REGEN_TICKS) {
|
||||
const amount = Math.min(this.saturation, 6);
|
||||
|
||||
@@ -18,14 +18,14 @@ async function setup() {
|
||||
|
||||
Deno.test("the power glove and feral claws go in the hands slot, and only work while worn", async () => {
|
||||
const t = await setup();
|
||||
// the hands slot is the only curios one, after the player's own menu's
|
||||
// the hands slot is the second curios one, after the body slot, which are after the player's own menu's
|
||||
t.send(1, { type: "click", menu: 0, slot: 0, button: 0, shift: true });
|
||||
t.game.tick();
|
||||
assertEquals(t.alice.attribute(ATTRIBUTES.attack_damage), 1 + 4);
|
||||
|
||||
// swapped for the claws by hand: the glove's damage goes, the claws' speed comes
|
||||
t.send(1, { type: "click", menu: 0, slot: 1, button: 0 });
|
||||
t.send(1, { type: "click", menu: 0, slot: PLAYER_MENU_EXTRA, button: 0 });
|
||||
t.send(1, { type: "click", menu: 0, slot: PLAYER_MENU_EXTRA + 1, button: 0 });
|
||||
t.game.tick();
|
||||
assertEquals(t.alice.attribute(ATTRIBUTES.attack_damage), 1);
|
||||
assertEquals(t.alice.attribute(ATTRIBUTES.attack_speed), 4 * 1.3);
|
||||
@@ -35,7 +35,7 @@ Deno.test("worn artifacts work again after rejoining, and say what they do", asy
|
||||
const t = await setup();
|
||||
t.send(1, { type: "click", menu: 0, slot: 0, button: 0, shift: true });
|
||||
const worn = t.take(1).findLast((m: Msg) => m.type === "container" && m.container === "extra").items;
|
||||
assertEquals(worn[0].lore, "When worn:\n+4 Attack Damage");
|
||||
assertEquals(worn[1].lore, "When worn:\n+4 Attack Damage");
|
||||
|
||||
t.game.on_disconnect(1);
|
||||
t.join(1, "alice");
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
// curios: accessory slots for items in the curios tags, next to the player's inventory, see mods/curios
|
||||
import { assertEquals } from "@std/assert";
|
||||
// curios: accessory slots for items in the curios tags, next to the player's inventory, see
|
||||
// mods/bworld/scripts/curios.ts
|
||||
import { assert, 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,16 +40,18 @@ 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 () => {
|
||||
const t = await setup();
|
||||
t.game.on_disconnect(1);
|
||||
const join = t.join(1, "alice");
|
||||
// the body slot is there because the base game's giant chestplate goes in it
|
||||
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_body_slot" },
|
||||
{ x: -45, y: 25, icon: "bworld:empty_ring_slot" },
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -50,16 +59,16 @@ 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]);
|
||||
assertEquals(last_container(messages, "inventory")[9], { id: "bworld:coal", count: 1 });
|
||||
assertEquals(curios_items(messages), [{ id: "jewelry:amulet", count: 1 }, { id: "jewelry:ring", count: 1 }]);
|
||||
assertEquals(curios_items(messages), [{ id: "jewelry:amulet", count: 1 }, null, { id: "jewelry:ring", count: 1 }]);
|
||||
|
||||
// and they come back out with a shift click, into the inventory
|
||||
t.send(1, { type: "click", menu: 0, slot: PLAYER_MENU_EXTRA + 1, button: 0, shift: true });
|
||||
assertEquals(curios_items(t.take(1))[1], null);
|
||||
t.send(1, { type: "click", menu: 0, slot: PLAYER_MENU_EXTRA + 2, button: 0, shift: true });
|
||||
assertEquals(curios_items(t.take(1))[2], null);
|
||||
t.send(1, { type: "click", menu: 0, slot: 0, button: 0, shift: true });
|
||||
|
||||
const player = t.game.players()[0];
|
||||
@@ -67,5 +76,57 @@ Deno.test("items only go in the slots they fit, and fall out when the player die
|
||||
const dropped = t.game.item_entities().map((e) => e.item.type_id).sort();
|
||||
assertEquals(dropped, ["bworld:coal", "jewelry:amulet", "jewelry:ring"]);
|
||||
t.game.tick();
|
||||
assertEquals(curios_items(t.take(1)), [null, null]);
|
||||
assertEquals(curios_items(t.take(1)), [null, 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(2);
|
||||
assertEquals(ring.container.get_item(ring.index)?.to_data(), { id: "jewelry:ring", count: 1 });
|
||||
assertEquals(loaded.game.mods.storage.curios, undefined);
|
||||
});
|
||||
|
||||
Deno.test("the giant chestplate goes in the body slot and gives 20 more health while worn", async () => {
|
||||
const t = await setup();
|
||||
t.send(1, { type: "chat", text: "/give bworld:giant_chestplate" });
|
||||
const slot = last_container(t.take(1), "inventory").findIndex((i: Msg) => i?.id === "bworld:giant_chestplate");
|
||||
const alice = t.game.players()[0];
|
||||
t.send(1, { type: "click", menu: 0, slot, button: 0, shift: true });
|
||||
// what curios give is worked out each tick, from what changed
|
||||
t.game.tick();
|
||||
assertEquals(curios_items(t.take(1))[1], {
|
||||
id: "bworld:giant_chestplate",
|
||||
count: 1,
|
||||
lore: "When worn:\n+20 Max Health",
|
||||
});
|
||||
assertEquals(alice.max_health, 40);
|
||||
|
||||
// like minecraft, more max health doesn't heal, regenerating fills it
|
||||
assertEquals(alice.health, 20);
|
||||
for (let i = 0; i < 20 * 20; i++) t.game.tick();
|
||||
assert(alice.health > 20, `regenerated to ${alice.health}`);
|
||||
const vitals = t.take(1).findLast((m: Msg) => m.type === "vitals");
|
||||
assertEquals(vitals.max_health, 40);
|
||||
|
||||
// it's kept over rejoining, the chestplate's health comes back before the health is checked against it
|
||||
const health = alice.health;
|
||||
t.game.on_disconnect(1);
|
||||
t.join(1, "alice");
|
||||
assertEquals(t.game.players()[0].health, health);
|
||||
|
||||
// taking it off takes the health over 20 away
|
||||
t.send(1, { type: "click", menu: 0, slot: PLAYER_MENU_EXTRA + 1, button: 0, shift: true });
|
||||
t.game.tick();
|
||||
assertEquals(t.game.players()[0].max_health, 20);
|
||||
assertEquals(t.game.players()[0].health, 20);
|
||||
});
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -28,7 +28,7 @@ Deno.test("the base game loads from mods/bworld", async () => {
|
||||
// 7 kinds of log, planks and leaves
|
||||
assertEquals(bworld(EverythingRegistry.entries("blocks")), 42);
|
||||
// 42 items (25 of them tools) plus the item forms of the 37 blocks that have one
|
||||
assertEquals(bworld(EverythingRegistry.entries("items")), 79);
|
||||
assertEquals(bworld(EverythingRegistry.entries("items")), 80);
|
||||
// bworld's 18 (4 wood tools, the wood watering can, 7 planks, the fishing rod, the smithing table), the cooking pot,
|
||||
// stove, cutting board and wood knife are farmersdelight's
|
||||
assertEquals(game.recipes.shaped.length, 22);
|
||||
|
||||
@@ -384,13 +384,14 @@ Deno.test("menus: filters, data, buttons, closing, saving, and dropping what's i
|
||||
assertEquals(menu_data(loaded.take(1)), undefined, "data is only sent again when it changes");
|
||||
|
||||
// breaking it closes the menu, runs on_close, and drops what was inside
|
||||
const containers = loaded.game.containers.size;
|
||||
loaded.send(1, { type: "break_block", x: 1, y: 100, z: 0 });
|
||||
assert(loaded.take(1).some((m) => m.type === "close_menu"));
|
||||
const logged = loaded.game.mods.storage.testmod.log as Record<string, unknown[]>;
|
||||
assertEquals(logged.closed, [false, false, false]);
|
||||
const dropped = loaded.game.item_entities().map((e) => e.item.to_data().id).sort();
|
||||
assertEquals(dropped, ["bworld:coal", "bworld:stone"]);
|
||||
assertEquals(loaded.game.containers.size, 0);
|
||||
assertEquals(loaded.game.containers.size, containers - 1, "its container is gone");
|
||||
Deno.removeSync(dir, { recursive: true });
|
||||
});
|
||||
|
||||
|
||||
@@ -12,12 +12,12 @@ Deno.test("exhaustion eats saturation first, then hunger", () => {
|
||||
const vitals = new Vitals();
|
||||
const noop = () => {};
|
||||
vitals.add_exhaustion(4.1);
|
||||
vitals.tick(20, noop, noop);
|
||||
vitals.tick(20, 20, noop, noop);
|
||||
assertEquals([vitals.food, vitals.saturation], [20, 4]);
|
||||
|
||||
vitals.saturation = 0;
|
||||
vitals.add_exhaustion(4);
|
||||
vitals.tick(20, noop, noop);
|
||||
vitals.tick(20, 20, noop, noop);
|
||||
assertEquals([vitals.food, vitals.saturation], [19, 0]);
|
||||
});
|
||||
|
||||
@@ -29,7 +29,7 @@ Deno.test("a full stomach heals, fast with saturation and slowly without, and st
|
||||
|
||||
// full hunger and saturation: every 10 ticks, up to a whole heart, paid for with exhaustion
|
||||
const fast = new Vitals();
|
||||
for (let i = 0; i < 10; i++) fast.tick(10, heal, damage);
|
||||
for (let i = 0; i < 10; i++) fast.tick(10, 20, heal, damage);
|
||||
assertAlmostEquals(healed, 5 / 6);
|
||||
assertEquals(fast.exhaustion, 5);
|
||||
|
||||
@@ -38,7 +38,7 @@ Deno.test("a full stomach heals, fast with saturation and slowly without, and st
|
||||
const slow = new Vitals();
|
||||
slow.food = 18;
|
||||
slow.saturation = 0;
|
||||
for (let i = 0; i < 80; i++) slow.tick(10, heal, damage);
|
||||
for (let i = 0; i < 80; i++) slow.tick(10, 20, heal, damage);
|
||||
assertEquals(healed, 1);
|
||||
|
||||
// starving: 1 every 4 seconds, never below 1 health
|
||||
@@ -46,9 +46,9 @@ Deno.test("a full stomach heals, fast with saturation and slowly without, and st
|
||||
starving.food = 0;
|
||||
starving.saturation = 0;
|
||||
let health = 2;
|
||||
for (let i = 0; i < 80; i++) starving.tick(health, heal, (amount) => health -= amount);
|
||||
for (let i = 0; i < 80; i++) starving.tick(health, 20, heal, (amount) => health -= amount);
|
||||
assertEquals(health, 1);
|
||||
for (let i = 0; i < 400; i++) starving.tick(health, heal, (amount) => health -= amount);
|
||||
for (let i = 0; i < 400; i++) starving.tick(health, 20, heal, (amount) => health -= amount);
|
||||
assertEquals(health, 1);
|
||||
assertEquals(hurt, 0);
|
||||
});
|
||||
|
||||