Search in sources :

Example 1 with PlayerSwimData

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

the class PlayerSwimDataClientHandler method onMessage.

@Override
public IMessage onMessage(MessagePlayerSwimData message, MessageContext ctx) {
    // We received this on the client, update other player position info
    if (ctx.side.equals(Side.CLIENT)) {
        PlayerSwimData d = message.data;
        if (!ScubaHandler.rotationMap.containsKey(d.playerUUID)) {
            ScubaHandler.rotationMap.put(d.playerUUID, new PlayerSwimData(d.playerUUID));
        }
        PlayerSwimData localData = ScubaHandler.rotationMap.get(d.playerUUID);
        if (d.playerUUID.equals(Minecraft.getMinecraft().player.getUniqueID())) {
            // We don't want to imprint our own movements from the server onto ourselves
            return null;
        }
        localData.rotationYawHead = d.rotationYawHead;
        localData.prevRotationYawHead = d.prevRotationYawHead;
        localData.rotationYaw = d.rotationYaw;
        localData.prevRotationYaw = d.prevRotationYaw;
        localData.renderYawOffset = d.renderYawOffset;
        localData.prevRenderYawOffset = d.prevRenderYawOffset;
        localData.rotationPitch = d.rotationPitch;
        localData.prevRotationPitch = d.prevRotationPitch;
        localData.targetRotationPitch = d.targetRotationPitch;
        localData.targetRotationYaw = d.targetRotationYaw;
        localData.targetRotationRoll = d.targetRotationRoll;
        localData.currentRotationPitch = d.currentRotationPitch;
        localData.currentRotationYaw = d.currentRotationYaw;
        localData.currentRotationRoll = d.currentRotationRoll;
        localData.targetHeadPitchOffset = d.targetHeadPitchOffset;
        localData.currentHeadPitchOffset = d.currentHeadPitchOffset;
        localData.currentSwimSpeed = d.currentSwimSpeed;
        localData.targetSwimSpeed = d.targetSwimSpeed;
    }
    return null;
}
Also used : MessagePlayerSwimData(net.tropicraft.core.common.network.MessagePlayerSwimData) PlayerSwimData(net.tropicraft.core.common.network.MessagePlayerSwimData.PlayerSwimData)

Example 2 with PlayerSwimData

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

the class ScubaHandler method clearPlayerRenderAngles.

public void clearPlayerRenderAngles(EntityPlayer p) {
    PlayerSwimData d = getData(p);
    if (p.isRiding() && p.getRidingEntity() instanceof EntityTropicraftWaterBase) {
        EntityTropicraftWaterBase fish = (EntityTropicraftWaterBase) p.getRidingEntity();
        p.rotationYawHead = fish.rotationYawHead;
        p.prevRotationYawHead = fish.prevRotationYawHead;
    } else {
        p.rotationYawHead = 0f;
        p.prevRotationYawHead = 0f;
        p.rotationYaw = 0f;
        p.prevRotationYaw = 0f;
    }
    p.renderYawOffset = 0f;
    p.prevRenderYawOffset = 0f;
    p.rotationPitch = -MathHelper.wrapDegrees(d.currentHeadPitchOffset);
    p.prevRotationPitch = -MathHelper.wrapDegrees(d.currentHeadPitchOffset);
}
Also used : MessagePlayerSwimData(net.tropicraft.core.common.network.MessagePlayerSwimData) PlayerSwimData(net.tropicraft.core.common.network.MessagePlayerSwimData.PlayerSwimData) EntityTropicraftWaterBase(net.tropicraft.core.common.entity.underdasea.atlantoku.EntityTropicraftWaterBase)

Example 3 with PlayerSwimData

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

the class ScubaHandler method onRenderPlayer.

@SubscribeEvent
public void onRenderPlayer(RenderPlayerEvent.Pre event) {
    if (inGUI) {
        return;
    }
    EntityPlayer p = event.getEntityPlayer();
    PlayerSwimData d = getData(p);
    if (p.isElytraFlying() || p.getRidingEntity() instanceof EntityBeachFloat) {
        return;
    }
    updateSwimRenderAngles(p);
    boolean inLiquid = isInWater(p) && isInWater(p, 0, 0.4D, 0);
    if (inLiquid) {
        if (!p.onGround && isPlayerWearingFlippers(p)) {
            p.limbSwingAmount = 0.2f + (d.currentSwimSpeed / 20);
        }
    } else {
        if (d.currentRotationPitch == 0f && d.currentRotationRoll == 0f) {
            return;
        }
    }
    GlStateManager.pushMatrix();
    boolean isSelf = d.playerUUID.equals(Minecraft.getMinecraft().player.getUniqueID());
    GlStateManager.translate(0, 1.5f, 0f);
    if (p.isRiding() && p.getRidingEntity() instanceof EntityTropicraftWaterBase) {
        d.currentRotationYaw = 0f;
        d.currentRotationRoll = 0f;
        d.currentHeadPitchOffset = 0f;
        d.currentRotationPitch = 0f;
        d.rotationYawHead = 90f;
    }
    if (isSelf) {
        GlStateManager.rotate(d.currentRotationYaw, 0f, -1f, 0f);
        GlStateManager.rotate(d.currentRotationPitch, 1f, 0f, 0f);
        GlStateManager.rotate(d.currentRotationRoll, 0f, 0f, -1f);
    } else {
        GlStateManager.translate(event.getX(), event.getY(), event.getZ());
        GlStateManager.rotate(d.currentRotationYaw, 0f, -1f, 0f);
        GlStateManager.rotate(d.currentRotationPitch, 1f, 0f, 0f);
        GlStateManager.rotate(d.currentRotationRoll, 0f, 0f, -1f);
        GlStateManager.translate(-event.getX(), -event.getY(), -event.getZ());
    }
    GlStateManager.translate(0, -1.5f, 0f);
    updateSwimDataAngles(p);
    clearPlayerRenderAngles(p);
}
Also used : MessagePlayerSwimData(net.tropicraft.core.common.network.MessagePlayerSwimData) PlayerSwimData(net.tropicraft.core.common.network.MessagePlayerSwimData.PlayerSwimData) EntityBeachFloat(net.tropicraft.core.common.entity.placeable.EntityBeachFloat) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityTropicraftWaterBase(net.tropicraft.core.common.entity.underdasea.atlantoku.EntityTropicraftWaterBase) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 4 with PlayerSwimData

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

the class ScubaHandler method onRenderViewTick.

@SubscribeEvent
public void onRenderViewTick(EntityViewRenderEvent.CameraSetup event) {
    if (event.getEntity().equals(Minecraft.getMinecraft().player)) {
        if (Minecraft.getMinecraft().player != null && !Minecraft.getMinecraft().player.isDead) {
            EntityPlayer p = Minecraft.getMinecraft().player;
            PlayerSwimData d = getData(p);
            event.setRoll(-d.currentRotationRoll * 0.25f);
        }
    }
}
Also used : MessagePlayerSwimData(net.tropicraft.core.common.network.MessagePlayerSwimData) PlayerSwimData(net.tropicraft.core.common.network.MessagePlayerSwimData.PlayerSwimData) EntityPlayer(net.minecraft.entity.player.EntityPlayer) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 5 with PlayerSwimData

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

the class ScubaHandler method updateSwimDataAngles.

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

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