Make cactus grow
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user