Biome condition for fishes

This commit is contained in:
2026-10-11 12:16:49 -03:00
parent fa969e0a96
commit e8387392fd
4 changed files with 57 additions and 5 deletions
+35
View File
@@ -3,6 +3,9 @@ import { assert, assertEquals } from "@std/assert";
import { EverythingRegistry, ItemRegistry } from "$/common/everything_registry.ts";
import { ItemStack } from "$/common/inventory.ts";
import { item_texture } from "$/common/utils.ts";
import { tag_api } from "$/common/tags.ts";
import { CYCLE_TICKS } from "$/common/time.ts";
import { biome_season } from "$/common/worldgen/biomes.ts";
import { test_game } from "./helpers.ts";
// deno-lint-ignore no-explicit-any
@@ -141,3 +144,35 @@ Deno.test("a cast rod shows its cast texture", async () => {
assertEquals(item_texture(rod), "bworld:fishing_rod_cast");
assertEquals(EverythingRegistry.get<ItemRegistry>("items", ROD)?.max_stack, 1);
});
Deno.test("a fish with biomes is only caught in them, by id or #tag", async () => {
const t = await test_game("mods");
// summer, when salmon and cod are both caught
while (biome_season("bworld:plains", t.game.world.time) !== "summer") t.game.world.time += CYCLE_TICKS;
const tags = tag_api();
// a column near spawn whose biome matches, in summer or winter
const find = (matches: (biome: string) => boolean) => {
for (let x = -4096; x <= 4096; x += 64) {
for (let z = -4096; z <= 4096; z += 64) {
const biome = t.game.world.biome_at(x, z);
const season = biome_season(biome, t.game.world.time);
if (matches(biome) && (season === "summer" || season === "winter")) return { x, y: 64, z };
}
}
throw new Error("no such biome near spawn");
};
const caught = (position: { x: number; y: number; z: number }) =>
new Set(
Array.from({ length: 200 }, () => t.game.mods.loot.roll("bworld:gameplay/fishing", { position })).flat()
.map((item) => item.id),
);
// salmon's biomes are #bworld:is_ocean and #bworld:is_forest, cod has none
assertEquals(
caught(find((b) => tags.has("biomes", "bworld:is_ocean", b))),
new Set(["bworld:cod", "bworld:salmon"]),
);
assertEquals(
caught(find((b) => !tags.has("biomes", "bworld:is_ocean", b) && !tags.has("biomes", "bworld:is_forest", b))),
new Set(["bworld:cod"]),
);
});