Search in sources :

Example 1 with MovementInput

use of net.minecraft.util.MovementInput in project ConvenientAdditions by Necr0.

the class EventHandlerPlayerMovement method onClientUpdate.

@SubscribeEvent
@SideOnly(Side.CLIENT)
public void onClientUpdate(TickEvent.ClientTickEvent event) {
    EntityPlayerSP player = Helper.getClientPlayer();
    if (player == null || event.phase != TickEvent.Phase.START)
        return;
    MovementInput input = player.movementInput;
    if (!wasJumping && input.jump) {
        MinecraftForge.EVENT_BUS.post(new PlayerMovementEvent.PlayerJumpEvent(player, player.getEntityWorld()));
    }
    if (!wasSneaking && input.sneak) {
        MinecraftForge.EVENT_BUS.post(new PlayerMovementEvent.PlayerSneakEvent(player, player.getEntityWorld()));
    }
    wasJumping = input.jump;
    wasSneaking = input.sneak;
}
Also used : PlayerMovementEvent(convenientadditions.api.event.PlayerMovementEvent) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) MovementInput(net.minecraft.util.MovementInput) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 2 with MovementInput

use of net.minecraft.util.MovementInput in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class EntityDraggable method tickAddedVelocity.

//TODO: Finishme
public void tickAddedVelocity() {
    if (worldBelowFeet != null && !ValkyrienWarfareMod.physicsManager.isEntityFixed(draggableAsEntity)) {
        CoordTransformObject coordTransform = worldBelowFeet.wrapping.coordTransform;
        float rotYaw = draggableAsEntity.rotationYaw;
        float rotPitch = draggableAsEntity.rotationPitch;
        float prevYaw = draggableAsEntity.prevRotationYaw;
        float prevPitch = draggableAsEntity.prevRotationPitch;
        Vector oldPos = new Vector(draggableAsEntity);
        RotationMatrices.applyTransform(coordTransform.prevwToLTransform, coordTransform.prevWToLRotation, draggableAsEntity);
        RotationMatrices.applyTransform(coordTransform.lToWTransform, coordTransform.lToWRotation, draggableAsEntity);
        Vector newPos = new Vector(draggableAsEntity);
        //Move the entity back to its old position, the added velocity will be used afterwards
        draggableAsEntity.setPosition(oldPos.X, oldPos.Y, oldPos.Z);
        Vector addedVel = oldPos.getSubtraction(newPos);
        velocityAddedToPlayer = addedVel;
        draggableAsEntity.rotationYaw = rotYaw;
        draggableAsEntity.rotationPitch = rotPitch;
        draggableAsEntity.prevRotationYaw = prevYaw;
        draggableAsEntity.prevRotationPitch = prevPitch;
        Vector oldLookingPos = new Vector(draggableAsEntity.getLook(1.0F));
        RotationMatrices.applyTransform(coordTransform.prevWToLRotation, oldLookingPos);
        RotationMatrices.applyTransform(coordTransform.lToWRotation, oldLookingPos);
        double newPitch = Math.asin(oldLookingPos.Y) * -180D / Math.PI;
        double f4 = -Math.cos(-newPitch * 0.017453292D);
        double radianYaw = Math.atan2((oldLookingPos.X / f4), (oldLookingPos.Z / f4));
        radianYaw += Math.PI;
        radianYaw *= -180D / Math.PI;
        if (!(Double.isNaN(radianYaw) || Math.abs(newPitch) > 85)) {
            double wrappedYaw = MathHelper.wrapDegrees(radianYaw);
            double wrappedRotYaw = MathHelper.wrapDegrees(draggableAsEntity.rotationYaw);
            double yawDif = wrappedYaw - wrappedRotYaw;
            if (Math.abs(yawDif) > 180D) {
                if (yawDif < 0) {
                    yawDif += 360D;
                } else {
                    yawDif -= 360D;
                }
            }
            yawDif %= 360D;
            final double threshold = .1D;
            if (Math.abs(yawDif) < threshold) {
                yawDif = 0D;
            }
            yawDifVelocity = yawDif;
        }
    }
    boolean onGroundOrig = draggableAsEntity.onGround;
    if (!ValkyrienWarfareMod.physicsManager.isEntityFixed(draggableAsEntity)) {
        float originalWalked = draggableAsEntity.distanceWalkedModified;
        float originalWalkedOnStep = draggableAsEntity.distanceWalkedOnStepModified;
        boolean originallySneaking = draggableAsEntity.isSneaking();
        draggableAsEntity.setSneaking(false);
        if (draggableAsEntity.worldObj.isRemote && draggableAsEntity instanceof EntityPlayerSP) {
            EntityPlayerSP playerSP = (EntityPlayerSP) draggableAsEntity;
            MovementInput moveInput = playerSP.movementInput;
            originallySneaking = moveInput.sneak;
            moveInput.sneak = false;
        }
        draggableAsEntity.moveEntity(velocityAddedToPlayer.X, velocityAddedToPlayer.Y, velocityAddedToPlayer.Z);
        if (!(draggableAsEntity instanceof EntityPlayer)) {
            if (draggableAsEntity instanceof EntityArrow) {
                draggableAsEntity.prevRotationYaw = draggableAsEntity.rotationYaw;
                draggableAsEntity.rotationYaw -= yawDifVelocity;
            } else {
                draggableAsEntity.prevRotationYaw = draggableAsEntity.rotationYaw;
                draggableAsEntity.rotationYaw += yawDifVelocity;
            }
        } else {
            if (draggableAsEntity.worldObj.isRemote) {
                draggableAsEntity.prevRotationYaw = draggableAsEntity.rotationYaw;
                draggableAsEntity.rotationYaw += yawDifVelocity;
            }
        }
        //Do not add this movement as if the entity were walking it
        draggableAsEntity.distanceWalkedModified = originalWalked;
        draggableAsEntity.distanceWalkedOnStepModified = originalWalkedOnStep;
        draggableAsEntity.setSneaking(originallySneaking);
        if (draggableAsEntity.worldObj.isRemote && draggableAsEntity instanceof EntityPlayerSP) {
            EntityPlayerSP playerSP = (EntityPlayerSP) draggableAsEntity;
            MovementInput moveInput = playerSP.movementInput;
            moveInput.sneak = originallySneaking;
        }
    }
    if (onGroundOrig) {
        draggableAsEntity.onGround = onGroundOrig;
    }
    velocityAddedToPlayer.multiply(.99D);
    yawDifVelocity *= .95D;
}
Also used : CoordTransformObject(ValkyrienWarfareBase.PhysicsManagement.CoordTransformObject) EntityArrow(net.minecraft.entity.projectile.EntityArrow) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) Vector(ValkyrienWarfareBase.API.Vector) MovementInput(net.minecraft.util.MovementInput)

Aggregations

EntityPlayerSP (net.minecraft.client.entity.EntityPlayerSP)2 MovementInput (net.minecraft.util.MovementInput)2 Vector (ValkyrienWarfareBase.API.Vector)1 CoordTransformObject (ValkyrienWarfareBase.PhysicsManagement.CoordTransformObject)1 PlayerMovementEvent (convenientadditions.api.event.PlayerMovementEvent)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 EntityArrow (net.minecraft.entity.projectile.EntityArrow)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1