Add a mob extension plugin for walking to entities

Adds a new mob extension plugin which creates a walk_to() method on
Mobs to allow walking to another entity (accounting for the size of the
entity) with an optional facing position.
This commit is contained in:
Gary Tierney
2017-01-01 08:17:21 +00:00
parent b047d0197a
commit baa12ca446
4 changed files with 128 additions and 3 deletions
@@ -103,6 +103,11 @@ public abstract class Mob extends Entity {
*/
private Direction firstDirection = Direction.NONE;
/**
* The last facing direction of this mob.
*/
private Direction lastDirection = Direction.NORTH;
/**
* This mob's second movement direction.
*/
@@ -196,8 +201,8 @@ public abstract class Mob extends Entity {
*/
public final Direction[] getDirections() {
if (firstDirection != Direction.NONE) {
return secondDirection == Direction.NONE ? new Direction[]{ firstDirection }
: new Direction[]{ firstDirection, secondDirection };
return secondDirection == Direction.NONE ? new Direction[]{firstDirection}
: new Direction[]{firstDirection, secondDirection};
}
return Direction.EMPTY_DIRECTION_ARRAY;
@@ -268,6 +273,15 @@ public abstract class Mob extends Entity {
return inventory;
}
/**
* Gets the last facing direction of this mob.
*
* @return The last direction this mob was facing.
*/
public Direction getLastDirection() {
return lastDirection;
}
/**
* Gets this mob's local npc {@link List}.
*
@@ -425,6 +439,15 @@ public abstract class Mob extends Entity {
blockSet.add(SynchronizationBlock.createInteractingMobBlock(mob.getInteractionIndex()));
}
/**
* Set the last direction this mob was facing.
*
* @param lastDirection The direction to set.
*/
public void setLastDirection(Direction lastDirection) {
this.lastDirection = lastDirection;
}
/**
* Sets the {@link Position} of this mob.
* <p>
@@ -470,7 +493,7 @@ public abstract class Mob extends Entity {
* Gets the number of tiles this mob occupies.
*
* @return The number of tiles this mob occupies.
*/
*/
public int size() {
return definition.map(NpcDefinition::getSize).orElse(1);
}
@@ -548,4 +571,5 @@ public abstract class Mob extends Entity {
world.schedule(new SkillNormalizationTask(this));
}
}
@@ -146,6 +146,7 @@ public final class WalkingQueue {
} else {
previousPoints.add(next);
position = new Position(next.getX(), next.getY(), height);
mob.setLastDirection(firstDirection);
if (running) {
next = points.poll();
@@ -158,6 +159,7 @@ public final class WalkingQueue {
} else {
previousPoints.add(next);
position = new Position(next.getX(), next.getY(), height);
mob.setLastDirection(secondDirection);
}
}
}