Move effects into the modding api

This commit is contained in:
2026-10-02 11:53:44 -03:00
parent 4309c700d2
commit e5dcb97643
33 changed files with 458 additions and 109 deletions
+1
View File
@@ -249,6 +249,7 @@ Deno.test("a mod with only data packs and reads", () => {
spawns: [],
entities: [],
entity_models: [],
effects: [],
tags: [],
},
scripts: {},
+1 -2
View File
@@ -4,7 +4,6 @@ import { assert, assertEquals } from "@std/assert";
import { PLAYER_MENU_EXTRA, PROTOCOL_VERSION } from "$/common/protocol.ts";
import { copy_dir, test_game } from "./helpers.ts";
import type { WorldSave } from "$/server/game/saves.ts";
import { EFFECTS } from "$/server/game/entity/effects.ts";
// deno-lint-ignore no-explicit-any
type Msg = any;
@@ -163,7 +162,7 @@ Deno.test("the giant chestplate gives regeneration III after 10 seconds without
const alice = t.game.players()[0];
t.send(1, { type: "click", menu: 0, slot, button: 0, shift: true });
t.game.damage_player(alice, 2, "test");
const regeneration = () => alice.get_effect(EFFECTS.regeneration);
const regeneration = () => alice.get_effect("bworld:regeneration");
for (let i = 0; i < 199; i++) t.game.tick();
assertEquals(regeneration(), undefined);
+12 -12
View File
@@ -1,7 +1,7 @@
import { assert, assertAlmostEquals, assertEquals } from "@std/assert";
import { ItemStack } from "$/common/inventory.ts";
import { Attribute, ATTRIBUTES } from "$/server/game/entity/attributes.ts";
import { EffectInstance, EFFECTS } from "$/server/game/entity/effects.ts";
import { effect_type, EffectInstance } from "$/server/game/entity/effects.ts";
import { DAMAGE } from "$/server/game/entity/entity.ts";
import { register_entity_type } from "$/server/game/entity/entity_types.ts";
import { Goal, GoalSelector, RandomStrollGoal } from "$/server/game/entity/goals.ts";
@@ -73,9 +73,9 @@ Deno.test("a stronger, shorter effect hides a weaker one, which takes over when
const mob = spawn(0.5, 100, 0.5);
const base_speed = mob.attribute(ATTRIBUTES.movement_speed);
mob.add_effect(new EffectInstance(EFFECTS.speed, 100));
mob.add_effect(new EffectInstance(EFFECTS.speed, 10, { amplifier: 2 }));
const effect = mob.get_effect(EFFECTS.speed)!;
mob.add_effect(new EffectInstance(effect_type("bworld:speed")!, 100));
mob.add_effect(new EffectInstance(effect_type("bworld:speed")!, 10, { amplifier: 2 }));
const effect = mob.get_effect("bworld:speed")!;
assertEquals([effect.amplifier, effect.duration, effect.hidden?.amplifier], [2, 10, 0]);
assertAlmostEquals(mob.attribute(ATTRIBUTES.movement_speed), base_speed * 1.6);
@@ -84,7 +84,7 @@ Deno.test("a stronger, shorter effect hides a weaker one, which takes over when
assertAlmostEquals(mob.attribute(ATTRIBUTES.movement_speed), base_speed * 1.2);
for (let i = 0; i < 90; i++) mob.tick_effects();
assertEquals(mob.has_effect(EFFECTS.speed), false);
assertEquals(mob.has_effect("bworld:speed"), false);
assertEquals(mob.attribute(ATTRIBUTES.movement_speed), base_speed);
});
@@ -93,16 +93,16 @@ Deno.test("effects: regeneration heals and poison never kills", async () => {
const mob = spawn(0.5, 100, 0.5);
mob.health = 2;
mob.add_effect(new EffectInstance(EFFECTS.poison, 200, { amplifier: 3 }));
mob.add_effect(new EffectInstance(effect_type("bworld:poison")!, 200, { amplifier: 3 }));
for (let i = 0; i < 200; i++) mob.tick_effects();
assertEquals(mob.health, 1);
mob.add_effect(new EffectInstance(EFFECTS.regeneration, 100, { amplifier: 1 }));
mob.add_effect(new EffectInstance(effect_type("bworld:regeneration")!, 100, { amplifier: 1 }));
for (let i = 0; i < 100; i++) mob.tick_effects();
// every 25 ticks at level 2
assertEquals(mob.health, 5);
mob.add_effect(new EffectInstance(EFFECTS.instant_health, 1));
mob.add_effect(new EffectInstance(effect_type("bworld:instant_health")!, 1));
assertEquals(mob.health, 9);
});
@@ -321,7 +321,7 @@ Deno.test("mobs drown after their air runs out, unless they breathe water", asyn
const breather = spawn(3.5, 100, 3.5);
breather.no_ai = true;
breather.add_effect(new EffectInstance(EFFECTS.water_breathing, -1));
breather.add_effect(new EffectInstance(effect_type("bworld:water_breathing")!, -1));
ticks(340);
assertEquals(breather.health, 10);
});
@@ -448,8 +448,8 @@ Deno.test("entities are saved with everything about them, riders on what they ri
mob.add_tag("test");
mob.data.mood = "happy";
mob.health = 6;
mob.add_effect(new EffectInstance(EFFECTS.speed, 100));
mob.add_effect(new EffectInstance(EFFECTS.speed, 10, { amplifier: 1 }));
mob.add_effect(new EffectInstance(effect_type("bworld:speed")!, 100));
mob.add_effect(new EffectInstance(effect_type("bworld:speed")!, 10, { amplifier: 1 }));
mob.attributes.get(ATTRIBUTES.physical_shielding)!.base = 4;
mob.set_item_slot("mainhand", new ItemStack("bworld:stick"));
mob.restrict_to(1, 2, 3, 8);
@@ -471,7 +471,7 @@ Deno.test("entities are saved with everything about them, riders on what they ri
assertEquals([...horse.tags], ["test"]);
assertEquals(horse.data, { mood: "happy" });
assertEquals(horse.health, 6);
const speed = horse.get_effect(EFFECTS.speed)!;
const speed = horse.get_effect("bworld:speed")!;
assertEquals([speed.amplifier, speed.duration, speed.hidden?.amplifier, speed.hidden?.duration], [1, 9, 0, 99]);
assertAlmostEquals(horse.attribute(ATTRIBUTES.movement_speed), 0.25 * 1.4);
assertEquals(horse.attribute(ATTRIBUTES.physical_shielding), 4);
+1
View File
@@ -35,6 +35,7 @@ export function mod_sources(mods_dir: string): ServerModSource[] {
spawns: mod.spawns.map((s) => s.json),
entities: mod.entities.map((e) => e.json),
entity_models: mod.entity_models.map((m) => m.json),
effects: mod.effects.map((e) => e.json),
tags: mod.tags.map((t) => t.json),
},
server_url: url(scripts.server),
+1
View File
@@ -205,6 +205,7 @@ Deno.test("tags survive packing into a .bmod", () => {
spawns: [],
entities: [],
entity_models: [],
effects: [],
tags: [tag],
};
const manifest = { format_version: 1, id: "x", name: "X", version: "1.0.0" };