Rework of MineCube.cs and further improvements to CalculatePath() (#2014)

* Add function to determine if the client is executing a walking process
* Add comments
* Remove test bot entry
* Add funtion to approach a block as close as possible
* Add funtion to approach a block as close as possible
* Add funtion to approach a block as close as possible
* Add comment to function in McClient.cs
* Improve concurrency and reduce potential calculation power
* Apply code suggestions
* Apply code suggestions
* Improve CalculatePath() function to allow approaching
* Fix typo in MinecraftClient/ChatBot.cs
* Add comments to Chatbot fucntion
* Add break to for loop to exit quicker
* Allow to give a maxOffset to the goal
* Comment the sample bot again.
* Add parameter for calculation timeout
* Remove TestBot again
* Implement timeout in Chatbot class
* Remove test commands
* Update comment in Chatbot.cs
* Set timeout to default 5 sec
* Change order of parameters back
* Add suggested improvements
* Move task and fix missing methods in .NET 4.0
* Create switch for tool handling
* Remove unused function
* Improve movement
* Improve performance of CalculatePath()

 - Replace Hashset OpenSet with a Binary Heap
  - Temporary remove maxOffset / minOffset features
 - Round start location for easier calculation
 - Add 0.5 to each location in reconstruct path to avoid getting stuck
    on edges

* Add diagonal movement
* Remove direct block movement
- causes kick for invalid packet movement if moving on the block you are
  currently standing on

* Floor start in A* and improve diagonal walking check
* Add helperfunctions to McClient.cs
* Prevent client from falling into danger
* Add comment to function and remove dependencies
* Add comments
* Remove debug settings

Co-authored-by: ORelio <ORelio@users.noreply.github.com>
This commit is contained in:
Daenges 2022-08-15 18:26:40 +02:00 committed by GitHub
parent ea6788278d
commit aa1f54d0d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 787 additions and 502 deletions

View file

@ -60,6 +60,8 @@ namespace MinecraftClient
private float playerYaw;
private float playerPitch;
private double motionY;
public enum MovementType { Sneak, Walk, Sprint}
public int currentMovementSpeed = 4;
private int sequenceId; // User for player block synchronization (Aka. digging, placing blocks, etc..)
private string host;
@ -344,7 +346,7 @@ namespace MinecraftClient
{
lock (locationLock)
{
for (int i = 0; i < 2; i++) //Needs to run at 20 tps; MCC runs at 10 tps
for (int i = 0; i < currentMovementSpeed; i++) //Needs to run at 20 tps; MCC runs at 10 tps
{
if (_yaw == null || _pitch == null)
{
@ -1125,9 +1127,7 @@ namespace MinecraftClient
else
{
// Calculate path through pathfinding. Path contains a list of 1-block movement that will be divided into steps
if (Movement.GetAvailableMoves(world, this.location, allowUnsafe).Contains(location))
path = new Queue<Location>(new[] { location });
else path = Movement.CalculatePath(world, this.location, location, allowUnsafe, maxOffset, minOffset, timeout ?? TimeSpan.FromSeconds(5));
path = Movement.CalculatePath(world, this.location, location, allowUnsafe, maxOffset, minOffset, timeout ?? TimeSpan.FromSeconds(5));
return path != null;
}
}
@ -1905,6 +1905,49 @@ namespace MinecraftClient
return terrainAndMovementsEnabled && locationReceived && ((steps != null && steps.Count > 0) || (path != null && path.Count > 0));
}
/// <summary>
/// Get the current goal
/// </summary>
/// <returns>Current goal of movement. Location.Zero if not set.</returns>
public Location GetCurrentMovementGoal()
{
return ClientIsMoving() ? Location.Zero : path.Last();
}
/// <summary>
/// Cancels the current movement
/// </summary>
/// <returns>True if there was an active path</returns>
public bool CancelMovement()
{
bool success = ClientIsMoving();
path = null;
return success;
}
/// <summary>
/// Change the amount of sent movement packets per time
/// </summary>
/// <param name="newSpeed">Set a new walking type</param>
public void SetMovementSpeed(MovementType newSpeed)
{
switch (newSpeed)
{
case MovementType.Sneak:
// https://minecraft.fandom.com/wiki/Sneaking#Effects - Sneaking 1.31m/s
currentMovementSpeed = 2;
break;
case MovementType.Walk:
// https://minecraft.fandom.com/wiki/Walking#Usage - Walking 4.317 m/s
currentMovementSpeed = 4;
break;
case MovementType.Sprint:
// https://minecraft.fandom.com/wiki/Sprinting#Usage - Sprinting 5.612 m/s
currentMovementSpeed = 5;
break;
}
}
/// <summary>
/// Called when the server sends a new player location,
/// or if a ChatBot whishes to update the player's location.