Improve growable component
This commit is contained in:
@@ -793,8 +793,11 @@ function register_fishing(ctx: ServerContext) {
|
||||
}
|
||||
|
||||
interface GrowableBlockParams {
|
||||
// what grows on top of it
|
||||
block_id: string;
|
||||
// it grows on mornings whose day is a multiple of this
|
||||
days: number;
|
||||
// how tall a stack of it grows, counting the blocks of it below
|
||||
max_height: number;
|
||||
}
|
||||
|
||||
@@ -810,9 +813,16 @@ function register_growable_block(ctx: ServerContext) {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: check max_height
|
||||
// the stack it's the top of, itself included, is as tall as it gets
|
||||
let height = 1;
|
||||
while (height < params.max_height && ctx.world.get_block(block.x, block.y - height, block.z) === block.id) {
|
||||
height += 1;
|
||||
}
|
||||
if (height >= params.max_height) {
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.world.set_block(block.x, block.y + 1, block.z, "bworld:cactus");
|
||||
ctx.world.set_block(block.x, block.y + 1, block.z, params.block_id);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user