Search in sources :

Example 6 with PlayerSwimData

use of net.tropicraft.core.common.network.MessagePlayerSwimData.PlayerSwimData in project Tropicraft by Tropicraft.

the class ScubaHandler method updateSwimRenderAngles.

public void updateSwimRenderAngles(EntityPlayer p) {
    PlayerSwimData d = getData(p);
    float ps = SWIM_SPEED_ROTATE_PITCH;
    float ys = SWIM_SPEED_ROTATE_YAW;
    float rs = SWIM_SPEED_ROTATE_ROLL;
    boolean liquidAbove = isInWater(p, 0, 1.4D, 0);
    boolean inLiquid = isInWater(p);
    if (inLiquid && liquidAbove) {
        d.targetRotationYaw = p.rotationYaw;
        d.targetHeadPitchOffset = 45f;
        float t = (float) p.moveStrafing * 90;
        if (p.moveStrafing != 0) {
            if (p.moveForward != 0f) {
                t = (float) p.moveStrafing * 45;
            }
            d.targetRotationYaw -= t;
        }
        // Not moving, level out
        if (!isPlayerWearingFlippers(p)) {
            if (p.moveForward == 0f && d.targetSwimSpeed == 0f) {
                d.targetRotationPitch = p.rotationPitch + 90f;
                d.targetHeadPitchOffset = d.targetRotationPitch;
                if (d.targetHeadPitchOffset > 55) {
                    d.targetHeadPitchOffset = 55f;
                }
            }
        }
        if (d.targetRotationRoll != 0) {
            d.targetRotationPitch -= 180f;
        }
        if (GameSettings.isKeyDown(Minecraft.getMinecraft().gameSettings.keyBindJump) && p.equals(Minecraft.getMinecraft().player)) {
            d.targetSwimSpeed = getFlipperSpeed(p);
            d.targetRotationPitch = 0f;
            d.targetHeadPitchOffset = 45f;
        }
        if (GameSettings.isKeyDown(Minecraft.getMinecraft().gameSettings.keyBindSneak) && p.equals(Minecraft.getMinecraft().player)) {
            d.targetSwimSpeed = getFlipperSpeed(p);
            d.targetRotationPitch = 180f;
            d.targetHeadPitchOffset = 45f;
        }
        d.targetRotationPitch += d.targetRotationRoll * 2f;
        // Backpaddle body and head adjustments
        if (p.moveForward < 0f) {
            d.targetRotationPitch = p.rotationPitch - 65f;
            d.targetHeadPitchOffset = p.rotationPitch - 45f;
        }
        // Full speed ahead cap'n
        if (p.moveForward > 0f) {
            d.targetRotationPitch = p.rotationPitch + 90f;
            d.targetHeadPitchOffset = p.rotationPitch + 90f;
            if (d.targetHeadPitchOffset > 90f) {
                d.targetHeadPitchOffset = 90f;
            }
        }
        // If moving sideways, look ahead
        if (p.moveStrafing != 0) {
            if (p.moveForward == 0f) {
                d.targetHeadPitchOffset = p.rotationPitch + 55f;
            } else {
                d.targetHeadPitchOffset = (p.rotationPitch + 55f);
            }
        }
        // Above a floor and not attempting to move
        if ((!isInWater(p, 0, -1.8D, 0) && d.targetSwimSpeed == 0f && !isPlayerWearingFlippers(p))) {
            d.targetRotationPitch = 0f;
            d.targetHeadPitchOffset = 0f;
            d.targetRotationRoll = 0f;
            ps = ps * 4;
            rs = rs * 4;
            ys = ys * 4;
        }
    } else {
        d.targetRotationPitch = 0f;
        d.targetRotationRoll = 0f;
        d.targetHeadPitchOffset = d.targetHeadPitchOffset * 0.8f;
        d.targetRotationYaw = p.rotationYaw;
        ps = ps * 4;
        rs = rs * 4;
        ys = ys * 4;
    }
    d.currentRotationPitch = lerp(MathHelper.wrapDegrees(d.currentRotationPitch), MathHelper.wrapDegrees(d.targetRotationPitch), ps);
    d.currentHeadPitchOffset = lerp(MathHelper.wrapDegrees(d.currentHeadPitchOffset), MathHelper.wrapDegrees(d.targetHeadPitchOffset), ps);
    d.currentRotationYaw = lerp(d.currentRotationYaw, d.targetRotationYaw, ys);
    d.currentRotationRoll = lerp(d.currentRotationRoll, d.targetRotationRoll, rs);
}
Also used : MessagePlayerSwimData(net.tropicraft.core.common.network.MessagePlayerSwimData) PlayerSwimData(net.tropicraft.core.common.network.MessagePlayerSwimData.PlayerSwimData)

