package net.minecraft.world.entity.boss.enderdragon.phases; import com.mojang.logging.LogUtils; import net.minecraft.world.entity.boss.enderdragon.EnderDragon; import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; public class EnderDragonPhaseManager { private static final Logger LOGGER = LogUtils.getLogger(); private final EnderDragon dragon; private final DragonPhaseInstance[] phases = new DragonPhaseInstance[EnderDragonPhase.getCount()]; @Nullable private DragonPhaseInstance currentPhase; public EnderDragonPhaseManager(EnderDragon dragon) { this.dragon = dragon; this.setPhase(EnderDragonPhase.HOVERING); } public void setPhase(EnderDragonPhase phase) { if (this.currentPhase == null || phase != this.currentPhase.getPhase()) { if (this.currentPhase != null) { this.currentPhase.end(); } this.currentPhase = this.getPhase((EnderDragonPhase)phase); if (!this.dragon.level().isClientSide) { this.dragon.getEntityData().set(EnderDragon.DATA_PHASE, phase.getId()); } LOGGER.debug("Dragon is now in phase {} on the {}", phase, this.dragon.level().isClientSide ? "client" : "server"); this.currentPhase.begin(); } } public DragonPhaseInstance getCurrentPhase() { return this.currentPhase; } public T getPhase(EnderDragonPhase phase) { int i = phase.getId(); if (this.phases[i] == null) { this.phases[i] = phase.createInstance(this.dragon); } return (T)this.phases[i]; } }