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

import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.Brain;
import net.minecraft.server.level.ServerLevel;
import java.util.Map;
import com.google.common.collect.ImmutableMap;
import net.minecraft.world.entity.ai.memory.MemoryStatus;
import net.minecraft.util.IntRange;
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
import java.util.function.Predicate;
import net.minecraft.world.entity.Mob;

public class CopyMemoryWithExpiry<E extends Mob, T> extends Behavior<E> {
    private final Predicate<E> predicate;
    private final MemoryModuleType<? extends T> sourceMemory;
    private final MemoryModuleType<T> targetMemory;
    private final IntRange durationOfCopy;
    
    public CopyMemoryWithExpiry(final Predicate<E> predicate, final MemoryModuleType<? extends T> awp2, final MemoryModuleType<T> awp3, final IntRange adx) {
        super(ImmutableMap.<MemoryModuleType<? extends T>, MemoryStatus>of(awp2, MemoryStatus.VALUE_PRESENT, awp3, MemoryStatus.VALUE_ABSENT));
        this.predicate = predicate;
        this.sourceMemory = awp2;
        this.targetMemory = awp3;
        this.durationOfCopy = adx;
    }
    
    @Override
    protected boolean checkExtraStartConditions(final ServerLevel zd, final E aoz) {
        return this.predicate.test(aoz);
    }
    
    @Override
    protected void start(final ServerLevel zd, final E aoz, final long long3) {
        final Brain<?> apr6 = aoz.getBrain();
        apr6.<T>setMemoryWithExpiry(this.targetMemory, (T)apr6.getMemory(this.sourceMemory).get(), this.durationOfCopy.randomValue(zd.random));
    }
}
