Move effects into the modding api

This commit is contained in:
2026-10-02 11:53:44 -03:00
parent 4309c700d2
commit e5dcb97643
33 changed files with 458 additions and 109 deletions
+22 -1
View File
@@ -58,9 +58,30 @@ export interface ItemComponent<P = any> {
on_use?(item: ItemStack, params: P, player: Player): void;
}
// P is the component's params from the effect json. see docs/modding/entities/effects.md
// deno-lint-ignore no-explicit-any
export interface EffectComponent<P = any> {
// whether on_tick runs this tick, like neoforge's shouldApplyEffectTickThisTick. ticks is what's left of the
// effect, or how long it's been on for ones that last forever. every tick when not set
should_tick?(ticks: number, amplifier: number, params: P): boolean;
// like neoforge's applyEffectTick. returning false takes the effect off. instant effects run it once, when added
on_tick?(entity: LivingRef, amplifier: number, params: P): boolean | void;
}
// a player or a mob, what effects work on
export interface LivingRef {
readonly id: string;
readonly health: number;
readonly max_health: number;
// cause is for events and the death message, like "magic"
damage(amount: number, cause?: string): void;
heal(amount: number): void;
}
export interface ComponentRegistry {
register_block<P>(id: Id, component: BlockComponent<P>): void;
register_item<P>(id: Id, component: ItemComponent<P>): void;
register_effect<P>(id: Id, component: EffectComponent<P>): void;
}
// commands, brigadier's way like neoforge's: see common/commands.ts and docs/modding/misc/commands.md
@@ -241,7 +262,7 @@ export interface Player {
add_modifier(attribute: Id, modifier: AttributeModifier): void;
// whether it had it
remove_modifier(attribute: Id, id: string): boolean;
// status effects, like minecraft's: "bworld:regeneration", "bworld:speed"... duration in ticks, -1 for forever.
// status effects, any mod's, like the base game's "bworld:regeneration". duration in ticks, -1 for forever.
// adding one they have merges them like minecraft: the stronger wins, and a weaker longer one waits under it
add_effect(id: Id, duration: number, options?: EffectOptions): void;
// the one they have of that type, undefined when they don't