Grubs for seashrooms

This commit is contained in:
2026-10-12 02:32:54 -03:00
parent df26248f4a
commit 726a52b91a
6 changed files with 73 additions and 12 deletions
@@ -0,0 +1,27 @@
{
"format_version": 1,
"loot_table": {
"pools": [
{
"entries": [
{ "item": "bworld:white_seashroom" },
{ "item": "bworld:light_gray_seashroom" },
{ "item": "bworld:gray_seashroom" },
{ "item": "bworld:black_seashroom" },
{ "item": "bworld:brown_seashroom" },
{ "item": "bworld:red_seashroom" },
{ "item": "bworld:orange_seashroom" },
{ "item": "bworld:yellow_seashroom" },
{ "item": "bworld:lime_seashroom" },
{ "item": "bworld:green_seashroom" },
{ "item": "bworld:cyan_seashroom" },
{ "item": "bworld:light_blue_seashroom" },
{ "item": "bworld:blue_seashroom" },
{ "item": "bworld:purple_seashroom" },
{ "item": "bworld:magenta_seashroom" },
{ "item": "bworld:pink_seashroom" }
]
}
]
}
}
@@ -0,0 +1,14 @@
{
"format_version": 1,
"loot_table": {
"pools": [
{
"entries": [
{ "item": "bworld:crayfish" },
{ "item": "bworld:chorus_snail" },
{ "item": "bworld:leech" }
]
}
]
}
}
+9 -8
View File
@@ -269,12 +269,13 @@ const ADDITION = 2;
const RESULT = 3;
// the crab pot's menu: its bait slot at the top, and a row of 9 slots under it for what it catches, which players can
// only take from. every morning a crab pot in water with worms in it uses one up to catch something: from the
// saltwater table in an ocean, the freshwater one anywhere else. a catch that doesn't fit is let go, and keeps the
// worm
// only take from. every morning a crab pot in water with bait in it uses one up to catch something: from the bait's
// saltwater table in an ocean, its freshwater one anywhere else. a catch that doesn't fit is let go, and keeps the
// bait
const CRABPOT_BAIT = 0;
const CRABPOT_OUTPUT = 9;
const CRABPOT_WORMS = "bworld:worms";
// each bait's loot tables, bworld:gameplay/crabpot_<name>_saltwater and _freshwater
const CRABPOT_BAITS: Record<string, string> = { "bworld:worms": "worms", "bworld:grubs": "grubs" };
function register_crabpot(ctx: ServerContext) {
const menu_type = ctx.menus.register<BlockRef>("bworld:crabpot", (menu, block) => {
@@ -304,13 +305,13 @@ function register_crabpot(ctx: ServerContext) {
// one that's never been opened has nothing in it
const container = block.data?.container && ctx.containers.get(block.data.container);
const bait = container && container.get(CRABPOT_BAIT);
if (!bait || bait.id !== CRABPOT_WORMS) {
const bait_name = bait && CRABPOT_BAITS[bait.id];
if (!bait || !bait_name) {
return;
}
const table = ctx.tags.has("biomes", "bworld:is_ocean", block.biome)
? "bworld:gameplay/crabpot_saltwater"
: "bworld:gameplay/crabpot_freshwater";
const water = ctx.tags.has("biomes", "bworld:is_ocean", block.biome) ? "saltwater" : "freshwater";
const table = `bworld:gameplay/crabpot_${bait_name}_${water}`;
const position = { x: x + 0.5, y: y + 0.5, z: z + 0.5 };
for (const item of ctx.loot.roll(table, { position })) {
// onto a stack of it with room, or into an empty output slot
+23 -4
View File
@@ -77,7 +77,7 @@ Deno.test("right clicking a crab pot opens its menu: a bait slot on top and 9 ou
assert(opened.slots.slice(1, 10).every((s: { output?: boolean }) => s.output));
});
Deno.test("crab pots have a freshwater and a saltwater loot table, one catch a roll", async () => {
Deno.test("crab pots have a freshwater and a saltwater loot table for each bait, one catch a roll", async () => {
const { game } = await test_game("mods");
const catches = (table: string) => {
const items = new Set<string>();
@@ -88,12 +88,12 @@ Deno.test("crab pots have a freshwater and a saltwater loot table, one catch a r
}
return [...items].sort();
};
assertEquals(catches("bworld:gameplay/crabpot_freshwater"), [
assertEquals(catches("bworld:gameplay/crabpot_worms_freshwater"), [
"bworld:chorus_snail",
"bworld:crayfish",
"bworld:leech",
]);
assertEquals(catches("bworld:gameplay/crabpot_saltwater"), [
assertEquals(catches("bworld:gameplay/crabpot_worms_saltwater"), [
"bworld:clam",
"bworld:cold_ocean_hermit_crab",
"bworld:crab",
@@ -104,9 +104,19 @@ Deno.test("crab pots have a freshwater and a saltwater loot table, one catch a r
"bworld:shrimp",
"bworld:warm_ocean_hermit_crab",
]);
assertEquals(catches("bworld:gameplay/crabpot_grubs_freshwater"), [
"bworld:chorus_snail",
"bworld:crayfish",
"bworld:leech",
]);
assertEquals(catches("bworld:gameplay/crabpot_grubs_saltwater"), SEASHROOMS.toSorted());
});
Deno.test("every morning a crab pot in water uses a worm to catch something, from its water's table", async () => {
const SEASHROOMS = ["white", "light_gray", "gray", "black", "brown", "red", "orange", "yellow", "lime", "green"]
.concat(["cyan", "light_blue", "blue", "purple", "magenta", "pink"])
.map((color) => `bworld:${color}_seashroom`);
Deno.test("every morning a crab pot in water uses its bait to catch something, from its bait and water's table", async () => {
const t = await test_game("mods");
t.join(1, "alice");
const tags = tag_api();
@@ -153,6 +163,9 @@ Deno.test("every morning a crab pot in water uses a worm to catch something, fro
const [dry_x, dry_z] = column(false);
const dry = pot([dry_x + 3, dry_z], false, new ItemStack("bworld:worms", 1));
const unbaited = pot([dry_x + 6, dry_z], true, new ItemStack("bworld:dirt", 1));
const [ocean_x, ocean_z] = column(true);
const grubs_ocean = pot([ocean_x + 3, ocean_z], true, new ItemStack("bworld:grubs", 1));
const grubs_river = pot([dry_x + 9, dry_z], true, new ItemStack("bworld:grubs", 1));
next_morning();
assertEquals(caught(ocean).length, 1);
@@ -165,6 +178,12 @@ Deno.test("every morning a crab pot in water uses a worm to catch something, fro
// not in water, or without worms, nothing
assertEquals([caught(dry), dry.get_item(0)?.amount], [[], 1]);
assertEquals([caught(unbaited), unbaited.get_item(0)?.type_id], [[], "bworld:dirt"]);
// grubs catch from their own tables, seashrooms in the ocean
assertEquals(caught(grubs_ocean).length, 1);
assert(SEASHROOMS.includes(caught(grubs_ocean)[0]), caught(grubs_ocean)[0]);
assertEquals(grubs_ocean.get_item(0), undefined);
assertEquals(caught(grubs_river).length, 1);
assert(freshwater.includes(caught(grubs_river)[0]), caught(grubs_river)[0]);
// with no room for the catch it's let go, and the worm kept
for (let slot = 1; slot <= 9; slot++) ocean.set_item(slot, new ItemStack("bworld:stone", 64));