mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 03:55:18 -04:00
Immediately update server-side position when TPing player
This commit is contained in:
parent
1ab445d8e5
commit
42d9d82f76
@ -361,26 +361,31 @@ namespace MCGalaxy.Network
|
||||
if (id == Entities.SelfID) pos.Y -= 22;
|
||||
|
||||
Send(Packet.Teleport(id, pos, rot, player.hasExtPositions));
|
||||
DoIgnorePositionPing(id);
|
||||
OnTeleported(id, pos, rot);
|
||||
}
|
||||
public override bool SendTeleport(byte id, Position pos, Orientation rot,
|
||||
Packet.TeleportMoveMode moveMode, bool usePos = true, bool interpolateOri = false, bool useOri = true) {
|
||||
if (!Supports(CpeExt.ExtEntityTeleport)) { return false; }
|
||||
|
||||
bool absoluteSelf = (moveMode == Packet.TeleportMoveMode.AbsoluteInstant ||
|
||||
moveMode == Packet.TeleportMoveMode.AbsoluteSmooth) && id == Entities.SelfID;
|
||||
|
||||
// NOTE: Classic clients require offseting own entity by 22 units vertically when using absolute location updates
|
||||
if ((moveMode == Packet.TeleportMoveMode.AbsoluteInstant ||
|
||||
moveMode == Packet.TeleportMoveMode.AbsoluteSmooth) && id == Entities.SelfID)
|
||||
{ pos.Y -= 22; }
|
||||
if (absoluteSelf) pos.Y -= 22;
|
||||
|
||||
Send(Packet.TeleportExt(id, usePos, moveMode, useOri, interpolateOri, pos, rot, player.hasExtPositions));
|
||||
DoIgnorePositionPing(id);
|
||||
if (absoluteSelf) OnTeleported(id, pos, rot);
|
||||
return true;
|
||||
}
|
||||
void DoIgnorePositionPing(byte id) {
|
||||
if (!hasTwoWayPing || id != Entities.SelfID) { return; }
|
||||
|
||||
void OnTeleported(byte id, Position pos, Orientation rot) {
|
||||
if (id != Entities.SelfID || !hasTwoWayPing) { return; }
|
||||
|
||||
ushort data = Ping.NextTwoWayPingData(true);
|
||||
SendTwoWayPing(data);
|
||||
|
||||
//Update server-side position and check MB/portals/zones
|
||||
player.ProcessMovementCore(pos, rot.RotY, rot.HeadX, false);
|
||||
}
|
||||
|
||||
public override void SendRemoveEntity(byte id) {
|
||||
@ -576,7 +581,7 @@ namespace MCGalaxy.Network
|
||||
} else {
|
||||
Send(Packet.AddEntity(id, name, pos, rot, player.hasCP437, player.hasExtPositions));
|
||||
}
|
||||
DoIgnorePositionPing(id);
|
||||
OnTeleported(id, pos, rot);
|
||||
}
|
||||
|
||||
public override void SendLevel(Level prev, Level level) {
|
||||
|
@ -225,24 +225,37 @@ namespace MCGalaxy
|
||||
if (held >= 0) ClientHeldBlock = (BlockID)held;
|
||||
|
||||
if (Session.Ping.IgnorePosition || Loading) { return; }
|
||||
if (trainGrab || following.Length > 0) { CheckBlocks(Pos, Pos); return; } // Doesn't check zones? Potential bug
|
||||
|
||||
if (trainGrab || following.Length > 0) { CheckBlocks(Pos, Pos); return; }
|
||||
Position next = new Position(x, y, z);
|
||||
ProcessMovementCore(next, yaw, pitch, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called to update player's position and check blocks and zones.
|
||||
/// If fromClient is true, calls OnPlayerMove event and updates AFK status.
|
||||
/// </summary>
|
||||
internal void ProcessMovementCore(Position next, byte yaw, byte pitch, bool fromClient) {
|
||||
|
||||
CheckBlocks(Pos, next);
|
||||
|
||||
bool cancel = false;
|
||||
OnPlayerMoveEvent.Call(this, next, yaw, pitch, ref cancel);
|
||||
if (cancel) { cancel = false; return; }
|
||||
|
||||
if (fromClient) {
|
||||
bool cancel = false;
|
||||
OnPlayerMoveEvent.Call(this, next, yaw, pitch, ref cancel);
|
||||
if (cancel) { cancel = false; return; }
|
||||
}
|
||||
|
||||
Pos = next;
|
||||
SetYawPitch(yaw, pitch);
|
||||
CheckZones(next);
|
||||
|
||||
if (!Moved()) return;
|
||||
if (DateTime.UtcNow < AFKCooldown) return;
|
||||
|
||||
LastAction = DateTime.UtcNow;
|
||||
if (IsAfk) CmdAfk.ToggleAfk(this, "");
|
||||
|
||||
if (fromClient) {
|
||||
if (!Moved()) return;
|
||||
if (DateTime.UtcNow < AFKCooldown) return;
|
||||
|
||||
LastAction = DateTime.UtcNow;
|
||||
if (IsAfk) CmdAfk.ToggleAfk(this, "");
|
||||
}
|
||||
}
|
||||
|
||||
void CheckZones(Position pos) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user