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

import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.Block;
import net.minecraft.tags.Tag;
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 aym, final double double2) {
        super(aym, double2, 8);
        this.cat = aym;
    }
    
    @Override
    public boolean canUse() {
        return this.cat.isTame() && !this.cat.isOrderedToSit() && super.canUse();
    }
    
    @Override
    public void start() {
        super.start();
        this.cat.setInSittingPose(false);
    }
    
    @Override
    public void stop() {
        super.stop();
        this.cat.setInSittingPose(false);
    }
    
    @Override
    public void tick() {
        super.tick();
        this.cat.setInSittingPose(this.isReachedTarget());
    }
    
    @Override
    protected boolean isValidTarget(final LevelReader bqd, final BlockPos fu) {
        if (!bqd.isEmptyBlock(fu.above())) {
            return false;
        }
        final BlockState cfj4 = bqd.getBlockState(fu);
        if (cfj4.is(Blocks.CHEST)) {
            return ChestBlockEntity.getOpenCount(bqd, fu) < 1;
        }
        return (cfj4.is(Blocks.FURNACE) && cfj4.<Boolean>getValue((Property<Boolean>)FurnaceBlock.LIT)) || cfj4.is(BlockTags.BEDS, a -> a.<BedPart>getOptionalValue(BedBlock.PART).map(cfx -> cfx != BedPart.HEAD).orElse(true));
    }
}
