Lava fishing

This commit is contained in:
2026-10-11 19:12:38 -03:00
parent 870235442b
commit 67e8fe5c00
13 changed files with 167 additions and 40 deletions
+3
View File
@@ -10,6 +10,9 @@
"components": {
"bworld:bucketable": {
"into": "bworld:lava_bucket"
},
"bworld:fishable": {
"loot_table": "bworld:gameplay/lava_fishing"
}
}
}
+1 -2
View File
@@ -17,8 +17,7 @@
"bite": [
20,
40
],
"loot_table": "bworld:gameplay/fishing"
]
}
}
}
+9 -1
View File
@@ -7,6 +7,14 @@
"nutrition": 2,
"saturation_modifier": 0.1
},
"base_sell_value": 1
"components": {
"bworld:fish": {
"liquid": "bworld:lava",
"weight": 2,
"minigame": "valley",
"difficulty": 90
}
},
"base_sell_value": 710
}
}
+9 -1
View File
@@ -7,6 +7,14 @@
"nutrition": 2,
"saturation_modifier": 0.1
},
"base_sell_value": 1
"components": {
"bworld:fish": {
"liquid": "bworld:lava",
"weight": 8,
"minigame": "ring",
"difficulty": 61
}
},
"base_sell_value": 85
}
}
+9 -1
View File
@@ -7,6 +7,14 @@
"nutrition": 2,
"saturation_modifier": 0.1
},
"base_sell_value": 1
"components": {
"bworld:fish": {
"liquid": "bworld:lava",
"weight": 10,
"minigame": "valley",
"difficulty": 50
}
},
"base_sell_value": 72
}
}
+9 -1
View File
@@ -7,6 +7,14 @@
"nutrition": 2,
"saturation_modifier": 0.1
},
"base_sell_value": 1
"components": {
"bworld:fish": {
"liquid": "bworld:lava",
"weight": 1,
"minigame": "maze",
"difficulty": 110
}
},
"base_sell_value": 3500
}
}
+9 -1
View File
@@ -7,6 +7,14 @@
"nutrition": 2,
"saturation_modifier": 0.1
},
"base_sell_value": 1
"components": {
"bworld:fish": {
"liquid": "bworld:lava",
"weight": 4,
"minigame": "ring",
"difficulty": 81
}
},
"base_sell_value": 350
}
}
+9 -1
View File
@@ -7,6 +7,14 @@
"nutrition": 2,
"saturation_modifier": 0.1
},
"base_sell_value": 1
"components": {
"bworld:fish": {
"liquid": "bworld:lava",
"weight": 0.1,
"minigame": "hold",
"difficulty": 50
}
},
"base_sell_value": 2750
}
}
+9 -1
View File
@@ -7,6 +7,14 @@
"nutrition": 2,
"saturation_modifier": 0.1
},
"base_sell_value": 1
"components": {
"bworld:fish": {
"liquid": "bworld:lava",
"weight": 10,
"minigame": "chess",
"difficulty": 70
}
},
"base_sell_value": 190
}
}
+38 -8
View File
@@ -11,8 +11,11 @@ const FISHABLE = "bworld:fishable";
const FISH = "bworld:fish";
// the menu a fish's minigame is played in. client.ts gives it the minigame's screen, see minigames/mod.ts
const MINIGAME_MENU = "bworld:fishing_minigame";
// built from every item with bworld:fish, see register_fishing
// what's caught in a fishable block whose bworld:fishable doesn't name a table, like water. each table is built from
// the items with bworld:fish that live in its liquid, see register_fishing
const FISHING_TABLE = "bworld:gameplay/fishing";
// the liquid a fish lives in when it doesn't say
const WATER = "bworld:water";
// further than this from the hook, the line snaps
const LINE_LENGTH = 16;
// blocks per tick it's thrown at, and how it falls and slows down in the air each tick, like minecraft's hook
@@ -35,8 +38,13 @@ interface FishingRodParams {
wait: [number, number];
// ticks it stays on the hook before it gets away
bite: [number, number];
// what's caught, a loot table. bworld:season, bworld:time and bworld:biome pick fish by where and when it's reeled in
loot_table: string;
}
// a block the hook floats on, like water and lava
interface FishableParams {
// what's caught in it, FISHING_TABLE when not given. bworld:season, bworld:time and bworld:biome pick fish by where
// and when it's reeled in
loot_table?: string;
}
// an item that's caught by fishing
@@ -53,6 +61,8 @@ interface FishParams {
minigame?: string;
// how hard its minigame is, 10 when not given. what it changes is up to the minigame
difficulty?: number;
// the fishable block it's caught in, bworld:water when not given. it's in that block's loot table
liquid?: string;
}
interface Cast {
@@ -122,7 +132,10 @@ export function register_fishing(ctx: ServerContext) {
};
// fishable blocks are found by their components, see is_fishable
ctx.components.register_block(FISHABLE, {});
ctx.components.register_block<FishableParams>(FISHABLE, {});
// what's caught in a fishable block
const table_of = (block: string) =>
(ctx.blocks.components(block)[FISHABLE] as FishableParams | undefined)?.loot_table ?? FISHING_TABLE;
// "seasons": ["summer", "autumn"], holds in any of them, at the loot's position. without a position, like a
// table rolled from a command, it holds
@@ -151,8 +164,12 @@ export function register_fishing(ctx: ServerContext) {
return from <= to ? hour >= from && hour < to : hour >= from || hour < to;
});
// every item with bworld:fish is in the fishing table, caught in its seasons, at its hours and in its biomes
// every item with bworld:fish is in its liquid's fishing table, caught in its seasons, at its hours and in its
// biomes
ctx.components.register_item<FishParams>(FISH, {});
const tables = new Map<string, { item: string; weight: number; conditions: { condition: string }[] }[]>([
[FISHING_TABLE, []],
]);
const entries = ctx.items.ids().flatMap((id) => {
const fish = ctx.items.components(id)[FISH] as FishParams | undefined;
if (!fish) return [];
@@ -166,9 +183,18 @@ export function register_fishing(ctx: ServerContext) {
if (fish.seasons) conditions.push({ condition: "bworld:season", seasons: fish.seasons });
if (fish.time) conditions.push({ condition: "bworld:time", ...fish.time });
if (fish.biomes) conditions.push({ condition: "bworld:biome", biomes: fish.biomes });
return [{ item: id, weight: fish.weight ?? 1, conditions }];
const liquid = fish.liquid ?? WATER;
if (!ctx.blocks.exists(liquid) || !(FISHABLE in ctx.blocks.components(liquid))) {
throw new Error(`${id} is caught in ${liquid}, which isn't a block with ${FISHABLE}`);
}
const entry = { item: id, weight: fish.weight ?? 1, conditions };
const table = table_of(liquid);
tables.set(table, [...tables.get(table) ?? [], entry]);
return [entry];
});
ctx.loot.register_table(FISHING_TABLE, { pools: entries.length > 0 ? [{ entries }] : [] });
for (const [table, entries] of tables) {
ctx.loot.register_table(table, { pools: entries.length > 0 ? [{ entries }] : [] });
}
// holds the fish until its minigame is won, and closes then. closing it before lets the fish get away
const minigame_menu = ctx.menus.register<{ minigame: string; fish: ItemStack; difficulty: number }>(
@@ -226,7 +252,11 @@ export function register_fishing(ctx: ServerContext) {
const cast = casts.get(player.id);
if (cast) {
if (cast.escape_at !== undefined) {
const loot = ctx.loot.roll(params.loot_table, { position: cast.position, player, tool: rod });
// a table no fish lives in isn't made, and nothing's caught there
const table = table_of(cast.water!.block);
const loot = ctx.loot.exists(table)
? ctx.loot.roll(table, { position: cast.position, player, tool: rod })
: [];
for (const item of loot) land(player, item);
}
stop(player, player.id);