72 lines
2.8 KiB
Java
72 lines
2.8 KiB
Java
package net.minecraft.world.entity;
|
|
|
|
import net.minecraft.world.phys.Vec3;
|
|
import net.minecraft.world.entity.ai.goal.Goal;
|
|
import net.minecraft.world.level.LevelAccessor;
|
|
import net.minecraft.world.level.LevelReader;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.world.level.Level;
|
|
|
|
public abstract class PathfinderMob extends Mob {
|
|
protected PathfinderMob(final EntityType<? extends PathfinderMob> akr, final Level bjt) {
|
|
super(akr, bjt);
|
|
}
|
|
|
|
public float getWalkTargetValue(final BlockPos fk) {
|
|
return this.getWalkTargetValue(fk, this.level);
|
|
}
|
|
|
|
public float getWalkTargetValue(final BlockPos fk, final LevelReader bjw) {
|
|
return 0.0f;
|
|
}
|
|
|
|
@Override
|
|
public boolean checkSpawnRules(final LevelAccessor bju, final MobSpawnType akz) {
|
|
return this.getWalkTargetValue(new BlockPos(this), bju) >= 0.0f;
|
|
}
|
|
|
|
public boolean isPathFinding() {
|
|
return !this.getNavigation().isDone();
|
|
}
|
|
|
|
@Override
|
|
protected void tickLeash() {
|
|
super.tickLeash();
|
|
final Entity akn2 = this.getLeashHolder();
|
|
if (akn2 != null && akn2.level == this.level) {
|
|
this.restrictTo(new BlockPos(akn2), 5);
|
|
final float float3 = this.distanceTo(akn2);
|
|
if (this instanceof TamableAnimal && ((TamableAnimal)this).isSitting()) {
|
|
if (float3 > 10.0f) {
|
|
this.dropLeash(true, true);
|
|
}
|
|
return;
|
|
}
|
|
this.onLeashDistance(float3);
|
|
if (float3 > 10.0f) {
|
|
this.dropLeash(true, true);
|
|
this.goalSelector.disableControlFlag(Goal.Flag.MOVE);
|
|
}
|
|
else if (float3 > 6.0f) {
|
|
final double double4 = (akn2.getX() - this.getX()) / float3;
|
|
final double double5 = (akn2.getY() - this.getY()) / float3;
|
|
final double double6 = (akn2.getZ() - this.getZ()) / float3;
|
|
this.setDeltaMovement(this.getDeltaMovement().add(Math.copySign(double4 * double4 * 0.4, double4), Math.copySign(double5 * double5 * 0.4, double5), Math.copySign(double6 * double6 * 0.4, double6)));
|
|
}
|
|
else {
|
|
this.goalSelector.enableControlFlag(Goal.Flag.MOVE);
|
|
final float float4 = 2.0f;
|
|
final Vec3 cvi5 = new Vec3(akn2.getX() - this.getX(), akn2.getY() - this.getY(), akn2.getZ() - this.getZ()).normalize().scale(Math.max(float3 - 2.0f, 0.0f));
|
|
this.getNavigation().moveTo(this.getX() + cvi5.x, this.getY() + cvi5.y, this.getZ() + cvi5.z, this.followLeashSpeed());
|
|
}
|
|
}
|
|
}
|
|
|
|
protected double followLeashSpeed() {
|
|
return 1.0;
|
|
}
|
|
|
|
protected void onLeashDistance(final float float1) {
|
|
}
|
|
}
|