Jester time
This commit is contained in:
@@ -287,7 +287,9 @@ export class MeleeAttackGoal extends Goal {
|
||||
|
||||
override tick() {
|
||||
const mob = this.mob;
|
||||
const target = mob.target!;
|
||||
// a script's goal ticking before this one can have let it go, it stops next tick
|
||||
const target = mob.target;
|
||||
if (!target) return;
|
||||
mob.look_control.look_at_entity(target);
|
||||
this.#recalculate -= 1;
|
||||
const block = `${Math.floor(target.x)},${Math.floor(target.y)},${Math.floor(target.z)}`;
|
||||
|
||||
+20
-12
@@ -1681,18 +1681,7 @@ function player_api(game: GameServer, player: ServerPlayer): Player {
|
||||
}
|
||||
player.vitals.add_exhaustion(amount);
|
||||
},
|
||||
attribute: (id) => player.attribute(known_attribute(id)),
|
||||
add_modifier(attribute, modifier) {
|
||||
const type = known_attribute(attribute);
|
||||
const { id, amount, operation } = modifier;
|
||||
if (typeof id !== "string" || typeof amount !== "number" || !Number.isFinite(amount)) {
|
||||
throw new Error("a modifier needs a string id and a number amount");
|
||||
}
|
||||
if (!MODIFIER_OPERATIONS.includes(operation)) throw new Error(`unknown modifier operation ${operation}`);
|
||||
player.attributes.get(type)?.add_modifier({ id, amount, operation });
|
||||
},
|
||||
remove_modifier: (attribute, id) =>
|
||||
player.attributes.get(known_attribute(attribute))?.remove_modifier(id) ?? false,
|
||||
...attributes_api(player),
|
||||
add_effect(id, duration, options = {}) {
|
||||
const type = known_effect(id);
|
||||
if (!Number.isInteger(duration) || (duration < 1 && duration !== -1)) {
|
||||
@@ -1748,8 +1737,27 @@ function look_direction(yaw: number, pitch: number): Position {
|
||||
return { x: -Math.sin(yaw) * cos_pitch, y: Math.sin(pitch), z: -Math.cos(yaw) * cos_pitch };
|
||||
}
|
||||
|
||||
// a player's or a mob's attribute, add_modifier and remove_modifier
|
||||
function attributes_api(entity: LivingEntity): Pick<LivingRef, "attribute" | "add_modifier" | "remove_modifier"> {
|
||||
return {
|
||||
attribute: (id) => entity.attribute(known_attribute(id)),
|
||||
add_modifier(attribute, modifier) {
|
||||
const type = known_attribute(attribute);
|
||||
const { id, amount, operation } = modifier;
|
||||
if (typeof id !== "string" || typeof amount !== "number" || !Number.isFinite(amount)) {
|
||||
throw new Error("a modifier needs a string id and a number amount");
|
||||
}
|
||||
if (!MODIFIER_OPERATIONS.includes(operation)) throw new Error(`unknown modifier operation ${operation}`);
|
||||
entity.attributes.get(type)?.add_modifier({ id, amount, operation });
|
||||
},
|
||||
remove_modifier: (attribute, id) =>
|
||||
entity.attributes.get(known_attribute(attribute))?.remove_modifier(id) ?? false,
|
||||
};
|
||||
}
|
||||
|
||||
export function living_ref(entity: LivingEntity): LivingRef {
|
||||
return {
|
||||
...attributes_api(entity),
|
||||
id: entity.id,
|
||||
get health() {
|
||||
return entity.health;
|
||||
|
||||
Reference in New Issue
Block a user