Make the fishing loot table be generated from the fish items

This commit is contained in:
2026-10-11 11:40:44 -03:00
parent 5a59a63862
commit ab2b8e6545
9 changed files with 86 additions and 47 deletions
+6
View File
@@ -7,6 +7,12 @@
"nutrition": 2,
"saturation_modifier": 0.1
},
"components": {
"bworld:fish": {
"weight": 60,
"seasons": ["spring", "summer", "winter"]
}
},
"base_sell_value": 30
}
}
+6
View File
@@ -7,6 +7,12 @@
"nutrition": 2,
"saturation_modifier": 0.1
},
"components": {
"bworld:fish": {
"weight": 25,
"seasons": ["summer", "autumn", "winter"]
}
},
"base_sell_value": 32
}
}
@@ -1,31 +0,0 @@
{
"format_version": 1,
"loot_table": {
"pools": [
{
"entries": [
{
"item": "bworld:cod",
"weight": 60,
"conditions": [
{
"condition": "bworld:season",
"seasons": ["spring", "summer", "winter"]
}
]
},
{
"item": "bworld:salmon",
"weight": 25,
"conditions": [
{
"condition": "bworld:season",
"seasons": ["summer", "autumn", "winter"]
}
]
}
]
}
]
}
}
+25
View File
@@ -619,6 +619,9 @@ function register_buckets(ctx: ServerContext) {
const FISHING_ROD = "bworld:fishing_rod";
const FISHING_HOOK = "bworld:fishing_hook";
const FISHABLE = "bworld:fishable";
const FISH = "bworld:fish";
// built from every item with bworld:fish, see register_fishing
const FISHING_TABLE = "bworld:gameplay/fishing";
// 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
@@ -645,6 +648,16 @@ interface FishingRodParams {
loot_table: string;
}
// an item that's caught by fishing
interface FishParams {
// how often it's caught against the other fish, 1 when not given
weight?: number;
// the seasons it's caught in, every one when not given
seasons?: Season[];
// the hours it's caught at, like bworld:time's, all day when not given
time?: { from: number; to: number };
}
interface Cast {
// the hotbar slot the rod is in, switching away reels it in
slot: number;
@@ -731,6 +744,18 @@ 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 and at its hours
ctx.components.register_item<FishParams>(FISH, {});
const entries = ctx.items.ids().flatMap((id) => {
const fish = ctx.items.components(id)[FISH] as FishParams | undefined;
if (!fish) return [];
const conditions = [];
if (fish.seasons) conditions.push({ condition: "bworld:season", seasons: fish.seasons });
if (fish.time) conditions.push({ condition: "bworld:time", ...fish.time });
return [{ item: id, weight: fish.weight ?? 1, conditions }];
});
ctx.loot.register_table(FISHING_TABLE, { pools: entries.length > 0 ? [{ entries }] : [] });
ctx.components.register_item<FishingRodParams>(FISHING_ROD, {
on_use(rod, params, player) {
const cast = casts.get(player.id);