BreathAirGoal .java

net.minecraft.world.entity.ai.goal.BreathAirGoal (class): members: isInterruptable, canContinueToUse, mob, canUse, start, tick. imports: MoverType, Blocks.

net.minecraft.world.entity.ai.goalclass72 linescommonextends Goal2.0 KB

API Surface (5)

boolean canUse()
boolean canContinueToUse()
boolean isInterruptable()
void start()
void tick()

Fields & Constants (1)

mob

Code Graph: Dependencies (9)

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

Full Source

BreathAirGoal.java72 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity.ai.goal;
2
3
import java.util.EnumSet;
4
import net.minecraft.core.BlockPos;
5
import net.minecraft.world.entity.MoverType;
6
import net.minecraft.world.entity.PathfinderMob;
7
import net.minecraft.world.level.LevelReader;
8
import net.minecraft.world.level.block.Blocks;
9
import net.minecraft.world.level.block.state.BlockState;
10
import net.minecraft.world.level.pathfinder.PathComputationType;
11
import net.minecraft.world.phys.Vec3;
12
13
public class BreathAirGoal extends Goal {
14
	private final PathfinderMob mob;
15
16
	public BreathAirGoal(final PathfinderMob mob) {
17
		this.mob = mob;
18
		this.setFlags(EnumSet.of(Goal.Flag.MOVE, Goal.Flag.LOOK));
19
	}
20
21
	@Override
22
	public boolean canUse() {
23
		return this.mob.getAirSupply() < 140;
24
	}
25
26
	@Override
27
	public boolean canContinueToUse() {
28
		return this.canUse();
29
	}
30
31
	@Override
32
	public boolean isInterruptable() {
33
		return false;
34
	}
35
36
	@Override
37
	public void start() {
38
		this.mob.getNavigation().stop();
39
		this.findAirPosition();
40
	}
41
42
	private void findAirPosition() {
43
		Iterable<BlockPos> between = BlockPos.neighborColumn(this.mob.getBlockX(), this.mob.getBlockY(), this.mob.getBlockZ(), this.mob.getBlockY() + 8);
44
		BlockPos destinationPos = null;
45
46
		for (BlockPos pos : between) {
47
			if (this.givesAir(this.mob.level(), pos)) {
48
				destinationPos = pos;
49
				break;
50
			}
51
		}
52
53
		if (destinationPos == null) {
54
			destinationPos = BlockPos.containing(this.mob.getX(), this.mob.getY() + 8.0, this.mob.getZ());
55
		}
56
57
		this.mob.getNavigation().moveTo(destinationPos.getX(), destinationPos.getY() + 1, destinationPos.getZ(), 1.0);
58
	}
59
60
	@Override
61
	public void tick() {
62
		this.findAirPosition();
63
		this.mob.moveRelative(0.02F, new Vec3(this.mob.xxa, this.mob.yya, this.mob.zza));
64
		this.mob.move(MoverType.SELF, this.mob.getDeltaMovement());
65
	}
66
67
	private boolean givesAir(final LevelReader level, final BlockPos pos) {
68
		BlockState state = level.getBlockState(pos);
69
		return (level.getFluidState(pos).isEmpty() || state.is(Blocks.BUBBLE_COLUMN)) && state.isPathfindable(PathComputationType.LAND);
70
	}
71
}
72

Decompiled Minecraft 26.3 source of BreathAirGoal (net/minecraft/world/entity/ai/goal/BreathAirGoal.java) with Mojang official mappings, stored verbatim on the site.