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

import net.minecraft.world.entity.ai.targeting.TargetingConditions;
import java.util.EnumSet;
import net.minecraft.world.entity.ai.goal.Goal;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.TamableAnimal;

public class OwnerHurtTargetGoal extends TargetGoal {
    private final TamableAnimal tameAnimal;
    private LivingEntity ownerLastHurt;
    private int timestamp;
    
    public OwnerHurtTargetGoal(final TamableAnimal alo) {
        super(alo, false);
        this.tameAnimal = alo;
        this.setFlags(EnumSet.<Flag>of(Flag.TARGET));
    }
    
    @Override
    public boolean canUse() {
        if (!this.tameAnimal.isTame() || this.tameAnimal.isSitting()) {
            return false;
        }
        final LivingEntity akz2 = this.tameAnimal.getOwner();
        if (akz2 == null) {
            return false;
        }
        this.ownerLastHurt = akz2.getLastHurtMob();
        final int integer3 = akz2.getLastHurtMobTimestamp();
        return integer3 != this.timestamp && this.canAttack(this.ownerLastHurt, TargetingConditions.DEFAULT) && this.tameAnimal.wantsToAttack(this.ownerLastHurt, akz2);
    }
    
    @Override
    public void start() {
        this.mob.setTarget(this.ownerLastHurt);
        final LivingEntity akz2 = this.tameAnimal.getOwner();
        if (akz2 != null) {
            this.timestamp = akz2.getLastHurtMobTimestamp();
        }
        super.start();
    }
}
