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

import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BedPart;
import net.minecraft.world.level.block.BedBlock;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.block.FurnaceBlock;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.entity.ChestBlockEntity;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.entity.PathfinderMob;
import net.minecraft.world.entity.animal.Cat;

public class CatSitOnBlockGoal extends MoveToBlockGoal {
    private final Cat cat;
    
    public CatSitOnBlockGoal(final Cat ate, final double double2) {
        super(ate, double2, 8);
        this.cat = ate;
    }
    
    @Override
    public boolean canUse() {
        return this.cat.isTame() && !this.cat.isSitting() && super.canUse();
    }
    
    @Override
    public void start() {
        super.start();
        this.cat.getSitGoal().wantToSit(false);
    }
    
    @Override
    public void stop() {
        super.stop();
        this.cat.setSitting(false);
    }
    
    @Override
    public void tick() {
        super.tick();
        this.cat.getSitGoal().wantToSit(false);
        if (!this.isReachedTarget()) {
            this.cat.setSitting(false);
        }
        else if (!this.cat.isSitting()) {
            this.cat.setSitting(true);
        }
    }
    
    @Override
    protected boolean isValidTarget(final LevelReader bjz, final BlockPos fk) {
        if (!bjz.isEmptyBlock(fk.above())) {
            return false;
        }
        final BlockState byj4 = bjz.getBlockState(fk);
        final Block bph5 = byj4.getBlock();
        if (bph5 == Blocks.CHEST) {
            return ChestBlockEntity.getOpenCount(bjz, fk) < 1;
        }
        return (bph5 == Blocks.FURNACE && byj4.<Boolean>getValue((Property<Boolean>)FurnaceBlock.LIT)) || (bph5.is(BlockTags.BEDS) && byj4.<BedPart>getValue(BedBlock.PART) != BedPart.HEAD);
    }
}
