Messy but working chicken
This commit is contained in:
@@ -14,6 +14,11 @@ export function register_entity_type(id: string, factory: EntityFactory) {
|
||||
types.set(id, factory);
|
||||
}
|
||||
|
||||
// every kind that can be summoned, items can't be without an item
|
||||
export function entity_type_ids() {
|
||||
return [...types.keys()].filter((id) => id !== ITEM_ENTITY_TYPE).sort();
|
||||
}
|
||||
|
||||
export function has_entity_type(id: string) {
|
||||
return types.has(id);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
// 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
|
||||
import type { EntityJson } from "$/common/mod_data.ts";
|
||||
import { ATTRIBUTES, type AttributeType } from "./attributes.ts";
|
||||
import type { EntityFactory } from "./entity_types.ts";
|
||||
import { FloatGoal, LookAtPlayerGoal, PanicGoal, RandomLookAroundGoal, RandomStrollGoal } from "./goals.ts";
|
||||
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 {
|
||||
class ModEntity extends Mob {
|
||||
readonly type = json.id;
|
||||
override width = json.width;
|
||||
override height = json.height;
|
||||
override eye_height = json.height * 0.85;
|
||||
|
||||
override default_attributes(): [AttributeType, number?][] {
|
||||
return [
|
||||
...super.default_attributes(),
|
||||
[ATTRIBUTES.max_health, json.max_health ?? 10],
|
||||
[ATTRIBUTES.movement_speed, json.movement_speed ?? 0.25],
|
||||
];
|
||||
}
|
||||
|
||||
override register_goals() {
|
||||
this.goals.add_goal(0, new FloatGoal(this));
|
||||
this.goals.add_goal(1, new PanicGoal(this, 1.4));
|
||||
this.goals.add_goal(5, new RandomStrollGoal(this, 1));
|
||||
this.goals.add_goal(6, new LookAtPlayerGoal(this, 6));
|
||||
this.goals.add_goal(7, new RandomLookAroundGoal(this));
|
||||
}
|
||||
|
||||
// animals stay, like minecraft's farm animals
|
||||
override remove_when_far_away() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return (level) => new ModEntity(level);
|
||||
}
|
||||
Reference in New Issue
Block a user