mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Bug fix: Cancel chunk load task when switching worlds
This commit is contained in:
parent
e150bd569b
commit
01ef9a89ca
7 changed files with 127 additions and 31 deletions
|
|
@ -60,6 +60,7 @@ namespace MinecraftClient
|
|||
private float playerYaw;
|
||||
private float playerPitch;
|
||||
private double motionY;
|
||||
private CancellationTokenSource chunkProcessCancelSource = new();
|
||||
public enum MovementType { Sneak, Walk, Sprint}
|
||||
public int currentMovementSpeed = 4;
|
||||
private int sequenceId; // User for player block synchronization (Aka. digging, placing blocks, etc..)
|
||||
|
|
@ -111,6 +112,7 @@ namespace MinecraftClient
|
|||
public int GetSequenceId() { return sequenceId; }
|
||||
public float GetPitch() { return playerPitch; }
|
||||
public World GetWorld() { return world; }
|
||||
public CancellationToken GetChunkProcessCancelToken() { return chunkProcessCancelSource.Token; }
|
||||
public Double GetServerTPS() { return averageTPS; }
|
||||
public bool GetIsSupportPreviewsChat() { return isSupportPreviewsChat; }
|
||||
public float GetHealth() { return playerHealth; }
|
||||
|
|
@ -475,7 +477,9 @@ namespace MinecraftClient
|
|||
/// </summary>
|
||||
public void OnConnectionLost(ChatBot.DisconnectReason reason, string message)
|
||||
{
|
||||
chunkProcessCancelSource.Cancel();
|
||||
world.Clear();
|
||||
chunkProcessCancelSource = new();
|
||||
|
||||
if (timeoutdetector != null)
|
||||
{
|
||||
|
|
@ -768,6 +772,17 @@ namespace MinecraftClient
|
|||
InvokeOnMainThread(() => { task(); return true; });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clear all tasks
|
||||
/// </summary>
|
||||
public void ClearTasks()
|
||||
{
|
||||
lock (threadTasksLock)
|
||||
{
|
||||
threadTasks.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if running on a different thread and InvokeOnMainThread is required
|
||||
/// </summary>
|
||||
|
|
@ -892,7 +907,9 @@ namespace MinecraftClient
|
|||
terrainAndMovementsEnabled = false;
|
||||
terrainAndMovementsRequested = false;
|
||||
locationReceived = false;
|
||||
chunkProcessCancelSource.Cancel();
|
||||
world.Clear();
|
||||
chunkProcessCancelSource = new();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
@ -1922,6 +1939,8 @@ namespace MinecraftClient
|
|||
/// </summary>
|
||||
public void OnRespawn()
|
||||
{
|
||||
ClearTasks();
|
||||
|
||||
if (terrainAndMovementsRequested)
|
||||
{
|
||||
terrainAndMovementsEnabled = true;
|
||||
|
|
@ -1931,7 +1950,9 @@ namespace MinecraftClient
|
|||
|
||||
if (terrainAndMovementsEnabled)
|
||||
{
|
||||
chunkProcessCancelSource.Cancel();
|
||||
world.Clear();
|
||||
chunkProcessCancelSource = new();
|
||||
}
|
||||
|
||||
entities.Clear();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue