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> aku, final Level bjw) {
        super(aku, bjw);
    }
    
    public float getWalkTargetValue(final BlockPos fk) {
        return this.getWalkTargetValue(fk, this.level);
    }
    
    public float getWalkTargetValue(final BlockPos fk, final LevelReader bjz) {
        return 0.0f;
    }
    
    @Override
    public boolean checkSpawnRules(final LevelAccessor bjx, final MobSpawnType alc) {
        return this.getWalkTargetValue(new BlockPos(this), bjx) >= 0.0f;
    }
    
    public boolean isPathFinding() {
        return !this.getNavigation().isDone();
    }
    
    @Override
    protected void tickLeash() {
        super.tickLeash();
        final Entity akq2 = this.getLeashHolder();
        if (akq2 != null && akq2.level == this.level) {
            this.restrictTo(new BlockPos(akq2), 5);
            final float float3 = this.distanceTo(akq2);
            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 = (akq2.getX() - this.getX()) / float3;
                final double double5 = (akq2.getY() - this.getY()) / float3;
                final double double6 = (akq2.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 cvl5 = new Vec3(akq2.getX() - this.getX(), akq2.getY() - this.getY(), akq2.getZ() - this.getZ()).normalize().scale(Math.max(float3 - 2.0f, 0.0f));
                this.getNavigation().moveTo(this.getX() + cvl5.x, this.getY() + cvl5.y, this.getZ() + cvl5.z, this.followLeashSpeed());
            }
        }
    }
    
    protected double followLeashSpeed() {
        return 1.0;
    }
    
    protected void onLeashDistance(final float float1) {
    }
}
