HealOrHarmMobEffect .java

net.minecraft.world.effect.HealOrHarmMobEffect (class): members: isHarm, applyInstantaneousEffect, amplification, serverLevel, applyEffectTick, owner, mob.

net.minecraft.world.effectclass49 linescommonextends InstantaneousMobEffect1.4 KB

API Surface (2)

boolean applyEffectTick(final ServerLevel level, final LivingEntity mob, final int amplification)
void applyInstantaneousEffect(final ServerLevel serverLevel, final @Nullable Entity source, final @Nullable Entity owner, final LivingEntity mob, final int amplification, final double scale)

Fields & Constants (6)

isHarm
serverLevel
source
owner
mob
amplification

Code Graph: Dependencies (5)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

HealOrHarmMobEffect.java49 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.effect;
2
3
import net.minecraft.server.level.ServerLevel;
4
import net.minecraft.world.entity.Entity;
5
import net.minecraft.world.entity.LivingEntity;
6
import org.jspecify.annotations.Nullable;
7
8
class HealOrHarmMobEffect extends InstantaneousMobEffect {
9
	private final boolean isHarm;
10
11
	public HealOrHarmMobEffect(final MobEffectCategory category, final int color, final boolean isHarm) {
12
		super(category, color);
13
		this.isHarm = isHarm;
14
	}
15
16
	@Override
17
	public boolean applyEffectTick(final ServerLevel level, final LivingEntity mob, final int amplification) {
18
		if (this.isHarm == mob.isInvertedHealAndHarm()) {
19
			mob.heal(Math.max(4 << amplification, 0));
20
		} else {
21
			mob.hurtServer(level, mob.damageSources().magic(), 6 << amplification);
22
		}
23
24
		return true;
25
	}
26
27
	@Override
28
	public void applyInstantaneousEffect(
29
		final ServerLevel serverLevel,
30
		final @Nullable Entity source,
31
		final @Nullable Entity owner,
32
		final LivingEntity mob,
33
		final int amplification,
34
		final double scale
35
	) {
36
		if (this.isHarm == mob.isInvertedHealAndHarm()) {
37
			int amount = (int)(scale * (4 << amplification) + 0.5);
38
			mob.heal(amount);
39
		} else {
40
			int amount = (int)(scale * (6 << amplification) + 0.5);
41
			if (source == null) {
42
				mob.hurtServer(serverLevel, mob.damageSources().magic(), amount);
43
			} else {
44
				mob.hurtServer(serverLevel, mob.damageSources().indirectMagic(source, owner), amount);
45
			}
46
		}
47
	}
48
}
49

Decompiled Minecraft 26.3 source of HealOrHarmMobEffect (net/minecraft/world/effect/HealOrHarmMobEffect.java) with Mojang official mappings, stored verbatim on the site.