Add season for crops
This commit is contained in:
@@ -4,8 +4,10 @@ A crop is a block with an `age` state, the base game's `bworld:crop` [component]
|
|||||||
places it. Adding one takes no code.
|
places it. Adding one takes no code.
|
||||||
|
|
||||||
Crops grow on Stardew Valley's clock with Minecraft's rules: every morning at 06:00, a crop whose farmland was watered
|
Crops grow on Stardew Valley's clock with Minecraft's rules: every morning at 06:00, a crop whose farmland was watered
|
||||||
the day before grows a day, then all farmland dries out. The crop shows the stage for how far along it is.
|
the day before grows a day, then all farmland dries out. The crop shows the stage for how far along it is. A crop with
|
||||||
`mods/farmersdelight` adds its cabbages, onions, tomatoes and rice this way.
|
`seasons` dies the first morning that's in another season, turning into a `bworld:dead_bush`, so a summer crop has to be
|
||||||
|
harvested before autumn comes. The season is its biome's, so a crop that only grows in summer is always out of season in
|
||||||
|
a snowy biome. `mods/farmersdelight` adds its cabbages, onions, tomatoes and rice this way.
|
||||||
|
|
||||||
## A Basic Crop
|
## A Basic Crop
|
||||||
|
|
||||||
@@ -96,15 +98,16 @@ and 1 to 4 seeds, like Minecraft's wheat:
|
|||||||
|
|
||||||
## Parameters
|
## Parameters
|
||||||
|
|
||||||
| Param | Meaning |
|
| Param | Meaning |
|
||||||
| ------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| ------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
| `days` | Watered mornings from planting to fully grown. |
|
| `days` | Watered mornings from planting to fully grown. |
|
||||||
| `stages` | How many ages it shows, 0 to `stages - 1`, spread evenly over `days`. The `age` state must fit them. |
|
| `stages` | How many ages it shows, 0 to `stages - 1`, spread evenly over `days`. The `age` state must fit them. |
|
||||||
| `fertilizer` | An item that grows it a day right away when used on it, like bone meal. |
|
| `fertilizer` | An item that grows it a day right away when used on it, like bone meal. |
|
||||||
| `water` | `"farmland"` (the default) needs watered farmland under it. `"always"` grows every morning. |
|
| `water` | `"farmland"` (the default) needs watered farmland under it. `"always"` grows every morning. |
|
||||||
| `regrow_days`, `harvest` | Right clicking it once grown picks it, dropping what the [loot table](../resources/loot_tables.md) `harvest` gives, and it grows back after `regrow_days`. |
|
| `regrow_days`, `harvest` | Right clicking it once grown picks it, dropping what the [loot table](../resources/loot_tables.md) `harvest` gives, and it grows back after `regrow_days`. |
|
||||||
| `upper` | `{ block, stages, supporting_age }`: its last stages grow a second block on top, see below. |
|
| `upper` | `{ block, stages, supporting_age }`: its last stages grow a second block on top, see below. |
|
||||||
| `leaves` | What the spot becomes when it's broken, like the water rice was planted in. |
|
| `leaves` | What the spot becomes when it's broken, like the water rice was planted in. |
|
||||||
|
| `seasons` | The [seasons](../worldgen/biomes.md#seasons) it grows in, like `["spring", "summer"]`. A morning in any other season turns it into a dead bush. Every season when not set. |
|
||||||
|
|
||||||
## Harvesting By Hand
|
## Harvesting By Hand
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,11 @@
|
|||||||
"bworld:crop": {
|
"bworld:crop": {
|
||||||
"days": 3,
|
"days": 3,
|
||||||
"stages": 4,
|
"stages": 4,
|
||||||
"fertilizer": "bworld:bone_meal"
|
"fertilizer": "bworld:bone_meal",
|
||||||
|
"seasons": [
|
||||||
|
"spring",
|
||||||
|
"autumn"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,11 @@
|
|||||||
"bworld:crop": {
|
"bworld:crop": {
|
||||||
"days": 6,
|
"days": 6,
|
||||||
"stages": 4,
|
"stages": 4,
|
||||||
"fertilizer": "bworld:bone_meal"
|
"fertilizer": "bworld:bone_meal",
|
||||||
|
"seasons": [
|
||||||
|
"spring",
|
||||||
|
"summer"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,7 +69,13 @@
|
|||||||
"bworld:crop": {
|
"bworld:crop": {
|
||||||
"days": 7,
|
"days": 7,
|
||||||
"stages": 8,
|
"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
|
// 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 type { Position } from "bworld/shared";
|
||||||
import { register_curios } from "./curios.ts";
|
import { register_curios } from "./curios.ts";
|
||||||
import { register_effects } from "./effects.ts";
|
import { register_effects } from "./effects.ts";
|
||||||
@@ -331,6 +331,7 @@ function register_smithing_table(ctx: ServerContext) {
|
|||||||
// it's dug up
|
// it's dug up
|
||||||
|
|
||||||
const FARMLAND = "bworld:hoed_dirt";
|
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
|
// every tier of watering can is a tool of this type, and shares the bworld:watering_can component
|
||||||
const WATERING_CAN = "watering_can";
|
const WATERING_CAN = "watering_can";
|
||||||
|
|
||||||
@@ -359,6 +360,8 @@ interface CropParams {
|
|||||||
upper?: { block: string; stages: number; supporting_age: number };
|
upper?: { block: string; stages: number; supporting_age: number };
|
||||||
// what the spot becomes when it's broken, like water where rice was
|
// what the spot becomes when it's broken, like water where rice was
|
||||||
leaves?: string;
|
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
|
// 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
|
// 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 stage_for = (params: CropParams, days: number) => {
|
||||||
const stages = params.stages + (params.upper?.stages ?? 0);
|
const stages = params.stages + (params.upper?.stages ?? 0);
|
||||||
@@ -457,6 +469,10 @@ function register_farming(ctx: ServerContext) {
|
|||||||
block.data = { days: days_of(block, params) };
|
block.data = { days: days_of(block, params) };
|
||||||
},
|
},
|
||||||
on_new_day(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);
|
const days = days_of(block, params);
|
||||||
if (days >= params.days) return;
|
if (days >= params.days) return;
|
||||||
const watered = params.water === "always" || is_watered(block.x, block.y - 1, block.z);
|
const watered = params.water === "always" || is_watered(block.x, block.y - 1, block.z);
|
||||||
|
|||||||
@@ -69,7 +69,11 @@
|
|||||||
"bworld:crop": {
|
"bworld:crop": {
|
||||||
"days": 12,
|
"days": 12,
|
||||||
"stages": 8,
|
"stages": 8,
|
||||||
"fertilizer": "bworld:bone_meal"
|
"fertilizer": "bworld:bone_meal",
|
||||||
|
"seasons": [
|
||||||
|
"spring",
|
||||||
|
"autumn"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,11 @@
|
|||||||
"bworld:crop": {
|
"bworld:crop": {
|
||||||
"days": 4,
|
"days": 4,
|
||||||
"stages": 4,
|
"stages": 4,
|
||||||
"fertilizer": "bworld:bone_meal"
|
"fertilizer": "bworld:bone_meal",
|
||||||
|
"seasons": [
|
||||||
|
"spring",
|
||||||
|
"summer"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,7 +68,12 @@
|
|||||||
"stages": 4,
|
"stages": 4,
|
||||||
"supporting_age": 4
|
"supporting_age": 4
|
||||||
},
|
},
|
||||||
"leaves": "bworld:water"
|
"leaves": "bworld:water",
|
||||||
|
"seasons": [
|
||||||
|
"spring",
|
||||||
|
"summer",
|
||||||
|
"autumn"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,7 +71,10 @@
|
|||||||
"stages": 8,
|
"stages": 8,
|
||||||
"fertilizer": "bworld:bone_meal",
|
"fertilizer": "bworld:bone_meal",
|
||||||
"regrow_days": 4,
|
"regrow_days": 4,
|
||||||
"harvest": "farmersdelight:harvest/tomatoes"
|
"harvest": "farmersdelight:harvest/tomatoes",
|
||||||
|
"seasons": [
|
||||||
|
"summer"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -188,6 +188,9 @@ Deno.test("potatoes and carrots are planted on farmland, and eaten anywhere else
|
|||||||
|
|
||||||
Deno.test("tomatoes take 11 days, are picked by hand, and grow back in 4", async () => {
|
Deno.test("tomatoes take 11 days, are picked by hand, and grow back in 4", async () => {
|
||||||
const t = await setup();
|
const t = await setup();
|
||||||
|
// they only grow in summer, which starts on day 50
|
||||||
|
t.game.set_time(49 * CYCLE_TICKS);
|
||||||
|
t.game.tick();
|
||||||
const ages = grow(t, 1, "farmersdelight:tomatoes", 11);
|
const ages = grow(t, 1, "farmersdelight:tomatoes", 11);
|
||||||
assertEquals(ages.at(-1), 7);
|
assertEquals(ages.at(-1), 7);
|
||||||
assertEquals(ages.at(-2), 6);
|
assertEquals(ages.at(-2), 6);
|
||||||
@@ -240,3 +243,35 @@ Deno.test("rice is planted in water, grows panicles on top without watering, and
|
|||||||
assertEquals(t.game.world.get_block_id(1, 100, 0), "bworld:water");
|
assertEquals(t.game.world.get_block_id(1, 100, 0), "bworld:water");
|
||||||
assertEquals(t.game.world.get_block_id(1, 101, 0), "bworld:air");
|
assertEquals(t.game.world.get_block_id(1, 101, 0), "bworld:air");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Deno.test("a crop dies into a dead bush the first morning out of its seasons", async () => {
|
||||||
|
const t = await setup();
|
||||||
|
// carrots grow in spring and autumn. the last morning of spring they grow
|
||||||
|
t.game.set_time(47 * CYCLE_TICKS);
|
||||||
|
t.game.tick();
|
||||||
|
assertEquals(grow(t, 0, "bworld:carrots", 1), [1]);
|
||||||
|
// and the first of summer they die, dropping nothing
|
||||||
|
t.game.set_block_state(0, 100, 0, 1);
|
||||||
|
t.next_morning();
|
||||||
|
assertEquals(t.game.world.day, 49);
|
||||||
|
assertEquals(t.game.world.get_block_id(0, 101, 0), "bworld:dead_bush");
|
||||||
|
assertEquals(t.game.item_entities(), []);
|
||||||
|
// still standing on its farmland
|
||||||
|
assertEquals(t.game.world.get_block_id(0, 100, 0), "bworld:hoed_dirt");
|
||||||
|
});
|
||||||
|
|
||||||
|
Deno.test("a two block crop dies whole, its top going without dropping anything", async () => {
|
||||||
|
const t = await setup();
|
||||||
|
t.game.set_block(1, 99, 0, "bworld:dirt");
|
||||||
|
t.game.set_block(1, 100, 0, "farmersdelight:rice");
|
||||||
|
for (let day = 0; day < 6; day++) t.next_morning();
|
||||||
|
assertEquals(t.game.world.get_block_id(1, 101, 0), "farmersdelight:rice_panicles");
|
||||||
|
|
||||||
|
// rice grows in autumn, dies in winter, winter starts on day 148
|
||||||
|
t.game.set_time(147 * CYCLE_TICKS - 1);
|
||||||
|
t.game.tick();
|
||||||
|
t.game.tick();
|
||||||
|
assertEquals(t.game.world.get_block_id(1, 100, 0), "bworld:dead_bush");
|
||||||
|
assertEquals(t.game.world.get_block_id(1, 101, 0), "bworld:air");
|
||||||
|
assertEquals(t.game.item_entities(), []);
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user