EnderDragonPhaseManager .java

net.minecraft.world.entity.boss.enderdragon.phases.EnderDragonPhaseManager (class): members: getCurrentPhase, currentPhase, setPhase, dragon, phases.

net.minecraft.world.entity.boss.enderdragon.phasesclass51 linescommon1.7 KB

API Surface (3)

void setPhase(final EnderDragonPhase<?> target)
DragonPhaseInstance getCurrentPhase()
<T extends DragonPhaseInstance> T getPhase(final EnderDragonPhase<T> phase)

Fields & Constants (4)

LOGGER
dragon
phases
currentPhase

String literals (2)

"client"
"server"

Code Graph: Dependencies (3)

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

Full Source

EnderDragonPhaseManager.java51 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity.boss.enderdragon.phases;
2
3
import com.mojang.logging.LogUtils;
4
import java.util.Objects;
5
import net.minecraft.world.entity.boss.enderdragon.EnderDragon;
6
import org.jspecify.annotations.Nullable;
7
import org.slf4j.Logger;
8
9
public class EnderDragonPhaseManager {
10
	private static final Logger LOGGER = LogUtils.getLogger();
11
	private final EnderDragon dragon;
12
	private final @Nullable DragonPhaseInstance[] phases = new DragonPhaseInstance[EnderDragonPhase.getCount()];
13
	private @Nullable DragonPhaseInstance currentPhase;
14
15
	public EnderDragonPhaseManager(final EnderDragon dragon) {
16
		this.dragon = dragon;
17
		this.setPhase(EnderDragonPhase.HOVERING);
18
	}
19
20
	public void setPhase(final EnderDragonPhase<?> target) {
21
		if (this.currentPhase == null || target != this.currentPhase.getPhase()) {
22
			if (this.currentPhase != null) {
23
				this.currentPhase.end();
24
			}
25
26
			this.currentPhase = this.getPhase((EnderDragonPhase<DragonPhaseInstance>)target);
27
			if (!this.dragon.level().isClientSide()) {
28
				this.dragon.getEntityData().set(EnderDragon.DATA_PHASE, target.getId());
29
			}
30
31
			LOGGER.debug("Dragon is now in phase {} on the {}", target, this.dragon.level().isClientSide() ? "client" : "server");
32
			this.currentPhase.begin();
33
		}
34
	}
35
36
	public DragonPhaseInstance getCurrentPhase() {
37
		return Objects.requireNonNull(this.currentPhase);
38
	}
39
40
	public <T extends DragonPhaseInstance> T getPhase(final EnderDragonPhase<T> phase) {
41
		int id = phase.getId();
42
		DragonPhaseInstance phaseInstance = this.phases[id];
43
		if (phaseInstance == null) {
44
			phaseInstance = phase.createInstance(this.dragon);
45
			this.phases[id] = phaseInstance;
46
		}
47
48
		return (T)phaseInstance;
49
	}
50
}
51

Decompiled Minecraft 26.3 source of EnderDragonPhaseManager (net/minecraft/world/entity/boss/enderdragon/phases/EnderDragonPhaseManager.java) with Mojang official mappings, stored verbatim on the site.