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

import net.minecraft.core.BlockPos;
import java.util.Optional;
import net.minecraft.world.entity.ai.Brain;
import net.minecraft.core.Vec3i;
import net.minecraft.server.level.ServerLevel;
import java.util.Map;
import net.minecraft.core.GlobalPos;
import com.google.common.collect.ImmutableMap;
import net.minecraft.world.entity.ai.memory.MemoryStatus;
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
import net.minecraft.world.entity.LivingEntity;

public class SetHiddenState extends Behavior<LivingEntity> {
    private final int closeEnoughDist;
    private final int stayHiddenTicks;
    private int ticksHidden;
    
    public SetHiddenState(final int integer1, final int integer2) {
        super(ImmutableMap.<MemoryModuleType<GlobalPos>, MemoryStatus>of(MemoryModuleType.HIDING_PLACE, MemoryStatus.VALUE_PRESENT, (MemoryModuleType<GlobalPos>)MemoryModuleType.HEARD_BELL_TIME, MemoryStatus.VALUE_PRESENT));
        this.stayHiddenTicks = integer1 * 20;
        this.ticksHidden = 0;
        this.closeEnoughDist = integer2;
    }
    
    @Override
    protected void start(final ServerLevel zd, final LivingEntity aoy, final long long3) {
        final Brain<?> apr6 = aoy.getBrain();
        final Optional<Long> optional7 = apr6.<Long>getMemory(MemoryModuleType.HEARD_BELL_TIME);
        final boolean boolean8 = optional7.get() + 300L <= long3;
        if (this.ticksHidden > this.stayHiddenTicks || boolean8) {
            apr6.<Long>eraseMemory(MemoryModuleType.HEARD_BELL_TIME);
            apr6.<GlobalPos>eraseMemory(MemoryModuleType.HIDING_PLACE);
            apr6.updateActivityFromSchedule(zd.getDayTime(), zd.getGameTime());
            this.ticksHidden = 0;
            return;
        }
        final BlockPos fu9 = apr6.<GlobalPos>getMemory(MemoryModuleType.HIDING_PLACE).get().pos();
        if (fu9.closerThan(aoy.blockPosition(), this.closeEnoughDist)) {
            ++this.ticksHidden;
        }
    }
}
