mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Optimize squid packet sending
Don't send a full MoveEntityAbsolutePacket when we can send a smaller MoveEntityDeltaPacket that only has rotation information.
This commit is contained in:
parent
d7fbdaf93d
commit
41d15f3ec3
1 changed files with 24 additions and 1 deletions
|
@ -27,6 +27,7 @@ package org.geysermc.connector.entity.living;
|
||||||
|
|
||||||
import com.nukkitx.math.vector.Vector3f;
|
import com.nukkitx.math.vector.Vector3f;
|
||||||
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
|
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
|
||||||
|
import com.nukkitx.protocol.bedrock.packet.MoveEntityDeltaPacket;
|
||||||
import org.geysermc.connector.entity.Tickable;
|
import org.geysermc.connector.entity.Tickable;
|
||||||
import org.geysermc.connector.entity.type.EntityType;
|
import org.geysermc.connector.entity.type.EntityType;
|
||||||
import org.geysermc.connector.network.session.GeyserSession;
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
|
@ -49,13 +50,35 @@ public class SquidEntity extends WaterEntity implements Tickable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tick(GeyserSession session) {
|
public void tick(GeyserSession session) {
|
||||||
|
boolean pitchChanged;
|
||||||
|
boolean yawChanged;
|
||||||
|
float oldPitch = pitch;
|
||||||
if (inWater) {
|
if (inWater) {
|
||||||
|
float oldYaw = yaw;
|
||||||
pitch += (targetPitch - pitch) * 0.1f;
|
pitch += (targetPitch - pitch) * 0.1f;
|
||||||
yaw += (targetYaw - yaw) * 0.1f;
|
yaw += (targetYaw - yaw) * 0.1f;
|
||||||
|
yawChanged = oldYaw != yaw;
|
||||||
} else {
|
} else {
|
||||||
pitch += (-90 - pitch) * 0.02f;
|
pitch += (-90 - pitch) * 0.02f;
|
||||||
|
yawChanged = false;
|
||||||
|
}
|
||||||
|
pitchChanged = oldPitch != pitch;
|
||||||
|
|
||||||
|
if (pitchChanged || yawChanged) {
|
||||||
|
MoveEntityDeltaPacket packet = new MoveEntityDeltaPacket();
|
||||||
|
packet.setRuntimeEntityId(geyserId);
|
||||||
|
|
||||||
|
if (pitchChanged) {
|
||||||
|
packet.getFlags().add(MoveEntityDeltaPacket.Flag.HAS_PITCH);
|
||||||
|
packet.setPitch(pitch);
|
||||||
|
}
|
||||||
|
if (yawChanged) {
|
||||||
|
packet.getFlags().add(MoveEntityDeltaPacket.Flag.HAS_YAW);
|
||||||
|
packet.setYaw(yaw);
|
||||||
|
}
|
||||||
|
|
||||||
|
session.sendUpstreamPacket(packet);
|
||||||
}
|
}
|
||||||
super.moveAbsolute(session, position, Vector3f.from(yaw, 0, yaw), onGround, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue