mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 04:32:50 -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;
|
if (id == Entities.SelfID) pos.Y -= 22;
|
||||||
|
|
||||||
Send(Packet.Teleport(id, pos, rot, player.hasExtPositions));
|
Send(Packet.Teleport(id, pos, rot, player.hasExtPositions));
|
||||||
DoIgnorePositionPing(id);
|
OnTeleported(id, pos, rot);
|
||||||
}
|
}
|
||||||
public override bool SendTeleport(byte id, Position pos, Orientation rot,
|
public override bool SendTeleport(byte id, Position pos, Orientation rot,
|
||||||
Packet.TeleportMoveMode moveMode, bool usePos = true, bool interpolateOri = false, bool useOri = true) {
|
Packet.TeleportMoveMode moveMode, bool usePos = true, bool interpolateOri = false, bool useOri = true) {
|
||||||
if (!Supports(CpeExt.ExtEntityTeleport)) { return false; }
|
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
|
// NOTE: Classic clients require offseting own entity by 22 units vertically when using absolute location updates
|
||||||
if ((moveMode == Packet.TeleportMoveMode.AbsoluteInstant ||
|
if (absoluteSelf) pos.Y -= 22;
|
||||||
moveMode == Packet.TeleportMoveMode.AbsoluteSmooth) && id == Entities.SelfID)
|
|
||||||
{ pos.Y -= 22; }
|
|
||||||
|
|
||||||
Send(Packet.TeleportExt(id, usePos, moveMode, useOri, interpolateOri, pos, rot, player.hasExtPositions));
|
Send(Packet.TeleportExt(id, usePos, moveMode, useOri, interpolateOri, pos, rot, player.hasExtPositions));
|
||||||
DoIgnorePositionPing(id);
|
if (absoluteSelf) OnTeleported(id, pos, rot);
|
||||||
return true;
|
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);
|
ushort data = Ping.NextTwoWayPingData(true);
|
||||||
SendTwoWayPing(data);
|
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) {
|
public override void SendRemoveEntity(byte id) {
|
||||||
@ -576,7 +581,7 @@ namespace MCGalaxy.Network
|
|||||||
} else {
|
} else {
|
||||||
Send(Packet.AddEntity(id, name, pos, rot, player.hasCP437, player.hasExtPositions));
|
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) {
|
public override void SendLevel(Level prev, Level level) {
|
||||||
|
@ -225,24 +225,37 @@ namespace MCGalaxy
|
|||||||
if (held >= 0) ClientHeldBlock = (BlockID)held;
|
if (held >= 0) ClientHeldBlock = (BlockID)held;
|
||||||
|
|
||||||
if (Session.Ping.IgnorePosition || Loading) { return; }
|
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);
|
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);
|
CheckBlocks(Pos, next);
|
||||||
|
|
||||||
bool cancel = false;
|
if (fromClient) {
|
||||||
OnPlayerMoveEvent.Call(this, next, yaw, pitch, ref cancel);
|
bool cancel = false;
|
||||||
if (cancel) { cancel = false; return; }
|
OnPlayerMoveEvent.Call(this, next, yaw, pitch, ref cancel);
|
||||||
|
if (cancel) { cancel = false; return; }
|
||||||
|
}
|
||||||
|
|
||||||
Pos = next;
|
Pos = next;
|
||||||
SetYawPitch(yaw, pitch);
|
SetYawPitch(yaw, pitch);
|
||||||
CheckZones(next);
|
CheckZones(next);
|
||||||
|
|
||||||
if (!Moved()) return;
|
if (fromClient) {
|
||||||
if (DateTime.UtcNow < AFKCooldown) return;
|
if (!Moved()) return;
|
||||||
|
if (DateTime.UtcNow < AFKCooldown) return;
|
||||||
LastAction = DateTime.UtcNow;
|
|
||||||
if (IsAfk) CmdAfk.ToggleAfk(this, "");
|
LastAction = DateTime.UtcNow;
|
||||||
|
if (IsAfk) CmdAfk.ToggleAfk(this, "");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckZones(Position pos) {
|
void CheckZones(Position pos) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user