Proper season and time conditions for fishing

This commit is contained in:
2026-10-08 15:49:46 -03:00
parent 9c5a15542a
commit aa0d2f73d0
11 changed files with 86 additions and 76 deletions
+2 -1
View File
@@ -17,7 +17,8 @@
"bite": [
20,
40
]
],
"loot_table": "bworld:gameplay/fishing"
}
}
}
@@ -0,0 +1,31 @@
{
"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"]
}
]
}
]
}
]
}
}
@@ -1,15 +0,0 @@
{
"format_version": 1,
"loot_table": {
"pools": [
{
"entries": [
{
"item": "bworld:salmon",
"weight": 60
}
]
}
]
}
}
@@ -1,15 +0,0 @@
{
"format_version": 1,
"loot_table": {
"pools": [
{
"entries": [
{
"item": "bworld:cod",
"weight": 60
}
]
}
]
}
}
@@ -1,19 +0,0 @@
{
"format_version": 1,
"loot_table": {
"pools": [
{
"entries": [
{
"item": "bworld:cod",
"weight": 60
},
{
"item": "bworld:salmon",
"weight": 25
}
]
}
]
}
}
@@ -1,19 +0,0 @@
{
"format_version": 1,
"loot_table": {
"pools": [
{
"entries": [
{
"item": "bworld:cod",
"weight": 60
},
{
"item": "bworld:salmon",
"weight": 25
}
]
}
]
}
}
+20 -6
View File
@@ -628,6 +628,8 @@ 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
loot_table: string;
}
interface Cast {
@@ -699,17 +701,29 @@ function register_fishing(ctx: ServerContext) {
// fishable blocks are found by their components, see is_fishable
ctx.components.register_block(FISHABLE, {});
// "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
ctx.loot.register_condition("bworld:season", (params, context) => {
const seasons = params.seasons as string[];
if (!context.position) return true;
return seasons.includes(ctx.world.season_at(context.position.x, context.position.z));
});
// "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) => {
const from = params.from as number;
const to = params.to as number;
const hour = ctx.world.hour;
return from <= to ? hour >= from && hour < to : hour >= from || hour < to;
});
ctx.components.register_item<FishingRodParams>(FISHING_ROD, {
on_use(rod, params, player) {
const cast = casts.get(player.id);
if (cast) {
if (cast.escape_at !== undefined) {
const season = ctx.world.season_at(
cast.hook.position.x,
cast.hook.position.z,
);
const loot_table = `bworld:gameplay/fishing_${season}`;
const loot = ctx.loot.roll(loot_table, { position: cast.position, player, tool: rod });
const loot = ctx.loot.roll(params.loot_table, { position: cast.position, player, tool: rod });
for (const item of loot) player.give_item(item.id, item.count, item.data);
}
stop(player, player.id);