DragonTakeoffPhase .java

net.minecraft.world.entity.boss.enderdragon.phases.DragonTakeoffPhase (class, 88 lines): members: firstTick, currentPath, targetLocation, doServerTick.

net.minecraft.world.entity.boss.enderdragon.phasesclass88 linescommonextends AbstractDragonPhaseInstance2.6 KB

API Surface (3)

void doServerTick(final ServerLevel level)
void begin()
EnderDragonPhase<DragonTakeoffPhase> getPhase()

Fields & Constants (3)

firstTick
currentPath
targetLocation

Full Source

DragonTakeoffPhase.java88 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.Vec3i;
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.level.pathfinder.Path;
10
import net.minecraft.world.phys.Vec3;
11
import org.jspecify.annotations.Nullable;
12
13
public class DragonTakeoffPhase extends AbstractDragonPhaseInstance {
14
	private boolean firstTick;
15
	private @Nullable Path currentPath;
16
	private @Nullable Vec3 targetLocation;
17
18
	public DragonTakeoffPhase(final EnderDragon dragon) {
19
		super(dragon);
20
	}
21
22
	@Override
23
	public void doServerTick(final ServerLevel level) {
24
		if (!this.firstTick && this.currentPath != null) {
25
			BlockPos egg = level.getHeightmapPos(Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, EnderDragonFight.getPodiumLocation(this.dragon.getFightOrigin()));
26
			if (!egg.closerToCenterThan(this.dragon.position(), 10.0)) {
27
				this.dragon.getPhaseManager().setPhase(EnderDragonPhase.HOLDING_PATTERN);
28
			}
29
		} else {
30
			this.firstTick = false;
31
			this.findNewTarget();
32
		}
33
	}
34
35
	@Override
36
	public void begin() {
37
		this.firstTick = true;
38
		this.currentPath = null;
39
		this.targetLocation = null;
40
	}
41
42
	private void findNewTarget() {
43
		int currentNodeIndex = this.dragon.findClosestNode();
44
		Vec3 lookVector = this.dragon.getHeadLookVector(1.0F);
45
		int targetNodeIndex = this.dragon.findClosestNode(-lookVector.x * 40.0, 105.0, -lookVector.z * 40.0);
46
		if (this.dragon.getDragonFight() != null && this.dragon.getDragonFight().aliveCrystals() > 0) {
47
			targetNodeIndex %= 12;
48
			if (targetNodeIndex < 0) {
49
				targetNodeIndex += 12;
50
			}
51
		} else {
52
			targetNodeIndex -= 12;
53
			targetNodeIndex &= 7;
54
			targetNodeIndex += 12;
55
		}
56
57
		this.currentPath = this.dragon.findPath(currentNodeIndex, targetNodeIndex, null);
58
		this.navigateToNextPathNode();
59
	}
60
61
	private void navigateToNextPathNode() {
62
		if (this.currentPath != null) {
63
			this.currentPath.advance();
64
			if (!this.currentPath.isDone()) {
65
				Vec3i current = this.currentPath.getNextNodePos();
66
				this.currentPath.advance();
67
68
				double yTarget;
69
				do {
70
					yTarget = current.getY() + this.dragon.getRandom().nextFloat() * 20.0F;
71
				} while (yTarget < current.getY());
72
73
				this.targetLocation = new Vec3(current.getX(), yTarget, current.getZ());
74
			}
75
		}
76
	}
77
78
	@Override
79
	public @Nullable Vec3 getFlyTargetLocation() {
80
		return this.targetLocation;
81
	}
82
83
	@Override
84
	public EnderDragonPhase<DragonTakeoffPhase> getPhase() {
85
		return EnderDragonPhase.TAKEOFF;
86
	}
87
}
88

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