Fishing hook

This commit is contained in:
2026-09-28 20:52:53 -03:00
parent d606bc4b55
commit ad6adb49dc
16 changed files with 258 additions and 37 deletions
+20 -1
View File
@@ -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");