Move effects into the modding api
This commit is contained in:
@@ -132,6 +132,22 @@ export interface EntityJson {
|
||||
arcane_shielding?: number;
|
||||
}
|
||||
|
||||
// a status effect, like neoforge's MobEffect. what it does over time comes from components scripts register, see
|
||||
// docs/modding/entities/effects.md
|
||||
export interface EffectJson {
|
||||
id: string;
|
||||
// like minecraft's MobEffectCategory, "neutral" when not set
|
||||
category?: EffectCategory;
|
||||
// happens once when added instead of lasting, like instant health. its components' on_tick runs once
|
||||
instant?: boolean;
|
||||
// attribute modifiers while it's on, for level 1. each level adds that much again, like minecraft's speed
|
||||
modifiers?: { attribute: string; amount: number; operation: EffectModifierOperation }[];
|
||||
components?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export type EffectCategory = "beneficial" | "harmful" | "neutral";
|
||||
export type EffectModifierOperation = "add_value" | "add_multiplied_base" | "add_multiplied_total";
|
||||
|
||||
type Vec3 = [number, number, number];
|
||||
|
||||
// a bedrock entity model (models/<name>.geo.json) with only what the engine uses. positions and sizes are in
|
||||
@@ -786,6 +802,41 @@ export function validate_entity(json: unknown): Problems {
|
||||
return problems;
|
||||
}
|
||||
|
||||
export function validate_effect(json: unknown): Problems {
|
||||
if (!is_object(json)) return ["effect must be an object"];
|
||||
const problems = validate_id(json.id, "id");
|
||||
if (json.category !== undefined && !["beneficial", "harmful", "neutral"].includes(json.category as string)) {
|
||||
problems.push('category must be "beneficial", "harmful" or "neutral"');
|
||||
}
|
||||
if (json.instant !== undefined && typeof json.instant !== "boolean") problems.push("instant must be true or false");
|
||||
if (json.modifiers !== undefined) {
|
||||
if (!Array.isArray(json.modifiers)) {
|
||||
problems.push("modifiers must be a list");
|
||||
} else {
|
||||
json.modifiers.forEach((modifier, i) => {
|
||||
const field = `modifiers[${i}]`;
|
||||
if (!is_object(modifier)) {
|
||||
problems.push(`${field} must be { attribute, amount, operation }`);
|
||||
return;
|
||||
}
|
||||
problems.push(...validate_id(modifier.attribute, `${field}.attribute`));
|
||||
if (typeof modifier.amount !== "number" || !Number.isFinite(modifier.amount)) {
|
||||
problems.push(`${field}.amount must be a number`);
|
||||
}
|
||||
if (
|
||||
!["add_value", "add_multiplied_base", "add_multiplied_total"].includes(modifier.operation as string)
|
||||
) {
|
||||
problems.push(
|
||||
`${field}.operation must be "add_value", "add_multiplied_base" or "add_multiplied_total"`,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
if (json.components !== undefined && !is_object(json.components)) problems.push("components must be an object");
|
||||
return problems;
|
||||
}
|
||||
|
||||
export function validate_entity_model(json: unknown): Problems {
|
||||
if (!is_object(json)) return ["entity model must be an object"];
|
||||
const problems = validate_id(json.id, "id");
|
||||
|
||||
Reference in New Issue
Block a user