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

import net.minecraft.tags.BlockTags;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.LevelReader;
import java.util.EnumSet;
import net.minecraft.world.entity.PathfinderMob;
import net.minecraft.world.entity.animal.Cat;

public class CatLieOnBedGoal extends MoveToBlockGoal {
    private final Cat cat;
    
    public CatLieOnBedGoal(final Cat ate, final double double2, final int integer) {
        super(ate, double2, integer, 6);
        this.cat = ate;
        this.verticalSearchStart = -2;
        this.setFlags(EnumSet.<Flag>of(Flag.JUMP, Flag.MOVE));
    }
    
    @Override
    public boolean canUse() {
        return this.cat.isTame() && !this.cat.isSitting() && !this.cat.isLying() && super.canUse();
    }
    
    @Override
    public void start() {
        super.start();
        this.cat.getSitGoal().wantToSit(false);
    }
    
    @Override
    protected int nextStartTick(final PathfinderMob alg) {
        return 40;
    }
    
    @Override
    public void stop() {
        super.stop();
        this.cat.setLying(false);
    }
    
    @Override
    public void tick() {
        super.tick();
        this.cat.getSitGoal().wantToSit(false);
        if (!this.isReachedTarget()) {
            this.cat.setLying(false);
        }
        else if (!this.cat.isLying()) {
            this.cat.setLying(true);
        }
    }
    
    @Override
    protected boolean isValidTarget(final LevelReader bjz, final BlockPos fk) {
        return bjz.isEmptyBlock(fk.above()) && bjz.getBlockState(fk).getBlock().is(BlockTags.BEDS);
    }
}
