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
+30 -2
View File
@@ -1,7 +1,8 @@
// mobs mods define in entities/<name>.json (see EntityJson): each one is a kind of animal that wanders around,
// panics when hurt and looks at players now and then, like minecraft's simpler animals
// the kinds of entity mods define in entities/<name>.json (see EntityJson): animals that wander around, panic when hurt
// and look at players now and then, like minecraft's simpler animals, and scripted ones that stay where scripts put them
import type { EntityJson } from "$/common/mod_data.ts";
import { ATTRIBUTES, type AttributeType } from "./attributes.ts";
import { Entity } from "./entity.ts";
import type { EntityFactory } from "./entity_types.ts";
import { FloatGoal, LookAtPlayerGoal, PanicGoal, RandomLookAroundGoal, RandomStrollGoal } from "./goals.ts";
import { Mob } from "./mob.ts";
@@ -9,6 +10,10 @@ import { Mob } from "./mob.ts";
// the entity's class. the attributes are read while LivingEntity is being built, before any field of a subclass is
// set, so each kind gets its own class that has its json already
export function mod_entity_factory(json: EntityJson): EntityFactory {
if (json.behavior === "scripted") {
return (level) => new ScriptedEntity(level, json);
}
class ModEntity extends Mob {
readonly type = json.id;
override width = json.width;
@@ -38,3 +43,26 @@ export function mod_entity_factory(json: EntityJson): EntityFactory {
}
return (level) => new ModEntity(level);
}
// it doesn't fall, think or get hurt, the script that spawned it moves it and takes it away, like the fishing hook.
// it isn't saved with the world: after a restart that script wouldn't know about it anymore
class ScriptedEntity extends Entity {
readonly type: string;
override no_gravity = true;
constructor(level: Entity["level"], json: EntityJson) {
super(level);
this.type = json.id;
this.width = json.width;
this.height = json.height;
this.eye_height = json.height * 0.85;
}
override tick() {
this.base_tick();
}
override get persistent() {
return false;
}
}