Make cactus grow

This commit is contained in:
2026-10-10 20:00:16 -03:00
parent b03ad862e0
commit f4cf1d8fa8
2 changed files with 37 additions and 1 deletions
+8 -1
View File
@@ -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
}
}
}
}
+29
View File
@@ -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<GrowableBlockParams>("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");
},
});
}