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 () => {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import { assert, assertEquals, assertStringIncludes } from "@std/assert";
|
||||
import { entity_model_from_geo, validate_entity } from "$/common/mod_data.ts";
|
||||
import { Mob } from "$/server/game/entity/mob.ts";
|
||||
import { create_entity } from "$/server/game/entity/entity_types.ts";
|
||||
import { test_game } from "./helpers.ts";
|
||||
|
||||
Deno.test("a bedrock geo.json becomes an entity model with only what the engine uses", () => {
|
||||
@@ -34,7 +35,7 @@ Deno.test("a bedrock geo.json becomes an entity model with only what the engine
|
||||
assertEquals(entity_model_from_geo({ format_version: "1.12.0" }, "a:b").model, undefined);
|
||||
});
|
||||
|
||||
Deno.test("an entity needs a model, a texture and a size", () => {
|
||||
Deno.test("an entity needs a texture and a size", () => {
|
||||
assertEquals(validate_entity({ id: "a:b", model: "a:b", texture: "a:b", width: 0.5, height: 1 }), []);
|
||||
assertEquals(validate_entity({ id: "a:b", model: "a:b", texture: "a:b", width: 0, height: 1, max_health: -1 }), [
|
||||
"width must be a number of blocks above 0, at most 16",
|
||||
@@ -42,6 +43,24 @@ Deno.test("an entity needs a model, a texture and a size", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
Deno.test("an entity without a model is drawn as its texture, and a scripted one has no ai", () => {
|
||||
assertEquals(validate_entity({ id: "a:b", texture: "a:b", behavior: "scripted", width: 0.25, height: 0.25 }), []);
|
||||
assertEquals(validate_entity({ id: "a:b", texture: "a:b", behavior: "flying", width: 0.25, height: 0.25 }), [
|
||||
'behavior must be "animal" or "scripted"',
|
||||
]);
|
||||
});
|
||||
|
||||
Deno.test("scripted entities stay put and aren't saved with the world", async () => {
|
||||
const { game } = await test_game("mods");
|
||||
const hook = create_entity(game.entities, "bworld:fishing_hook")!;
|
||||
assert(!(hook instanceof Mob));
|
||||
hook.set_position(0.5, 100, 0.5);
|
||||
game.entities.add_entity(hook);
|
||||
for (let i = 0; i < 20; i++) game.tick();
|
||||
assertEquals([hook.x, hook.y, hook.z, hook.removed], [0.5, 100, 0.5, false]);
|
||||
assertEquals(game.entities.save().filter((saved) => saved.id === "bworld:fishing_hook"), []);
|
||||
});
|
||||
|
||||
Deno.test("/summon spawns a mod's entity where the player is", async () => {
|
||||
const { join, take, send, game } = await test_game("mods");
|
||||
join(1, "alice");
|
||||
|
||||
Reference in New Issue
Block a user