Move effects out of cubi

This commit is contained in:
2026-11-05 22:37:41 -03:00
parent 0e2d8fdcac
commit 9bc8fd992a
17 changed files with 452 additions and 70 deletions
+4 -1
View File
@@ -3,6 +3,9 @@
"effect": {
"id": "bworld:water_breathing",
"category": "beneficial",
"icon": "bworld:water_breathing"
"icon": "bworld:water_breathing",
"components": {
"bworld:refill_air": {}
}
}
}
+3 -1
View File
@@ -103,7 +103,9 @@ export function register_curios(ctx: ServerContext) {
});
ctx.events.after.player_join.subscribe(({ player }) => last_hurt.set(player.id, ctx.system.current_tick));
ctx.events.after.player_damage.subscribe(({ player }) => last_hurt.set(player.id, ctx.system.current_tick));
ctx.events.after.entity_damage.subscribe(({ player }) => {
if (player) last_hurt.set(player.id, ctx.system.current_tick);
});
ctx.events.after.tick.subscribe(() => {
for (const [id, effects] of unhurt_effects) {
const player = ctx.players.get(id);
+14 -2
View File
@@ -1,8 +1,8 @@
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
// SPDX-License-Identifier: AGPL-3.0-or-later
// what the base game's effects do over time, see mods/bworld/effects. speed and slowness are only attribute
// modifiers, and resistance and water breathing work where damage and air happen, like minecraft's
// what the base game's effects do, see mods/bworld/effects. speed and slowness are only attribute modifiers, and
// resistance has no component, it lowers damage as it comes in
import type { ServerContext } from "cubi/server";
// every n ticks, n halving with each level: minecraft's regeneration and poison
@@ -25,6 +25,18 @@ export function register_effects(ctx: ServerContext) {
if (entity.health > 1) entity.damage(1, "magic");
},
});
// effects tick after the entity loses air under water, so it never runs out
ctx.components.register_effect("bworld:refill_air", {
on_tick(entity) {
entity.air = entity.max_air;
},
});
// 20% less damage for each level, unless nothing could stop it, like falling out of the world
ctx.events.before.entity_damage.subscribe((event) => {
const resistance = event.entity.effect("bworld:resistance");
if (!resistance || event.bypasses_invulnerability) return;
event.amount *= Math.max(0, 1 - 0.2 * (resistance.amplifier + 1));
});
// instant: amount for level 1, doubling with each level
ctx.components.register_effect<{ amount: number }>("bworld:heal", {
on_tick(entity, amplifier, params) {