Biome condition for fishes
This commit is contained in:
@@ -10,7 +10,8 @@
|
||||
"components": {
|
||||
"bworld:fish": {
|
||||
"weight": 25,
|
||||
"seasons": ["summer", "autumn", "winter"]
|
||||
"seasons": ["summer", "autumn", "winter"],
|
||||
"biomes": ["#bworld:is_ocean", "#bworld:is_river"]
|
||||
}
|
||||
},
|
||||
"base_sell_value": 32
|
||||
|
||||
@@ -644,7 +644,7 @@ 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 and bworld:time pick fish by where and when it's reeled in
|
||||
// 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;
|
||||
}
|
||||
|
||||
@@ -656,6 +656,8 @@ interface FishParams {
|
||||
seasons?: Season[];
|
||||
// the hours it's caught at, like bworld:time's, all day when not given
|
||||
time?: { from: number; to: number };
|
||||
// the biomes and #biome tags it's caught in, every one when not given
|
||||
biomes?: string[];
|
||||
}
|
||||
|
||||
interface Cast {
|
||||
@@ -735,6 +737,16 @@ function register_fishing(ctx: ServerContext) {
|
||||
return seasons.includes(ctx.world.season_at(context.position.x, context.position.z));
|
||||
});
|
||||
|
||||
// "biomes": ["bworld:swamp", "#bworld:is_ocean"], holds in any of the biomes or biome tags at the loot's
|
||||
// position. without a position it holds, like bworld:season
|
||||
ctx.loot.register_condition("bworld:biome", (params, context) => {
|
||||
if (!context.position) return true;
|
||||
const biome = ctx.world.biome_at(context.position.x, context.position.z);
|
||||
return (params.biomes as string[]).some((entry) =>
|
||||
entry.startsWith("#") ? ctx.tags.has("biomes", entry, biome) : entry === biome
|
||||
);
|
||||
});
|
||||
|
||||
// "from": 20, "to": 4, hours on a 24 hour clock, from inclusive and to exclusive. from past to wraps around
|
||||
// midnight, and fractions are minutes, like 6.5 for 06:30
|
||||
ctx.loot.register_condition("bworld:time", (params) => {
|
||||
@@ -744,7 +756,7 @@ 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
|
||||
// every item with bworld:fish is in the fishing table, caught in its seasons, at its hours and in its biomes
|
||||
ctx.components.register_item<FishParams>(FISH, {});
|
||||
const entries = ctx.items.ids().flatMap((id) => {
|
||||
const fish = ctx.items.components(id)[FISH] as FishParams | undefined;
|
||||
@@ -752,6 +764,7 @@ function register_fishing(ctx: ServerContext) {
|
||||
const conditions = [];
|
||||
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 }];
|
||||
});
|
||||
ctx.loot.register_table(FISHING_TABLE, { pools: entries.length > 0 ? [{ entries }] : [] });
|
||||
|
||||
Reference in New Issue
Block a user