use of net.tropicraft.core.common.network.MessagePlayerSwimData 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;
}
use of net.tropicraft.core.common.network.MessagePlayerSwimData 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)));
}
Aggregations