diff --git a/docs/modding/blocks/crops.md b/docs/modding/blocks/crops.md index 95c2fdd..2f3da53 100644 --- a/docs/modding/blocks/crops.md +++ b/docs/modding/blocks/crops.md @@ -108,6 +108,7 @@ and 1 to 4 seeds, like Minecraft's wheat: | `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. | | `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. | +| `ripe` | The block it turns into the morning it's fully grown, like `bworld:pumpkin`. Its stages spread over the days before, the last one the day before it ripens. | ## Harvesting By Hand diff --git a/mods/bworld/blocks/melon.json b/mods/bworld/blocks/melon.json new file mode 100644 index 0000000..f546a61 --- /dev/null +++ b/mods/bworld/blocks/melon.json @@ -0,0 +1,16 @@ +{ + "format_version": 1, + "block": { + "id": "bworld:melon", + "textures": { + "top": "bworld:melon_top", + "bottom": "bworld:melon_bottom", + "side": "bworld:melon_side" + }, + "mining": { + "toughness": 1.5, + "tool": "axe" + }, + "loot_table": "bworld:blocks/melon" + } +} diff --git a/mods/bworld/blocks/melon_plant.json b/mods/bworld/blocks/melon_plant.json new file mode 100644 index 0000000..01d8644 --- /dev/null +++ b/mods/bworld/blocks/melon_plant.json @@ -0,0 +1,80 @@ +{ + "format_version": 1, + "block": { + "id": "bworld:melon_plant", + "textures": { + "crop": "bworld:melon_stage_0" + }, + "model": "engine:crop", + "variants": { + "age=0": { + "textures": { + "crop": "bworld:melon_stage_0" + } + }, + "age=1": { + "textures": { + "crop": "bworld:melon_stage_1" + } + }, + "age=2": { + "textures": { + "crop": "bworld:melon_stage_2" + } + }, + "age=3": { + "textures": { + "crop": "bworld:melon_stage_3" + } + }, + "age=4": { + "textures": { + "crop": "bworld:melon_stage_4" + } + }, + "age=5": { + "textures": { + "crop": "bworld:melon_stage_5" + } + }, + "age=6": { + "textures": { + "crop": "bworld:melon_stage_6" + } + }, + "age=7": { + "textures": { + "crop": "bworld:melon_stage_7" + } + } + }, + "render_layer": "cutout", + "collision": false, + "mining": { + "toughness": 0 + }, + "drops": "bworld:melon_seeds", + "item": false, + "place_on": [ + "bworld:hoed_dirt" + ], + "states": [ + { + "name": "age", + "bits": 3, + "default": 0 + } + ], + "components": { + "bworld:crop": { + "days": 12, + "stages": 8, + "fertilizer": "bworld:bone_meal", + "ripe": "bworld:melon", + "seasons": [ + "summer" + ] + } + } + } +} diff --git a/mods/bworld/blocks/pumpkin.json b/mods/bworld/blocks/pumpkin.json new file mode 100644 index 0000000..06edb46 --- /dev/null +++ b/mods/bworld/blocks/pumpkin.json @@ -0,0 +1,16 @@ +{ + "format_version": 1, + "block": { + "id": "bworld:pumpkin", + "textures": { + "top": "bworld:pumpkin_top", + "bottom": "bworld:pumpkin_bottom", + "side": "bworld:pumpkin_side" + }, + "mining": { + "toughness": 1.5, + "tool": "axe" + }, + "drops": "bworld:pumpkin" + } +} diff --git a/mods/bworld/blocks/pumpkin_plant.json b/mods/bworld/blocks/pumpkin_plant.json new file mode 100644 index 0000000..4b5caa5 --- /dev/null +++ b/mods/bworld/blocks/pumpkin_plant.json @@ -0,0 +1,80 @@ +{ + "format_version": 1, + "block": { + "id": "bworld:pumpkin_plant", + "textures": { + "crop": "bworld:pumpkin_stage_0" + }, + "model": "engine:crop", + "variants": { + "age=0": { + "textures": { + "crop": "bworld:pumpkin_stage_0" + } + }, + "age=1": { + "textures": { + "crop": "bworld:pumpkin_stage_1" + } + }, + "age=2": { + "textures": { + "crop": "bworld:pumpkin_stage_2" + } + }, + "age=3": { + "textures": { + "crop": "bworld:pumpkin_stage_3" + } + }, + "age=4": { + "textures": { + "crop": "bworld:pumpkin_stage_4" + } + }, + "age=5": { + "textures": { + "crop": "bworld:pumpkin_stage_5" + } + }, + "age=6": { + "textures": { + "crop": "bworld:pumpkin_stage_6" + } + }, + "age=7": { + "textures": { + "crop": "bworld:pumpkin_stage_7" + } + } + }, + "render_layer": "cutout", + "collision": false, + "mining": { + "toughness": 0 + }, + "drops": "bworld:pumpkin_seeds", + "item": false, + "place_on": [ + "bworld:hoed_dirt" + ], + "states": [ + { + "name": "age", + "bits": 3, + "default": 0 + } + ], + "components": { + "bworld:crop": { + "days": 12, + "stages": 8, + "fertilizer": "bworld:bone_meal", + "ripe": "bworld:pumpkin", + "seasons": [ + "autumn" + ] + } + } + } +} diff --git a/mods/bworld/items/melon.json b/mods/bworld/items/melon.json new file mode 100644 index 0000000..f544160 --- /dev/null +++ b/mods/bworld/items/melon.json @@ -0,0 +1,7 @@ +{ + "format_version": 1, + "item": { + "id": "bworld:melon", + "base_sell_value": 60 + } +} diff --git a/mods/bworld/items/melon_seeds.json b/mods/bworld/items/melon_seeds.json new file mode 100644 index 0000000..5109323 --- /dev/null +++ b/mods/bworld/items/melon_seeds.json @@ -0,0 +1,8 @@ +{ + "format_version": 1, + "item": { + "id": "bworld:melon_seeds", + "texture": "bworld:melon_seed", + "places": "bworld:melon_plant" + } +} diff --git a/mods/bworld/items/melon_slice.json b/mods/bworld/items/melon_slice.json new file mode 100644 index 0000000..bd1a33d --- /dev/null +++ b/mods/bworld/items/melon_slice.json @@ -0,0 +1,12 @@ +{ + "format_version": 1, + "item": { + "id": "bworld:melon_slice", + "texture": "bworld:melon", + "food": { + "nutrition": 2, + "saturation_modifier": 0.3 + }, + "base_sell_value": 10 + } +} diff --git a/mods/bworld/items/pumpkin.json b/mods/bworld/items/pumpkin.json new file mode 100644 index 0000000..94f2af6 --- /dev/null +++ b/mods/bworld/items/pumpkin.json @@ -0,0 +1,7 @@ +{ + "format_version": 1, + "item": { + "id": "bworld:pumpkin", + "base_sell_value": 80 + } +} diff --git a/mods/bworld/items/pumpkin_seeds.json b/mods/bworld/items/pumpkin_seeds.json new file mode 100644 index 0000000..20754fb --- /dev/null +++ b/mods/bworld/items/pumpkin_seeds.json @@ -0,0 +1,8 @@ +{ + "format_version": 1, + "item": { + "id": "bworld:pumpkin_seeds", + "texture": "bworld:melon_seed", + "places": "bworld:pumpkin_plant" + } +} diff --git a/mods/bworld/loot_tables/blocks/melon.json b/mods/bworld/loot_tables/blocks/melon.json new file mode 100644 index 0000000..ac063dd --- /dev/null +++ b/mods/bworld/loot_tables/blocks/melon.json @@ -0,0 +1,18 @@ +{ + "format_version": 1, + "loot_table": { + "pools": [ + { + "entries": [ + { + "item": "bworld:melon_slice", + "count": { + "min": 3, + "max": 7 + } + } + ] + } + ] + } +} diff --git a/mods/bworld/recipes/crafting_melon_seeds.json b/mods/bworld/recipes/crafting_melon_seeds.json new file mode 100644 index 0000000..381aecd --- /dev/null +++ b/mods/bworld/recipes/crafting_melon_seeds.json @@ -0,0 +1,16 @@ +{ + "format_version": 1, + "recipe": { + "type": "shaped", + "pattern": [ + "I" + ], + "key": { + "I": "bworld:melon_slice" + }, + "result": { + "id": "bworld:melon_seeds", + "count": 1 + } + } +} diff --git a/mods/bworld/recipes/crafting_pumpkin_seeds.json b/mods/bworld/recipes/crafting_pumpkin_seeds.json new file mode 100644 index 0000000..2b3f226 --- /dev/null +++ b/mods/bworld/recipes/crafting_pumpkin_seeds.json @@ -0,0 +1,16 @@ +{ + "format_version": 1, + "recipe": { + "type": "shaped", + "pattern": [ + "I" + ], + "key": { + "I": "bworld:pumpkin" + }, + "result": { + "id": "bworld:pumpkin_seeds", + "count": 4 + } + } +} diff --git a/mods/bworld/scripts/server.ts b/mods/bworld/scripts/server.ts index 780df50..93e1a97 100644 --- a/mods/bworld/scripts/server.ts +++ b/mods/bworld/scripts/server.ts @@ -360,6 +360,9 @@ 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 block it turns into the morning it's fully grown, like a pumpkin. its stages come before that, the last one + // the day before + ripe?: 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[]; } @@ -428,7 +431,8 @@ function register_farming(ctx: ServerContext) { // 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); + // becoming the ripe block is a stage too, the last + const stages = params.stages + (params.upper?.stages ?? 0) + (params.ripe ? 1 : 0); return Math.min(stages - 1, Math.floor(days * (stages - 1) / params.days)); }; @@ -443,6 +447,10 @@ function register_farming(ctx: ServerContext) { // shows the stage for days, growing or taking away the top block for two block crops const set_days = (block: BlockRef, params: CropParams, days: number) => { + if (params.ripe && days >= params.days) { + ctx.world.set_block(block.x, block.y, block.z, params.ripe); + return; + } block.data = { ...block.data, days }; const stage = stage_for(params, days); const upper = params.upper; diff --git a/tests/farming_test.ts b/tests/farming_test.ts index 5533cce..a8f8972 100644 --- a/tests/farming_test.ts +++ b/tests/farming_test.ts @@ -306,3 +306,28 @@ Deno.test("beetroots, cotton and strawberries grow, and strawberries and cotton } assertEquals(t.state(2, 101, 0, "age"), 7); }); + +Deno.test("a pumpkin plant becomes a pumpkin the morning it's grown, and a melon breaks into slices", async () => { + const t = await setup(["bworld:bone_meal 64"]); + // pumpkins grow in autumn, from day 99 + t.game.set_time(98 * CYCLE_TICKS); + t.game.tick(); + // every stage shows, the last the day before + const ages = grow(t, 0, "bworld:pumpkin_plant", 11); + assertEquals(ages, [0, 1, 2, 2, 3, 4, 4, 5, 6, 6, 7]); + t.game.set_block_state(0, 100, 0, 1); + t.next_morning(); + assertEquals(t.game.world.get_block_id(0, 101, 0), "bworld:pumpkin"); + assertEquals(t.game.world.get_tile(0, 101, 0), undefined, "no crop data left behind"); + + // bone meal ripens it too + t.game.set_block(1, 100, 0, "bworld:hoed_dirt"); + t.game.set_block(1, 101, 0, "bworld:melon_plant"); + t.hold("bworld:bone_meal"); + for (let i = 0; i < 12; i++) t.use(1, 101, 0); + assertEquals(t.game.world.get_block_id(1, 101, 0), "bworld:melon"); + t.send(1, { type: "break_block", x: 1, y: 101, z: 0 }); + const slices = t.game.item_entities().map((e) => e.item.to_data()); + assertEquals(slices.map((item) => item.id), ["bworld:melon_slice"]); + assert(slices[0].count >= 3 && slices[0].count <= 7); +});