Move effects out of cubi
This commit is contained in:
+36
-1
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user