Add season for crops
This commit is contained in:
@@ -49,7 +49,11 @@
|
||||
"bworld:crop": {
|
||||
"days": 3,
|
||||
"stages": 4,
|
||||
"fertilizer": "bworld:bone_meal"
|
||||
"fertilizer": "bworld:bone_meal",
|
||||
"seasons": [
|
||||
"spring",
|
||||
"autumn"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,11 @@
|
||||
"bworld:crop": {
|
||||
"days": 6,
|
||||
"stages": 4,
|
||||
"fertilizer": "bworld:bone_meal"
|
||||
"fertilizer": "bworld:bone_meal",
|
||||
"seasons": [
|
||||
"spring",
|
||||
"summer"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,13 @@
|
||||
"bworld:crop": {
|
||||
"days": 7,
|
||||
"stages": 8,
|
||||
"fertilizer": "bworld:bone_meal"
|
||||
"fertilizer": "bworld:bone_meal",
|
||||
"seasons": [
|
||||
"spring",
|
||||
"summer",
|
||||
"autumn",
|
||||
"winter"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -69,7 +69,11 @@
|
||||
"bworld:crop": {
|
||||
"days": 12,
|
||||
"stages": 8,
|
||||
"fertilizer": "bworld:bone_meal"
|
||||
"fertilizer": "bworld:bone_meal",
|
||||
"seasons": [
|
||||
"spring",
|
||||
"autumn"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,11 @@
|
||||
"bworld:crop": {
|
||||
"days": 4,
|
||||
"stages": 4,
|
||||
"fertilizer": "bworld:bone_meal"
|
||||
"fertilizer": "bworld:bone_meal",
|
||||
"seasons": [
|
||||
"spring",
|
||||
"summer"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +68,12 @@
|
||||
"stages": 4,
|
||||
"supporting_age": 4
|
||||
},
|
||||
"leaves": "bworld:water"
|
||||
"leaves": "bworld:water",
|
||||
"seasons": [
|
||||
"spring",
|
||||
"summer",
|
||||
"autumn"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +71,10 @@
|
||||
"stages": 8,
|
||||
"fertilizer": "bworld:bone_meal",
|
||||
"regrow_days": 4,
|
||||
"harvest": "farmersdelight:harvest/tomatoes"
|
||||
"harvest": "farmersdelight:harvest/tomatoes",
|
||||
"seasons": [
|
||||
"summer"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user