package net.minecraft.world.entity.ai.goal;

import java.util.Iterator;
import net.minecraft.util.Mth;
import net.minecraft.tags.FluidTags;
import net.minecraft.world.entity.Entity;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.PathfinderMob;

public class TryFindWaterGoal extends Goal {
    private final PathfinderMob mob;
    
    public TryFindWaterGoal(final PathfinderMob alg) {
        this.mob = alg;
    }
    
    @Override
    public boolean canUse() {
        return this.mob.onGround && !this.mob.level.getFluidState(new BlockPos(this.mob)).is(FluidTags.WATER);
    }
    
    @Override
    public void start() {
        BlockPos fk2 = null;
        final Iterable<BlockPos> iterable3 = BlockPos.betweenClosed(Mth.floor(this.mob.getX() - 2.0), Mth.floor(this.mob.getY() - 2.0), Mth.floor(this.mob.getZ() - 2.0), Mth.floor(this.mob.getX() + 2.0), Mth.floor(this.mob.getY()), Mth.floor(this.mob.getZ() + 2.0));
        for (final BlockPos fk3 : iterable3) {
            if (this.mob.level.getFluidState(fk3).is(FluidTags.WATER)) {
                fk2 = fk3;
                break;
            }
        }
        if (fk2 != null) {
            this.mob.getMoveControl().setWantedPosition(fk2.getX(), fk2.getY(), fk2.getZ(), 1.0);
        }
    }
}
