Fishing hook
This commit is contained in:
+15
-1
@@ -36,18 +36,28 @@ async function setup() {
|
||||
}
|
||||
return false;
|
||||
};
|
||||
return { ...t, slot, rod, cast, reel, fish, wait_for_bite };
|
||||
const hooks = () => t.game.entities.all().filter((e) => e.type === "bworld:fishing_hook");
|
||||
return { ...t, slot, rod, cast, reel, fish, wait_for_bite, hooks };
|
||||
}
|
||||
|
||||
Deno.test("cast into water, reel in a fish once something bites", async () => {
|
||||
const t = await setup();
|
||||
t.cast();
|
||||
assertEquals(t.rod()?.data, { cast: true });
|
||||
// the hook floats on the water, and goes under when something bites
|
||||
assertEquals(t.hooks().length, 1);
|
||||
const hook = t.hooks()[0];
|
||||
assertEquals([hook.x, hook.z], [2.5, 0.5]);
|
||||
const floating = hook.y;
|
||||
assert(floating > 100.7 && floating < 101, String(floating));
|
||||
|
||||
assert(t.wait_for_bite());
|
||||
assert(hook.y < floating - 0.1, String(hook.y));
|
||||
t.reel();
|
||||
assertEquals(t.fish().length, 1);
|
||||
assertEquals(t.rod()?.data, undefined);
|
||||
t.game.tick();
|
||||
assertEquals(t.hooks().length, 0);
|
||||
});
|
||||
|
||||
Deno.test("reeling in before a bite catches nothing", async () => {
|
||||
@@ -72,6 +82,8 @@ Deno.test("switching away from the rod takes the line out", async () => {
|
||||
t.send(1, { type: "select_slot", slot: (t.slot + 1) % 9 });
|
||||
t.game.tick();
|
||||
assertEquals(t.rod()?.data, undefined);
|
||||
t.game.tick();
|
||||
assertEquals(t.hooks().length, 0);
|
||||
t.send(1, { type: "select_slot", slot: t.slot });
|
||||
assert(!t.wait_for_bite());
|
||||
});
|
||||
@@ -82,6 +94,8 @@ Deno.test("the line comes out when the water is gone", async () => {
|
||||
t.game.set_block(2, 100, 0, "bworld:stone");
|
||||
t.game.tick();
|
||||
assertEquals(t.rod()?.data, undefined);
|
||||
t.game.tick();
|
||||
assertEquals(t.hooks().length, 0);
|
||||
});
|
||||
|
||||
Deno.test("a cast rod shows its cast texture", async () => {
|
||||
|
||||
Reference in New Issue
Block a user