Files
bworld/docs/modding/entities/effects.md
T
2026-10-02 13:19:12 -03:00

5.3 KiB
Raw Blame History

Status Effects

Status effects change a player or a mob for a while, like speed or poison. They work like NeoForge's MobEffects: an effect is defined once, and adding it to someone gives them an instance of it with a duration and a level.

Like blocks and items, an effect is data with components. Its JSON in the mod's effects/ folder says what it is and which attributes it changes. Components, registered by the server script, say what it does over time. Even the base game's effects are defined this way, in mods/bworld/effects.

Defining an Effect

effects/swiftness.json:

{
	"format_version": 1,
	"effect": {
		"id": "copper_tools:swiftness",
		"category": "beneficial",
		"icon": "copper_tools:swiftness",
		"modifiers": [{ "attribute": "bworld:movement_speed", "amount": 0.1, "operation": "add_multiplied_total" }]
	}
}
Field Required What it does
id yes The effect's id, in the mod's namespace.
category no "beneficial", "harmful" or "neutral" (the default), like NeoForge's MobEffectCategory.
instant no true makes it happen once when added instead of lasting, like bworld:instant_health.
icon no A texture, shown at the top of the inventory screen while the player has it, with its name, level and time left on hover. 16×16 like an item's.
modifiers no Attribute modifiers while it's on. Each level adds amount again.
components no What it does over time, see below.

The modifiers' operation is "add_value", "add_multiplied_base" or "add_multiplied_total". They come off when the effect ends.

Effect Components

An effect that does something each tick lists components, with their parameters:

"components": {
	"copper_tools:rusting": { "every": 40 }
}

The server script registers them during setup, in the mod's own namespace:

import type { ServerContext } from "bworld/server";

export function setup(ctx: ServerContext) {
	ctx.components.register_effect<{ every: number }>("copper_tools:rusting", {
		should_tick: (ticks, amplifier, params) => ticks % params.every === 0,
		on_tick(entity, amplifier) {
			entity.damage(amplifier + 1, "rust");
		},
	});
}
Handler Called when Returns
should_tick(ticks, amplifier, params) Every tick the effect is on, to ask whether on_tick runs. Every tick without it. true to run on_tick
on_tick(entity, amplifier, params) When should_tick says so. Instant effects run it once, when added. false takes the effect off

ticks is how many ticks the effect has left, or how long it's been on for one that lasts forever. amplifier is the level minus 1. entity is the player or mob that has it:

interface LivingRef {
	readonly id: string;
	readonly health: number;
	readonly max_health: number;
	damage(amount: number, cause?: string): void; // cause is for events and the death message
	heal(amount: number): void;
}

Like block components, an effect that lists a component nobody registered stops the server from starting.

Using Effects

/effect <effect> [seconds] gives you one while testing, for 30 seconds unless you say.

Any mod's effects are added to players by id, see Status Effects:

player.add_effect("copper_tools:swiftness", 200, { amplifier: 1 });

The Base Game's Effects

Effect What it does
bworld:speed 20% faster a level.
bworld:slowness 15% slower a level.
bworld:regeneration Heals 1 every 50 ticks, twice as often each level.
bworld:poison Hurts 1 every 25 ticks, twice as often each level. Never kills.
bworld:instant_health Heals 4 at once, doubling each level.
bworld:resistance Takes 20% less damage a level.
bworld:water_breathing Doesn't run out of air under water.

Resistance and water breathing have no components: like in Minecraft, the engine checks for them where damage and air are worked out.