Example 7 with PlayerSwimData

use of net.tropicraft.core.common.network.MessagePlayerSwimData.PlayerSwimData in project Tropicraft by Tropicraft.

the class ScubaHandler method restorePlayerRenderAngles.

public void restorePlayerRenderAngles(EntityPlayer p) {
    PlayerSwimData d = getData(p);
    p.rotationYawHead = d.rotationYawHead;
    p.prevRotationYawHead = d.prevRotationYawHead;
    p.rotationYaw = d.rotationYaw;
    p.prevRotationYaw = d.prevRotationYaw;
    p.renderYawOffset = d.renderYawOffset;
    p.prevRenderYawOffset = d.prevRenderYawOffset;
    p.rotationPitch = d.rotationPitch;
    p.prevRotationPitch = d.prevRotationPitch;
}
Also used : MessagePlayerSwimData(net.tropicraft.core.common.network.MessagePlayerSwimData) PlayerSwimData(net.tropicraft.core.common.network.MessagePlayerSwimData.PlayerSwimData)

Example 8 with PlayerSwimData

use of net.tropicraft.core.common.network.MessagePlayerSwimData.PlayerSwimData in project Tropicraft by Tropicraft.

the class ScubaHandler method onTickPlayer.

@SubscribeEvent
public void onTickPlayer(PlayerTickEvent event) {
    if (!event.type.equals(TickEvent.Type.PLAYER))
        return;
    if (event.player != Minecraft.getMinecraft().player) {
        return;
    }
    EntityPlayer p = event.player;
    if (!p.capabilities.isFlying) {
        PlayerSwimData d = getData(p);
        double above = 1.5D;
        if (d.currentRotationPitch != 0) {
            above = 2D;
        }
        boolean liquidAbove = isInWater(p, 0, above, 0);
        boolean inLiquid = isInWater(p) && isInWater(p, 0, -0.5D, 0);
        if (inLiquid && !liquidAbove && d.currentRotationPitch < 45f && d.currentRotationPitch > -15f && (p.posY - (int) p.posY < 0.5f) && isPlayerWearingFlippers(p)) {
            // p.motionY += 0.02f;
            d.targetRotationPitch = 0f;
            if (!inLiquid) {
                p.motionY -= 4f;
            }
        }
        if (inLiquid && liquidAbove && isPlayerWearingFlippers(p)) {
            p.setNoGravity(true);
            d.targetSwimSpeed = 0f;
            if (GameSettings.isKeyDown(Minecraft.getMinecraft().gameSettings.keyBindForward)) {
                d.targetSwimSpeed = getFlipperSpeed(p);
            }
            if (GameSettings.isKeyDown(Minecraft.getMinecraft().gameSettings.keyBindBack)) {
                d.targetSwimSpeed = -getFlipperSpeed(p);
            }
            if (p.moveStrafing != 0) {
                d.targetSwimSpeed = getFlipperSpeed(p) / 2;
            }
            if (d.currentSwimSpeed < d.targetSwimSpeed) {
                d.currentSwimSpeed += SWIM_SPEED_ACCEL;
                if (d.currentSwimSpeed > d.targetSwimSpeed) {
                    d.currentSwimSpeed = d.targetSwimSpeed;
                }
            } else if (d.currentSwimSpeed > d.targetSwimSpeed) {
                d.currentSwimSpeed -= SWIM_SPEED_ACCEL;
                if (d.currentSwimSpeed < d.targetSwimSpeed) {
                    d.currentSwimSpeed = d.targetSwimSpeed;
                }
            }
            float currentSpeed = d.currentSwimSpeed * 0.1f;
            float offset = 0f;
            p.motionX = currentSpeed * Math.sin(-(d.currentRotationYaw + offset) * (Math.PI / 180.0));
            p.motionZ = currentSpeed * Math.cos(-(d.currentRotationYaw + offset) * (Math.PI / 180.0));
            p.motionY = (currentSpeed) * Math.sin((d.currentRotationPitch + d.currentHeadPitchOffset) * (Math.PI / 180.0));
            if (p.isSneaking()) {
                p.setSneaking(false);
                if (p.motionY > -0.2f) {
                    p.motionY -= 0.02f;
                } else {
                    p.motionY = -0.2f;
                }
            }
        } else {
            d.targetSwimSpeed = 0f;
            p.setNoGravity(false);
        }
    }
    TCPacketHandler.sendToServer(new MessagePlayerSwimData(getData(p)));
}
Also used : MessagePlayerSwimData(net.tropicraft.core.common.network.MessagePlayerSwimData) PlayerSwimData(net.tropicraft.core.common.network.MessagePlayerSwimData.PlayerSwimData) EntityPlayer(net.minecraft.entity.player.EntityPlayer) MessagePlayerSwimData(net.tropicraft.core.common.network.MessagePlayerSwimData) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 9 with PlayerSwimData

