mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Add simple movements with /move command
- Determine if we can move to the specified direction - Add moving ability to the specified direction - Add /move command for triggering moves - Add move decomp. into steps (more natural) - Add pathfinding routines (still WIP) - SO YES YOU CAN NOW WALK USING MCC!!!
This commit is contained in:
parent
00131de08b
commit
b0c8f82697
9 changed files with 475 additions and 17 deletions
|
|
@ -33,6 +33,8 @@ namespace MinecraftClient
|
|||
|
||||
private object locationLock = new object();
|
||||
private World world = new World();
|
||||
private Queue<Location> steps;
|
||||
private Queue<Location> path;
|
||||
private Location location;
|
||||
|
||||
private string host;
|
||||
|
|
@ -369,6 +371,23 @@ namespace MinecraftClient
|
|||
UpdateLocation(location, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Move to the specified location
|
||||
/// </summary>
|
||||
/// <param name="location">Location to reach</param>
|
||||
/// <param name="allowUnsafe">Allow possible but unsafe locations</param>
|
||||
/// <returns>True if a path has been found</returns>
|
||||
public bool MoveTo(Location location, bool allowUnsafe = false)
|
||||
{
|
||||
lock (locationLock)
|
||||
{
|
||||
if (Movement.GetAvailableMoves(world, this.location, allowUnsafe).Contains(location))
|
||||
path = new Queue<Location>(new[] { location });
|
||||
else path = Movement.CalculatePath(world, this.location, location, allowUnsafe);
|
||||
return path != null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Received some text from the server
|
||||
/// </summary>
|
||||
|
|
@ -453,15 +472,15 @@ namespace MinecraftClient
|
|||
{
|
||||
lock (locationLock)
|
||||
{
|
||||
Location onFoots = new Location(location.X, Math.Floor(location.Y), location.Z);
|
||||
Location belowFoots = location + new Location(0, -1, 0);
|
||||
Block blockOnFoots = world.GetBlock(onFoots);
|
||||
Block blockBelowFoots = world.GetBlock(belowFoots);
|
||||
handler.SendLocationUpdate(location, blockBelowFoots.Type.IsSolid());
|
||||
if (!blockBelowFoots.Type.IsSolid())
|
||||
location = belowFoots;
|
||||
else if (!blockOnFoots.Type.IsSolid())
|
||||
location = onFoots;
|
||||
for (int i = 0; i < 2; i++) //Needs to run at 20 tps; MCC runs at 10 tps
|
||||
{
|
||||
if (steps != null && steps.Count > 0)
|
||||
location = steps.Dequeue();
|
||||
else if (path != null && path.Count > 0)
|
||||
steps = Movement.Move2Steps(location, path.Dequeue());
|
||||
else location = Movement.HandleGravity(world, location);
|
||||
handler.SendLocationUpdate(location, Movement.IsOnGround(world, location));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue