TryFindLiquidGoal .java

net.minecraft.world.entity.ai.goal.TryFindLiquidGoal (class, 46 lines): members: fluidTag, mob, canUse, start. imports: Fluid, PathfinderMob, TagKey, Mth.

net.minecraft.world.entity.ai.goalclass46 linescommonextends Goal1.2 KB

API Surface (2)

boolean canUse()
void start()

Fields & Constants (2)

mob
fluidTag

Code Graph: Dependencies (6)

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

Full Source

TryFindLiquidGoal.java46 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity.ai.goal;
2
3
import net.minecraft.core.BlockPos;
4
import net.minecraft.tags.TagKey;
5
import net.minecraft.util.Mth;
6
import net.minecraft.world.entity.PathfinderMob;
7
import net.minecraft.world.level.material.Fluid;
8
9
public class TryFindLiquidGoal extends Goal {
10
	private final PathfinderMob mob;
11
	private final TagKey<Fluid> fluidTag;
12
13
	public TryFindLiquidGoal(final PathfinderMob mob, final TagKey<Fluid> fluidTag) {
14
		this.mob = mob;
15
		this.fluidTag = fluidTag;
16
	}
17
18
	@Override
19
	public boolean canUse() {
20
		return this.mob.onGround() && !this.mob.level().getFluidState(this.mob.blockPosition()).is(this.fluidTag);
21
	}
22
23
	@Override
24
	public void start() {
25
		BlockPos fluidPos = null;
26
27
		for (BlockPos pos : BlockPos.betweenClosed(
28
			Mth.floor(this.mob.getX() - 2.0),
29
			Mth.floor(this.mob.getY() - 2.0),
30
			Mth.floor(this.mob.getZ() - 2.0),
31
			Mth.floor(this.mob.getX() + 2.0),
32
			this.mob.getBlockY(),
33
			Mth.floor(this.mob.getZ() + 2.0)
34
		)) {
35
			if (this.mob.level().getFluidState(pos).is(this.fluidTag)) {
36
				fluidPos = pos;
37
				break;
38
			}
39
		}
40
41
		if (fluidPos != null) {
42
			this.mob.getMoveControl().setWantedPosition(fluidPos.getX(), fluidPos.getY(), fluidPos.getZ(), 1.0);
43
		}
44
	}
45
}
46

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