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
+12
View File
@@ -177,6 +177,8 @@ export interface ServerWorld {
get_block_data<T>(x: number, y: number, z: number): T | undefined;
// pops an item out of the block at x y z, like a broken block's drops
drop_item(x: number, y: number, z: number, item: ItemStack): void;
// an entity from entities/ with its feet at x y z. throws for kinds that don't exist
spawn_entity(id: Id, x: number, y: number, z: number): EntityRef;
is_loaded(x: number, z: number): boolean;
readonly seed: string;
// ticks since 06:00 of day 1. a day is 36000 ticks (06:00 to 18:00), a night 12000
@@ -186,6 +188,16 @@ export interface ServerWorld {
set_time(time: number): void;
}
// an entity in the world. once it's removed, by a script or anything else, it stays removed and moving it does nothing
export interface EntityRef {
readonly id: string;
readonly type: Id;
readonly position: Readonly<Position>;
readonly removed: boolean;
teleport(x: number, y: number, z: number): void;
remove(): void;
}
export interface Player {
readonly id: string;
readonly name: string;
+1 -1
View File
@@ -178,7 +178,7 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
if ((entity_owners.get(json.id)?.length ?? 0) > 1) {
errors.push(`${file}: entity ${json.id} is also defined by ${entity_owners.get(json.id)!.join(", ")}`);
}
uses(file, json.model, "entity model");
if (json.model !== undefined) uses(file, json.model, "entity model");
uses(file, json.texture, "texture");
}
for (const { file, json } of mod.entity_models) {
+9 -3
View File
@@ -80,12 +80,15 @@ export interface ItemJson {
components?: Record<string, unknown>;
}
// a kind of mob, drawn with an entity model and one texture. it wanders around, panics when hurt and looks at players
// a kind of entity, drawn with an entity model and one texture, or without a model as its texture facing the camera
export interface EntityJson {
id: string;
// an entity model, see EntityModelJson
model: string;
model?: string;
texture: string;
// "animal" (the default) wanders around, panics when hurt and looks at players. "scripted" stays where scripts put
// it: no gravity, ai or health, and it isn't saved with the world, like the fishing hook
behavior?: "animal" | "scripted";
// its collision box in blocks, width is for both x and z
width: number;
height: number;
@@ -629,9 +632,12 @@ export function validate_entity(json: unknown): Problems {
if (!is_object(json)) return ["entity must be an object"];
const problems = [
...validate_id(json.id, "id"),
...validate_id(json.model, "model"),
...(json.model === undefined ? [] : validate_id(json.model, "model")),
...validate_id(json.texture, "texture"),
];
if (json.behavior !== undefined && json.behavior !== "animal" && json.behavior !== "scripted") {
problems.push('behavior must be "animal" or "scripted"');
}
for (const key of ["width", "height"]) {
if (typeof json[key] !== "number" || json[key] <= 0 || json[key] > 16) {
problems.push(`${key} must be a number of blocks above 0, at most 16`);