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

import net.minecraft.world.entity.Entity;
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.world.entity.ai.memory.MemoryModuleType;
import net.minecraft.world.entity.LivingEntity;

public class Mount<E extends LivingEntity> extends Behavior<E> {
    private final float speedModifier;
    
    public Mount(final float float1) {
        super(ImmutableMap.<MemoryModuleType<PositionTracker>, MemoryStatus>of(MemoryModuleType.LOOK_TARGET, MemoryStatus.REGISTERED, (MemoryModuleType<PositionTracker>)MemoryModuleType.WALK_TARGET, MemoryStatus.VALUE_ABSENT, (MemoryModuleType<PositionTracker>)MemoryModuleType.RIDE_TARGET, MemoryStatus.VALUE_PRESENT));
        this.speedModifier = float1;
    }
    
    @Override
    protected boolean checkExtraStartConditions(final ServerLevel zd, final E aoy) {
        return !aoy.isPassenger();
    }
    
    @Override
    protected void start(final ServerLevel zd, final E aoy, final long long3) {
        if (this.isCloseEnoughToStartRiding(aoy)) {
            aoy.startRiding(this.getRidableEntity(aoy));
        }
        else {
            BehaviorUtils.setWalkAndLookTargetMemories(aoy, this.getRidableEntity(aoy), this.speedModifier, 1);
        }
    }
    
    private boolean isCloseEnoughToStartRiding(final E aoy) {
        return this.getRidableEntity(aoy).closerThan(aoy, 1.0);
    }
    
    private Entity getRidableEntity(final E aoy) {
        return aoy.getBrain().<Entity>getMemory(MemoryModuleType.RIDE_TARGET).get();
    }
}
