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
+12
View File
@@ -398,6 +398,18 @@ Deno.test("a stonecutter cuts its input into the recipe picked with a button, on
);
});
Deno.test("resistance takes 20% off damage for each level, but not off what nothing could stop", async () => {
const t = await setup();
const alice = t.game.players()[0];
const amounts: number[] = [];
// loaded after bworld, so it sees what resistance left
t.game.mods.before.entity_damage.for_mod("test").subscribe((event) => amounts.push(event.amount));
t.game.mods.player(alice).add_effect("bworld:resistance", 100, { amplifier: 1 });
t.game.damage_player(alice, 10, "fall");
t.game.damage_player(alice, 10, "void");
assertEquals(amounts, [6, 10]);
});
Deno.test("a bucket picks up a water source but not flowing water, and a water bucket puts a source back", async () => {
const t = await setup([["bworld:bucket", 1]]);
const held = () => t.game.players()[0].held_item?.type_id;
+36 -1
View File
@@ -9,6 +9,7 @@ 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";
import { Mob } from "@/server/game/entity/mob.ts";
import { living_ref } from "@/server/game/mod_runtime.ts";
import { test_game } from "./helpers.ts";
// a mob for testing, walking like a pig
@@ -256,7 +257,7 @@ Deno.test("mobs hurt players like anything else, and mods still get a say", asyn
const { game, spawn, ticks } = await floor_game();
const alice = game.players()[0];
const causes: string[] = [];
game.mods.before.player_damage.for_mod("test").subscribe((event) => causes.push(event.cause));
game.mods.before.entity_damage.for_mod("test").subscribe((event) => causes.push(event.cause));
const mob = spawn(0.5, 100, 1.5);
ticks(1);
@@ -329,6 +330,40 @@ Deno.test("mobs drown after their air runs out, unless they breathe water", asyn
assertEquals(breather.health, 10);
});
Deno.test("mods get a say in damage to mobs too", async () => {
const { game, spawn, ticks } = await floor_game();
const mob = spawn(0.5, 100, 2.5);
ticks(1);
const seen: { entity: string; player: unknown; cause: string; amount: number }[] = [];
game.mods.before.entity_damage.for_mod("test").subscribe((event) => {
if (event.entity.id === mob.id) event.amount /= 2;
});
game.mods.after.entity_damage.for_mod("test").subscribe(({ entity, player, cause, amount }) =>
seen.push({ entity: entity.id, player, cause, amount })
);
assert(mob.hurt(4, DAMAGE.generic));
assertEquals(mob.health, 10 - 2);
assertEquals(seen, [{ entity: mob.id, player: undefined, cause: "generic", amount: 2 }]);
});
Deno.test("scripts can set a mob's air, up to its most", async () => {
const { game, spawn, ticks } = await floor_game();
for (let y = 100; y <= 102; y++) game.set_block(3, y, 3, "bworld:water");
for (const [x, z] of [[2, 3], [4, 3], [3, 2], [3, 4]]) {
for (let y = 100; y <= 102; y++) game.set_block(x, y, z, "bworld:stone");
}
const mob = spawn(3.5, 100, 3.5);
mob.no_ai = true;
const ref = living_ref(mob);
ref.air = ref.max_air * 10;
assertEquals(mob.air, mob.max_air);
game.mods.after.tick.for_mod("test").subscribe(() => ref.air = ref.max_air);
ticks(400);
assert(mob.eyes_in_water);
assertEquals(mob.health, 10);
});
Deno.test("the move control walks a mob to where it's told at minecraft's speed", async () => {
const { spawn, ticks } = await floor_game();
const mob = spawn(0.5, 100, -5.5);
+1 -1
View File
@@ -186,7 +186,7 @@ Deno.test("dying takes 1 durability off every tool carried, and ones that run ou
Deno.test("mods can stop or change damage, and hurt, heal and feed players", async () => {
const t = await setup();
t.game.mods.before.player_damage.for_mod("test").subscribe((event) => {
t.game.mods.before.entity_damage.for_mod("test").subscribe((event) => {
if (event.cause === "fall") event.cancel = true;
if (event.cause === "poison") event.amount = 1;
});