Improve growable component
This commit is contained in:
@@ -793,8 +793,11 @@ function register_fishing(ctx: ServerContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface GrowableBlockParams {
|
interface GrowableBlockParams {
|
||||||
|
// what grows on top of it
|
||||||
block_id: string;
|
block_id: string;
|
||||||
|
// it grows on mornings whose day is a multiple of this
|
||||||
days: number;
|
days: number;
|
||||||
|
// how tall a stack of it grows, counting the blocks of it below
|
||||||
max_height: number;
|
max_height: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -810,9 +813,16 @@ function register_growable_block(ctx: ServerContext) {
|
|||||||
return;
|
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);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -350,3 +350,12 @@ Deno.test("blocks without data run on_new_day near players, once a morning", asy
|
|||||||
t.next_morning();
|
t.next_morning();
|
||||||
assertEquals(t.game.world.get_block_id(far, 102, 0), "bworld:air");
|
assertEquals(t.game.world.get_block_id(far, 102, 0), "bworld:air");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Deno.test("a cactus grows a block a day until it's 4 tall", async () => {
|
||||||
|
const t = await setup();
|
||||||
|
t.game.set_block(0, 100, 0, "bworld:sand");
|
||||||
|
t.game.set_block(0, 101, 0, "bworld:cactus");
|
||||||
|
for (let day = 0; day < 6; day++) t.next_morning();
|
||||||
|
const column = [101, 102, 103, 104, 105].map((y) => t.game.world.get_block_id(0, y, 0));
|
||||||
|
assertEquals(column, ["bworld:cactus", "bworld:cactus", "bworld:cactus", "bworld:cactus", "bworld:air"]);
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user