Add season for crops

This commit is contained in:
2026-10-10 14:48:29 -03:00
parent 588655e7df
commit 373d9f83e5
10 changed files with 103 additions and 19 deletions
+5 -1
View File
@@ -49,7 +49,11 @@
"bworld:crop": {
"days": 3,
"stages": 4,
"fertilizer": "bworld:bone_meal"
"fertilizer": "bworld:bone_meal",
"seasons": [
"spring",
"autumn"
]
}
}
}
+5 -1
View File
@@ -49,7 +49,11 @@
"bworld:crop": {
"days": 6,
"stages": 4,
"fertilizer": "bworld:bone_meal"
"fertilizer": "bworld:bone_meal",
"seasons": [
"spring",
"summer"
]
}
}
}
+7 -1
View File
@@ -69,7 +69,13 @@
"bworld:crop": {
"days": 7,
"stages": 8,
"fertilizer": "bworld:bone_meal"
"fertilizer": "bworld:bone_meal",
"seasons": [
"spring",
"summer",
"autumn",
"winter"
]
}
}
}
+17 -1
View File
@@ -1,5 +1,5 @@
// the base game's block and item behavior, written against the same api as any other mod
import type { BlockRef, Container, EntityRef, Player, ServerContext } from "bworld/server";
import type { BlockRef, Container, EntityRef, Player, Season, ServerContext } from "bworld/server";
import type { Position } from "bworld/shared";
import { register_curios } from "./curios.ts";
import { register_effects } from "./effects.ts";
@@ -331,6 +331,7 @@ function register_smithing_table(ctx: ServerContext) {
// it's dug up
const FARMLAND = "bworld:hoed_dirt";
const DEAD_BUSH = "bworld:dead_bush";
// every tier of watering can is a tool of this type, and shares the bworld:watering_can component
const WATERING_CAN = "watering_can";
@@ -359,6 +360,8 @@ interface CropParams {
upper?: { block: string; stages: number; supporting_age: number };
// what the spot becomes when it's broken, like water where rice was
leaves?: string;
// the seasons it grows in. a morning in any other season turns it into a dead bush. every season when not set
seasons?: Season[];
}
// the top of a two block crop. it grows with the crop under it, and breaking it breaks the whole plant
@@ -414,6 +417,15 @@ function register_farming(ctx: ServerContext) {
},
});
// out of season it dies, the top of a two block crop going with it without dropping anything
const die = (block: BlockRef, params: CropParams) => {
const { x, y, z } = block;
if (params.upper && ctx.world.get_block(x, y + 1, z) === params.upper.block) {
ctx.world.set_block(x, y + 1, z, "bworld:air");
}
ctx.world.set_block(x, y, z, DEAD_BUSH);
};
// the stage for how many days it has grown: evenly spread, fully grown on the last day
const stage_for = (params: CropParams, days: number) => {
const stages = params.stages + (params.upper?.stages ?? 0);
@@ -457,6 +469,10 @@ function register_farming(ctx: ServerContext) {
block.data = { days: days_of(block, params) };
},
on_new_day(block, params) {
if (params.seasons && !params.seasons.includes(block.season)) {
die(block, params);
return;
}
const days = days_of(block, params);
if (days >= params.days) return;
const watered = params.water === "always" || is_watered(block.x, block.y - 1, block.z);