Skip to content

Commit

Permalink
trying to clean up a little
Browse files Browse the repository at this point in the history
  • Loading branch information
psu-de committed Mar 13, 2024
1 parent 500220d commit b7ef677
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 29 deletions.
8 changes: 0 additions & 8 deletions Plugins/MineSharp.Pathfinder/Moves/DirectMove.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public override bool IsMovePossible(Position position, IWorld world)
/// <inheritdoc />
protected override async Task PerformMove(MineSharpBot bot, int count, Movements movements)
{
// TODO: IsMovePossible() ist nicht korrekt
var player = bot.GetPlugin<PlayerPlugin>();
var physics = bot.GetPlugin<PhysicsPlugin>();
var entity = player.Entity ?? throw new NullReferenceException("Player entity not initialized.");
Expand All @@ -66,12 +65,5 @@ protected override async Task PerformMove(MineSharpBot bot, int count, Movements
}
}
physics.InputControls.Reset();

if (!CollisionHelper.IsPointInBlockBb(entity.Position, targetBlock))
{
throw new Exception("move went wrong"); // TODO: Move exception
}

await MovementUtils.MoveInsideBlock(entity, targetBlock, physics);
}
}
9 changes: 1 addition & 8 deletions Plugins/MineSharp.Pathfinder/Moves/FallDownMove.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected override async Task PerformMove(MineSharpBot bot, int count, Movements
MovementUtils.SetHorizontalMovementsFromVector(this.Motion, physics.InputControls);

var stopNextTick = false;
while (player.Entity.IsOnGround)
while (entity.IsOnGround)
{
if (!stopNextTick)
{
Expand All @@ -71,12 +71,5 @@ protected override async Task PerformMove(MineSharpBot bot, int count, Movements

physics.InputControls.Reset();
await physics.WaitForOnGround();

if (!CollisionHelper.IntersectsBbWithBlock(entity.GetBoundingBox(), targetBlock))
{
throw new Exception("move went wrong."); // TODO: Better exception
}

await MovementUtils.MoveInsideBlock(entity, targetBlock, physics);
}
}
8 changes: 0 additions & 8 deletions Plugins/MineSharp.Pathfinder/Moves/JumpOneBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,5 @@ protected override async Task PerformMove(MineSharpBot bot, int count, Movements
}

await physics.WaitForOnGround();

if (!CollisionHelper.IntersectsBbWithBlock(entity.GetBoundingBox(), targetBlock))
{
throw new Exception("move went wrong."); // TODO: Better exception
}

Console.WriteLine($"target={target}, block={targetBlock}");
await MovementUtils.MoveInsideBlock(entity, targetBlock, physics);
}
}
5 changes: 1 addition & 4 deletions Plugins/MineSharp.Pathfinder/Moves/JumpUpMove.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ public override bool IsMovePossible(Position position, IWorld world)
/// <inheritdoc />
protected override async Task PerformMove(MineSharpBot bot, int count, Movements movements)
{
if (count != 1)
throw new InvalidOperationException();

var physics = bot.GetPlugin<PhysicsPlugin>();
var player = bot.GetPlugin<PlayerPlugin>();
var entity = player.Entity ?? throw new NullReferenceException("player is not initialized");
Expand All @@ -62,7 +59,7 @@ protected override async Task PerformMove(MineSharpBot bot, int count, Movements
{
await physics.WaitForTick();

if (CollisionHelper.IsXzPointInBlockBb(entity.Position, targetBlock))
if (CollisionHelper.IntersectsBbWithBlock(entity.GetBoundingBox(), targetBlock))
{
break;
}
Expand Down
13 changes: 12 additions & 1 deletion Plugins/MineSharp.Pathfinder/Moves/Move.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using MineSharp.Core.Common.Entities;
using MineSharp.Core.Geometry;
using MineSharp.Data;
using MineSharp.Pathfinder.Exceptions;
using MineSharp.Pathfinder.Utils;
using MineSharp.Physics.Input;
using MineSharp.World;
Expand Down Expand Up @@ -46,14 +47,24 @@ internal async Task Perform(MineSharpBot bot, int count, Position startPosition,
var player = bot.GetPlugin<PlayerPlugin>();
var physics = bot.GetPlugin<PhysicsPlugin>();
var entity = player.Entity ?? throw new NullReferenceException("player is not initialized");

var target = (Position)this.Motion.Scaled(count).Add(startPosition);

if (entity.Velocity.HorizontalLengthSquared() > 0.15 * 0.15)
await MovementUtils.SlowDown(entity, physics);

await physics.Look(0, 0);
await MovementUtils.MoveInsideBlock(entity, startPosition, physics);

await PerformMove(bot, count, movements);

physics.InputControls.Reset();

if (!CollisionHelper.IntersectsBbWithBlock(entity.GetBoundingBox(), target))
{
throw new MoveWentWrongException($"bot is not on expected position (actual={entity.Position}, expected={target})");
}

await MovementUtils.MoveInsideBlock(entity, target, physics);
}

/// <summary>
Expand Down

0 comments on commit b7ef677

Please sign in to comment.