Messy but working chicken
This commit is contained in:
+1
-1
@@ -240,7 +240,7 @@ Deno.test("the atlas fits textures of any size, tallest first, without overlappi
|
||||
Deno.test("a mod with only data packs and reads", () => {
|
||||
const bmod = {
|
||||
manifest: { format_version: 1, id: "tiny", name: "Tiny", version: "1.0.0" },
|
||||
data: { blocks: [], models: [], items: [], recipes: [], ores: [] },
|
||||
data: { blocks: [], models: [], items: [], recipes: [], ores: [], entities: [], entity_models: [] },
|
||||
scripts: {},
|
||||
textures: new Map(),
|
||||
};
|
||||
|
||||
@@ -32,6 +32,8 @@ export function mod_sources(mods_dir: string): ServerModSource[] {
|
||||
items: mod.items.map((i) => i.json),
|
||||
recipes: mod.recipes.map((r) => r.json),
|
||||
ores: mod.ores.map((o) => o.json),
|
||||
entities: mod.entities.map((e) => e.json),
|
||||
entity_models: mod.entity_models.map((m) => m.json),
|
||||
},
|
||||
server_url: url(scripts.server),
|
||||
worldgen_url: url(scripts.worldgen),
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
// mobs mods define in entities/<name>.json, drawn with a bedrock model from models/<name>.geo.json
|
||||
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 { test_game } from "./helpers.ts";
|
||||
|
||||
Deno.test("a bedrock geo.json becomes an entity model with only what the engine uses", () => {
|
||||
const geo = JSON.parse(Deno.readTextFileSync("mods/bworld/models/chicken.geo.json"));
|
||||
const { model, problems } = entity_model_from_geo(geo, "bworld:chicken");
|
||||
assertEquals(problems, []);
|
||||
assertEquals(model!.texture_width, 16);
|
||||
assertEquals(model!.bones.map((bone) => bone.name), ["root", "left_feet", "right_feet", "body", "head"]);
|
||||
assertEquals(model!.bones[4], {
|
||||
name: "head",
|
||||
parent: "root",
|
||||
pivot: [1, 2, -1],
|
||||
cubes: [
|
||||
{ origin: [-1, 4, -2], size: [2, 2, 2], uv: [0, 6] },
|
||||
{ origin: [-1, 4, -3], size: [2, 1, 1], uv: [8, 6] },
|
||||
],
|
||||
});
|
||||
|
||||
// per face uvs and parents that come later aren't supported
|
||||
const per_face = { origin: [0, 0, 0], size: [1, 1, 1], uv: { north: { uv: [0, 0], uv_size: [1, 1] } } };
|
||||
const bad = entity_model_from_geo({
|
||||
"minecraft:geometry": [{
|
||||
description: { texture_width: 16, texture_height: 16 },
|
||||
bones: [{ name: "leg", parent: "body", cubes: [per_face] }, { name: "body" }],
|
||||
}],
|
||||
}, "a:b");
|
||||
assertEquals(bad.model, undefined);
|
||||
assert(bad.problems.some((p) => p.includes("parent body must be a bone before it")), String(bad.problems));
|
||||
assert(bad.problems.some((p) => p.includes("per face uvs aren't supported")), String(bad.problems));
|
||||
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", () => {
|
||||
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",
|
||||
"max_health must be a number, 0 or more",
|
||||
]);
|
||||
});
|
||||
|
||||
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");
|
||||
send(1, { type: "move", x: 3.5, y: 100, z: -2.5, yaw: 1, pitch: 0 });
|
||||
take(1);
|
||||
|
||||
send(1, { type: "suggest", id: 1, text: "/summon bworld:chi" });
|
||||
assertEquals(take(1).find((m) => m.type === "suggestions").suggestions, [{ text: "bworld:chicken" }]);
|
||||
|
||||
send(1, { type: "chat", text: "/summon bworld:chicken" });
|
||||
const messages = take(1);
|
||||
const added = messages.find((m) => m.type === "add_entity");
|
||||
assertEquals(added.entity.type, "bworld:chicken");
|
||||
assertEquals([added.entity.x, added.entity.y, added.entity.z], [3.5, 100, -2.5]);
|
||||
|
||||
const chicken = game.entities.get_entity(added.entity.id) as Mob;
|
||||
assert(chicken instanceof Mob);
|
||||
assertEquals([chicken.width, chicken.height, chicken.max_health], [0.3, 0.4, 4]);
|
||||
// animals don't despawn
|
||||
assertEquals(chicken.remove_when_far_away(1000), false);
|
||||
|
||||
send(1, { type: "chat", text: "/summon bworld:item" });
|
||||
assertStringIncludes(take(1).find((m) => m.type === "chat").text, "There's no entity bworld:item");
|
||||
});
|
||||
Reference in New Issue
Block a user