package gr8pefish.openglider.common.helper;

import gr8pefish.openglider.common.item.ItemHangGlider;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;

public class OpenGliderPlayerHelper {

    /**
     * Updates the position of the player when gliding.
     * Glider is assumed to be deployed already.
     *
     * @param player - the player
     */
    public static void updatePosition(EntityPlayer player){

        if (shouldBeGliding(player)) {
            if (player.motionY < 0) {
                final double horizontalSpeed;
                final double verticalSpeed;

                //ToDo: tweak speeds/make sure okay (change with tiers)
                if (player.isSneaking()) {
                    horizontalSpeed = 0.1;
                    verticalSpeed = 0.8;
                } else {
                    horizontalSpeed = 0.03;
                    verticalSpeed = 0.5;
                }

                player.motionY *= verticalSpeed;
                double x = Math.cos(Math.toRadians(player.rotationYawHead + 90)) * horizontalSpeed;
                double z = Math.sin(Math.toRadians(player.rotationYawHead + 90)) * horizontalSpeed;
                player.motionX += x;
                player.motionZ += z;
                player.fallDistance = 0f; /* Don't like getting hurt :( */
            }

            //no wild arm swinging while flying
            if (player.worldObj.isRemote) {
                player.limbSwing = 0;
                player.limbSwingAmount = 0;
            }
        }

    }

    public static boolean shouldBeGliding(EntityPlayer player){
        if (player == null || player.isDead) return false;
        ItemStack held = player.getHeldItem(EnumHand.MAIN_HAND);
        if (held == null || !(held.getItem() instanceof ItemHangGlider)) return false; //ToDo: Remove at some point? (some upgrade/better tier?)
        if (player.onGround || player.isInWater()) return false;
        return true;

    }
}

@@ -38,16 +38,88 @@
 elper;%0A%0A
+import gr8pefish.openglider.common.capabilities.OpenGliderCapabilities;%0A
 import g
@@ -481,16 +481,24 @@
 e player
+ gliding
 %0A     */
@@ -798,16 +798,35 @@
 h tiers)
+, make configurable
 %0A       
@@ -905,9 +905,10 @@
 = 0.
-1
+09
 ;%0A  
@@ -943,17 +943,17 @@
 eed = 0.
-8
+7
 ;%0A      
@@ -1016,9 +1016,9 @@
  0.0
-3
+2
 ;%0A  
@@ -1809,32 +1809,34 @@
 ) return false;%0A
+//
         ItemStac
@@ -1884,16 +1884,18 @@
 _HAND);%0A
+//
         
@@ -1985,14 +1985,16 @@
 Do: 
-Remove
+Add back
  at 
@@ -2008,36 +2008,8 @@
 int?
- (some upgrade/better tier?)
 %0A   

Remove mandatory item holding while flying