use of net.tropicraft.core.common.network.MessagePlayerSwimData.PlayerSwimData in project Tropicraft by Tropicraft.

the class ScubaHandlerCommon method onTickPlayer.

@SubscribeEvent
public void onTickPlayer(PlayerTickEvent event) {
    if (!event.type.equals(TickEvent.Type.PLAYER))
        return;
    EntityPlayer p = event.player;
    PlayerSwimData d = getData(p);
    boolean inLiquid = isInWater(p);
    if (event.phase.equals(Phase.END)) {
        if (!inLiquid) {
            if (d.targetHeight == d.currentHeight) {
                float f;
                float f1;
                if (p.isElytraFlying()) {
                    f = 0.6F;
                    f1 = 0.6F;
                } else if (p.isPlayerSleeping()) {
                    f = 0.2F;
                    f1 = 0.2F;
                } else if (p.isSneaking()) {
                    f = 0.6F;
                    f1 = 1.65F;
                } else {
                    f = 0.6F;
                    f1 = 1.8F;
                }
                if (f != 0.3f || f1 != p.height) {
                    AxisAlignedBB axisalignedbb = p.getEntityBoundingBox();
                    axisalignedbb = new AxisAlignedBB(axisalignedbb.minX, axisalignedbb.minY, axisalignedbb.minZ, axisalignedbb.minX + (double) f, axisalignedbb.minY + (double) f1, axisalignedbb.minZ + (double) f);
                    if (!p.world.collidesWithAnyBlock(axisalignedbb)) {
                        this.setPlayerSize(p, f, f1, 0f, f1);
                        d.currentHeight = f1;
                        d.targetHeight = f1;
                    }
                }
                return;
            }
        }
        if (!isInWater(p, 0, -3.2, 0)) {
            // || p.world.getBlockState(bp).getMaterial().isLiquid()) {
            if (!isPlayerWearingFlippers(p)) {
                d.targetHeight = 1.8f;
            }
        } else {
            d.targetHeight = 1.1f;
        }
        if (!isInWater(p, 0, +1.8D, 0)) {
            d.targetHeight = 1.8f;
        }
        if (d.currentHeight < d.targetHeight) {
            d.currentHeight += 0.1f;
            if (d.currentHeight > d.targetHeight) {
                d.currentHeight = d.targetHeight;
            }
        }
        if (d.currentHeight > d.targetHeight) {
            d.currentHeight -= 0.1f;
            if (d.currentHeight < d.targetHeight) {
                d.currentHeight = d.targetHeight;
            }
        }
        setPlayerSize(p, 0.6f, d.currentHeight, rangeMap(d.currentHeight, 0.6f, 1.8f, 1.25f, 0f), 1f);
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) PlayerSwimData(net.tropicraft.core.common.network.MessagePlayerSwimData.PlayerSwimData) EntityPlayer(net.minecraft.entity.player.EntityPlayer) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

PlayerSwimData (net.tropicraft.core.common.network.MessagePlayerSwimData.PlayerSwimData)9 MessagePlayerSwimData (net.tropicraft.core.common.network.MessagePlayerSwimData)8 EntityPlayer (net.minecraft.entity.player.EntityPlayer)4 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)4 EntityTropicraftWaterBase (net.tropicraft.core.common.entity.underdasea.atlantoku.EntityTropicraftWaterBase)2 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 EntityBeachFloat (net.tropicraft.core.common.entity.placeable.EntityBeachFloat)1