DragonDeathPhase .java

net.minecraft.world.entity.boss.enderdragon.phases.DragonDeathPhase (class, 69 lines): members: doClientTick, getFlySpeed, targetLocation, doServerTick.

net.minecraft.world.entity.boss.enderdragon.phasesclass69 linescommonextends AbstractDragonPhaseInstance2.1 KB

API Surface (5)

void doClientTick()
void doServerTick(final ServerLevel level)
void begin()
float getFlySpeed()
EnderDragonPhase<DragonDeathPhase> getPhase()

Fields & Constants (2)

targetLocation
time

Full Source

DragonDeathPhase.java69 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity.boss.enderdragon.phases;
2
3
import net.minecraft.core.BlockPos;
4
import net.minecraft.core.particles.ParticleTypes;
5
import net.minecraft.server.level.ServerLevel;
6
import net.minecraft.world.entity.boss.enderdragon.EnderDragon;
7
import net.minecraft.world.level.dimension.end.EnderDragonFight;
8
import net.minecraft.world.level.levelgen.Heightmap;
9
import net.minecraft.world.phys.Vec3;
10
import org.jspecify.annotations.Nullable;
11
12
public class DragonDeathPhase extends AbstractDragonPhaseInstance {
13
	private @Nullable Vec3 targetLocation;
14
	private int time;
15
16
	public DragonDeathPhase(final EnderDragon dragon) {
17
		super(dragon);
18
	}
19
20
	@Override
21
	public void doClientTick() {
22
		if (this.time++ % 10 == 0) {
23
			float xo = (this.dragon.getRandom().nextFloat() - 0.5F) * 8.0F;
24
			float yo = (this.dragon.getRandom().nextFloat() - 0.5F) * 4.0F;
25
			float zo = (this.dragon.getRandom().nextFloat() - 0.5F) * 8.0F;
26
			this.dragon
27
				.level()
28
				.addParticle(ParticleTypes.EXPLOSION_EMITTER, this.dragon.getX() + xo, this.dragon.getY() + 2.0 + yo, this.dragon.getZ() + zo, 0.0, 0.0, 0.0);
29
		}
30
	}
31
32
	@Override
33
	public void doServerTick(final ServerLevel level) {
34
		this.time++;
35
		if (this.targetLocation == null) {
36
			BlockPos egg = level.getHeightmapPos(Heightmap.Types.MOTION_BLOCKING, EnderDragonFight.getPodiumLocation(this.dragon.getFightOrigin()));
37
			this.targetLocation = Vec3.atBottomCenterOf(egg);
38
		}
39
40
		double distToTarget = this.targetLocation.distanceToSqr(this.dragon.getX(), this.dragon.getY(), this.dragon.getZ());
41
		if (!(distToTarget < 100.0) && !(distToTarget > 22500.0) && !this.dragon.horizontalCollision && !this.dragon.verticalCollision) {
42
			this.dragon.setHealth(1.0F);
43
		} else {
44
			this.dragon.setHealth(0.0F);
45
		}
46
	}
47
48
	@Override
49
	public void begin() {
50
		this.targetLocation = null;
51
		this.time = 0;
52
	}
53
54
	@Override
55
	public float getFlySpeed() {
56
		return 3.0F;
57
	}
58
59
	@Override
60
	public @Nullable Vec3 getFlyTargetLocation() {
61
		return this.targetLocation;
62
	}
63
64
	@Override
65
	public EnderDragonPhase<DragonDeathPhase> getPhase() {
66
		return EnderDragonPhase.DYING;
67
	}
68
}
69

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