Curios and artifacts !
@@ -0,0 +1,28 @@
|
||||
# Artifacts
|
||||
|
||||
A bworld port of [Artifacts](https://github.com/ochotonida/artifacts) by ochotonida. Its textures and game design come
|
||||
from the original, version 15.1.3 for NeoForge 26.1.2, under the MIT license:
|
||||
|
||||
```
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 Wouter Pauwels
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
```
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"item": {
|
||||
"id": "artifacts:feral_claws",
|
||||
"texture": "artifacts:feral_claws",
|
||||
"max_stack": 1,
|
||||
"components": {
|
||||
"curios:attribute_modifiers": [
|
||||
{ "attribute": "bworld:attack_speed", "amount": 0.3, "operation": "add_multiplied_base" }
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"item": {
|
||||
"id": "artifacts:power_glove",
|
||||
"texture": "artifacts:power_glove",
|
||||
"max_stack": 1,
|
||||
"components": {
|
||||
"curios:attribute_modifiers": [
|
||||
{ "attribute": "bworld:attack_damage", "amount": 4, "operation": "add_value" }
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"id": "artifacts",
|
||||
"name": "Artifacts",
|
||||
"description": "A port of ochotonida's Artifacts: wearable items worn in Curios slots.",
|
||||
"version": "0.1.0",
|
||||
"authors": [
|
||||
"ochotonida (original)",
|
||||
"paula (port)"
|
||||
],
|
||||
"game_version": ">=0.1.0",
|
||||
"dependencies": [
|
||||
{
|
||||
"id": "bworld",
|
||||
"version": "*"
|
||||
},
|
||||
{
|
||||
"id": "curios",
|
||||
"version": "*"
|
||||
}
|
||||
],
|
||||
"credits": "CREDITS.md"
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"tag": {
|
||||
"values": ["artifacts:power_glove", "artifacts:feral_claws"]
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 220 B |
|
After Width: | Height: | Size: 1.5 KiB |
@@ -0,0 +1,21 @@
|
||||
# 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/>.
|
||||
```
|
||||
@@ -0,0 +1,45 @@
|
||||
# Curios
|
||||
|
||||
A port of [Curios](https://github.com/TheIllusiveC4/Curios): accessory slots, like rings, necklaces and belts, for any
|
||||
mod's items. Players open them with the Curios button next to their inventory, or G while an inventory is open.
|
||||
|
||||
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.
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"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",
|
||||
"client": "scripts/client.ts"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// the curios button next to every inventory screen, or G like curios' keybind, asks the server to show the slots
|
||||
import type { ClientContext } from "bworld/client";
|
||||
import { active_slots } from "./slots.ts";
|
||||
|
||||
const GAP = 16;
|
||||
const WIDTH = 120;
|
||||
const HEIGHT = 32;
|
||||
|
||||
export function setup(ctx: ClientContext) {
|
||||
// no item goes in any slot, so there's nothing to show
|
||||
if (active_slots(ctx.tags).length === 0) return;
|
||||
|
||||
ctx.ui.add_inventory_overlay({
|
||||
on_render(g, screen) {
|
||||
const clicked = g.button("Curios", screen.x - WIDTH - GAP, screen.y, WIDTH, HEIGHT);
|
||||
if (clicked || g.key_pressed("KeyG")) {
|
||||
ctx.net.send("curios:open", {});
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
// curios: accessory slots, shown with the player's inventory from the curios button. 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:attribute_modifiers' params, a list of these
|
||||
interface WornModifier {
|
||||
attribute: string;
|
||||
amount: number;
|
||||
operation: AttributeModifier["operation"];
|
||||
}
|
||||
|
||||
export function setup(ctx: ServerContext) {
|
||||
const active = active_slots(ctx.tags);
|
||||
|
||||
ctx.components.register_item<WornModifier[]>("curios:attribute_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[];
|
||||
|
||||
// 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 }[]>();
|
||||
const stop_watching = new Map<string, () => void>();
|
||||
|
||||
// by player name, like the players themselves are saved. undefined until they first open curios
|
||||
function saved_curios(player: Player): Container | undefined {
|
||||
const id = ctx.storage.get<Record<string, string>>("containers")?.[player.name];
|
||||
return id ? ctx.containers.get(id) : undefined;
|
||||
}
|
||||
|
||||
function curios_of(player: Player): Container {
|
||||
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);
|
||||
return container;
|
||||
}
|
||||
|
||||
// keeps what their curios give them up to date
|
||||
function watch(player: Player, curios: Container) {
|
||||
stop_watching.get(player.id)?.();
|
||||
stop_watching.set(player.id, curios.on_change(() => update_modifiers(player, curios)));
|
||||
update_modifiers(player, curios);
|
||||
}
|
||||
|
||||
function update_modifiers(player: Player, curios: Container) {
|
||||
for (const { attribute, id } of applied.get(player.id) ?? []) player.remove_modifier(attribute, id);
|
||||
const now: { attribute: string; id: string }[] = [];
|
||||
for (const [index, slot] of SLOTS.entries()) {
|
||||
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}`;
|
||||
player.add_modifier(attribute, { id, amount, operation });
|
||||
now.push({ attribute, id });
|
||||
}
|
||||
}
|
||||
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);
|
||||
});
|
||||
|
||||
ctx.net.on("curios:open", (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
|
||||
for (const [index, slot] of SLOTS.entries()) {
|
||||
const item = curios.get(index);
|
||||
if (item && !active.includes(slot)) {
|
||||
player.give_item(item.id, item.count, item.data);
|
||||
curios.set(index, undefined);
|
||||
}
|
||||
}
|
||||
// in rows of 9, each row centered
|
||||
ctx.ui.open_container(player, {
|
||||
container: curios,
|
||||
layout: active.map((slot, i) => {
|
||||
const row = Math.floor(i / 9);
|
||||
const in_row = Math.min(9, active.length - row * 9);
|
||||
return {
|
||||
slot: SLOTS.indexOf(slot),
|
||||
x: (9 - in_row) / 2 + (i % 9),
|
||||
y: row,
|
||||
filter: (item) => fits(ctx.tags, slot, item.id),
|
||||
icon: `curios:empty_${slot}_slot`,
|
||||
};
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
ctx.events.after.player_death.subscribe(({ player }) => {
|
||||
const curios = saved_curios(player);
|
||||
if (!curios) return;
|
||||
const { x, y, z } = player.position;
|
||||
for (let i = 0; i < curios.size; i++) {
|
||||
const item = curios.get(i);
|
||||
if (!item) continue;
|
||||
const { id, count, data } = item;
|
||||
curios.set(i, undefined);
|
||||
ctx.world.drop_item(Math.floor(x), Math.floor(Math.max(y, 0)), Math.floor(z), { id, count, data });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// like minecraft's attribute tooltips: "+4 Attack Damage", "+30% Attack Speed"
|
||||
function describe({ attribute, amount, operation }: WornModifier): string {
|
||||
const name = attribute.split(":").at(-1)!.split("_").map((word) => word[0].toUpperCase() + word.slice(1)).join(" ");
|
||||
const sign = amount < 0 ? "-" : "+";
|
||||
const value = operation === "add_value" ? `${Math.abs(amount)}` : `${Math.round(Math.abs(amount) * 100)}%`;
|
||||
return `${sign}${value} ${name}`;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// curios' slot types, both scripts share them
|
||||
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);
|
||||
}
|
||||
|
After Width: | Height: | Size: 145 B |
|
After Width: | Height: | Size: 144 B |
|
After Width: | Height: | Size: 152 B |
|
After Width: | Height: | Size: 157 B |
|
After Width: | Height: | Size: 139 B |
|
After Width: | Height: | Size: 140 B |
|
After Width: | Height: | Size: 149 B |
|
After Width: | Height: | Size: 158 B |
|
After Width: | Height: | Size: 157 B |
|
After Width: | Height: | Size: 152 B |
|
After Width: | Height: | Size: 144 B |