Swim .java

net.minecraft.world.entity.ai.behavior.Swim (class): members: chance, fluid, checkExtraStartConditions, canStillUse, tick. imports: Fluid, FluidTags, Mob.

net.minecraft.world.entity.ai.behaviorclass38 linescommonextends Mob>1.1 KB

API Surface (3)

boolean checkExtraStartConditions(final ServerLevel level, final Mob body)
boolean canStillUse(final ServerLevel level, final Mob body, final long timestamp)
void tick(final ServerLevel level, final Mob body, final long timestamp)

Fields & Constants (2)

chance
fluid

Code Graph: Dependencies (6)

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

Full Source

Swim.java38 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity.ai.behavior;
2
3
import com.google.common.collect.ImmutableMap;
4
import net.minecraft.server.level.ServerLevel;
5
import net.minecraft.tags.FluidTags;
6
import net.minecraft.tags.TagKey;
7
import net.minecraft.world.entity.Mob;
8
import net.minecraft.world.level.material.Fluid;
9
10
public class Swim<T extends Mob> extends Behavior<T> {
11
	private final float chance;
12
	private final TagKey<Fluid> fluid;
13
14
	public Swim(final float chance) {
15
		this(chance, FluidTags.ENTITY_FLOATABLE);
16
	}
17
18
	public Swim(final float chance, final TagKey<Fluid> fluid) {
19
		super(ImmutableMap.of());
20
		this.chance = chance;
21
		this.fluid = fluid;
22
	}
23
24
	protected boolean checkExtraStartConditions(final ServerLevel level, final Mob body) {
25
		return body.isInFluidDeeperThan(body.getFluidJumpThreshold(), this.fluid) || body.isInLava();
26
	}
27
28
	protected boolean canStillUse(final ServerLevel level, final Mob body, final long timestamp) {
29
		return this.checkExtraStartConditions(level, body);
30
	}
31
32
	protected void tick(final ServerLevel level, final Mob body, final long timestamp) {
33
		if (body.getRandom().nextFloat() < this.chance) {
34
			body.getJumpControl().jump();
35
		}
36
	}
37
}
38

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