minecraft-src/net/minecraft/world/entity/ai/goal/WaterAvoidingRandomStrollGoal.java
2025-07-04 01:41:11 +03:00

31 lines
1,022 B
Java

package net.minecraft.world.entity.ai.goal;
import net.minecraft.world.entity.PathfinderMob;
import net.minecraft.world.entity.ai.util.LandRandomPos;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.Nullable;
public class WaterAvoidingRandomStrollGoal extends RandomStrollGoal {
public static final float PROBABILITY = 0.001F;
protected final float probability;
public WaterAvoidingRandomStrollGoal(PathfinderMob mob, double speedModifier) {
this(mob, speedModifier, 0.001F);
}
public WaterAvoidingRandomStrollGoal(PathfinderMob mob, double speedModifier, float probability) {
super(mob, speedModifier);
this.probability = probability;
}
@Nullable
@Override
protected Vec3 getPosition() {
if (this.mob.isInWaterOrBubble()) {
Vec3 vec3 = LandRandomPos.getPos(this.mob, 15, 7);
return vec3 == null ? super.getPosition() : vec3;
} else {
return this.mob.getRandom().nextFloat() >= this.probability ? LandRandomPos.getPos(this.mob, 10, 7) : super.getPosition();
}
}
}