// 
// Decompiled by Procyon v0.6.0
// 

package com.hypixel.hytale.server.npc.corecomponents.movement;

import com.hypixel.hytale.math.vector.Vector3d;
import com.hypixel.hytale.server.npc.entities.NPCEntity;
import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
import com.hypixel.hytale.server.npc.movement.controllers.MotionController;
import com.hypixel.hytale.server.npc.movement.controllers.MotionControllerFly;
import com.hypixel.hytale.component.ComponentAccessor;
import com.hypixel.hytale.server.npc.movement.Steering;
import javax.annotation.Nullable;
import com.hypixel.hytale.server.npc.sensorinfo.InfoProvider;
import com.hypixel.hytale.server.npc.role.Role;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import com.hypixel.hytale.component.Ref;
import com.hypixel.hytale.server.npc.corecomponents.builders.BuilderBodyMotionBase;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.npc.corecomponents.movement.builders.BuilderBodyMotionTakeOff;
import com.hypixel.hytale.server.npc.corecomponents.BodyMotionBase;

public class BodyMotionTakeOff extends BodyMotionBase
{
    protected final double jumpSpeed;
    
    public BodyMotionTakeOff(@Nonnull final BuilderBodyMotionTakeOff builderBodyMotionTakeOff) {
        super(builderBodyMotionTakeOff);
        this.jumpSpeed = builderBodyMotionTakeOff.getJumpSpeed();
    }
    
    @Override
    public boolean computeSteering(@Nonnull final Ref<EntityStore> ref, @Nonnull final Role role, @Nullable final InfoProvider sensorInfo, final double dt, @Nonnull final Steering desiredSteering, @Nonnull final ComponentAccessor<EntityStore> componentAccessor) {
        if (!role.getActiveMotionController().matchesType(MotionControllerFly.class)) {
            final TransformComponent transformComponent = componentAccessor.getComponent(ref, TransformComponent.getComponentType());
            assert transformComponent != null;
            final NPCEntity npcComponent = componentAccessor.getComponent(ref, NPCEntity.getComponentType());
            assert npcComponent != null;
            role.setActiveMotionController(ref, npcComponent, "Fly", componentAccessor);
            final Vector3d position = transformComponent.getPosition();
            position.setY(transformComponent.getPosition().getY() + 0.1);
            ((MotionControllerFly)role.getActiveMotionController()).takeOff(ref, this.jumpSpeed, componentAccessor);
        }
        return false;
    }
}
