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

import java.util.Optional;
import net.minecraft.world.entity.ai.Brain;
import net.minecraft.core.Vec3i;
import net.minecraft.world.entity.Entity;
import net.minecraft.core.BlockPos;
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 xd, final LivingEntity akz, final long long3) {
        final Brain<?> alp6 = akz.getBrain();
        final Optional<Long> optional7 = alp6.<Long>getMemory(MemoryModuleType.HEARD_BELL_TIME);
        final boolean boolean8 = optional7.get() + 300L <= long3;
        if (this.ticksHidden > this.stayHiddenTicks || boolean8) {
            alp6.<Long>eraseMemory(MemoryModuleType.HEARD_BELL_TIME);
            alp6.<GlobalPos>eraseMemory(MemoryModuleType.HIDING_PLACE);
            alp6.updateActivity(xd.getDayTime(), xd.getGameTime());
            this.ticksHidden = 0;
            return;
        }
        final BlockPos fk9 = alp6.<GlobalPos>getMemory(MemoryModuleType.HIDING_PLACE).get().pos();
        if (fk9.closerThan(new BlockPos(akz), this.closeEnoughDist + 1)) {
            ++this.ticksHidden;
        }
    }
}
