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

import java.util.Iterator;
import net.minecraft.core.BlockPos;
import net.minecraft.util.Mth;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.tags.Tag;
import net.minecraft.tags.FluidTags;
import net.minecraft.world.entity.PathfinderMob;

public class TryFindWaterGoal extends Goal {
    private final PathfinderMob mob;
    
    public TryFindWaterGoal(final PathfinderMob apg) {
        this.mob = apg;
    }
    
    @Override
    public boolean canUse() {
        return this.mob.isOnGround() && !this.mob.level.getFluidState(this.mob.blockPosition()).is(FluidTags.WATER);
    }
    
    @Override
    public void start() {
        BlockPos fu2 = 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 fu3 : iterable3) {
            if (this.mob.level.getFluidState(fu3).is(FluidTags.WATER)) {
                fu2 = fu3;
                break;
            }
        }
        if (fu2 != null) {
            this.mob.getMoveControl().setWantedPosition(fu2.getX(), fu2.getY(), fu2.getZ(), 1.0);
        }
    }
}
