diff --git a/mods/bworld/blocks/cactus.json b/mods/bworld/blocks/cactus.json index 4f880d4..ac0cc66 100644 --- a/mods/bworld/blocks/cactus.json +++ b/mods/bworld/blocks/cactus.json @@ -16,6 +16,13 @@ "toughness": 0.6 }, "drops": "bworld:cactus", - "place_on": ["bworld:sand", "bworld:cactus"] + "place_on": ["bworld:sand", "bworld:cactus"], + "components": { + "bworld:growable_block": { + "block_id": "bworld:cactus", + "days": 1, + "max_height": 4 + } + } } } diff --git a/mods/bworld/scripts/server.ts b/mods/bworld/scripts/server.ts index 93e1a97..d06927e 100644 --- a/mods/bworld/scripts/server.ts +++ b/mods/bworld/scripts/server.ts @@ -15,6 +15,7 @@ export function setup(ctx: ServerContext) { register_buckets(ctx); register_curios(ctx); register_effects(ctx); + register_growable_block(ctx); } // right clicking with a type of tool turns the block into another, like any hoe on grass @@ -790,3 +791,31 @@ function register_fishing(ctx: ServerContext) { } }); } + +interface GrowableBlockParams { + block_id: string; + days: number; + max_height: number; +} + +function register_growable_block(ctx: ServerContext) { + ctx.components.register_block("bworld:growable_block", { + on_create(block) { + block.data = {}; + }, + on_new_day(block, params, day) { + console.log(ctx.world.get_block(block.x, block.y + 1, block.z)); + if (ctx.world.get_block(block.x, block.y + 1, block.z) !== "bworld:air") { + return; + } + const should_grow_today = day % params.days === 0; + if (!should_grow_today) { + return; + } + + // TODO: check max_height + + ctx.world.set_block(block.x, block.y + 1, block.z, "bworld:cactus"); + }, + }); +}