Comments for FollowTargetGoal

This commit is contained in:
Felix Cravic 2020-11-29 22:19:13 +01:00
parent b6aa81bbbf
commit 75e3ffde8d
2 changed files with 19 additions and 13 deletions

View File

@ -20,7 +20,7 @@ import java.util.List;
* <p>
* The command works using a list of valid syntaxes.
* For instance we could build the command
* "/health set Notch 50" into multiple argument types "/health [set/add/remove] [Username] [Integer]"
* "/health set Notch 50" into multiple argument types "/health [set/add/remove] [username] [integer]"
* <p>
* All the default argument types can be found in {@link ArgumentType}
* and the syntax be created/registered using {@link #addSyntax(CommandExecutor, Argument[])}.
@ -163,6 +163,7 @@ public class Command {
* or if no corresponding syntax has been found.
*
* @return the default executor, null if not any
* @see #setDefaultExecutor(CommandExecutor)
*/
@Nullable
public CommandExecutor getDefaultExecutor() {
@ -183,6 +184,7 @@ public class Command {
* Gets all the syntaxes of this command.
*
* @return a collection containing all this command syntaxes
* @see #addSyntax(CommandCondition, CommandExecutor, Argument[])
*/
@NotNull
public Collection<CommandSyntax> getSyntaxes() {

View File

@ -10,21 +10,20 @@ import org.jetbrains.annotations.NotNull;
public class FollowTargetGoal extends GoalSelector {
private final UpdateOption updateOption;
private final UpdateOption pathUpdateOption;
private long lastUpdateTime = 0;
private boolean forceEnd = false;
private Position lastTargetPos;
public FollowTargetGoal(@NotNull EntityCreature entityCreature, @NotNull UpdateOption updateOption) {
/**
* Creates a follow target goal object.
*
* @param entityCreature the entity
* @param pathUpdateOption the time between each path update (to check if the target moved)
*/
public FollowTargetGoal(@NotNull EntityCreature entityCreature, @NotNull UpdateOption pathUpdateOption) {
super(entityCreature);
this.updateOption = updateOption;
}
private float getDistance(Position a, Position b) {
if (a == null || b == null)
throw new NullPointerException();
return MathUtils.square(a.getX() - b.getX()) +
MathUtils.square(a.getZ() - b.getZ());
this.pathUpdateOption = pathUpdateOption;
}
@Override
@ -60,8 +59,8 @@ public class FollowTargetGoal extends GoalSelector {
@Override
public void tick(long time) {
if (forceEnd ||
updateOption.getValue() == 0 ||
updateOption.getTimeUnit().toMilliseconds(updateOption.getValue()) + lastUpdateTime > time) {
pathUpdateOption.getValue() == 0 ||
pathUpdateOption.getTimeUnit().toMilliseconds(pathUpdateOption.getValue()) + lastUpdateTime > time) {
return;
}
Position targetPos = entityCreature.getTarget() != null ? entityCreature.getTarget().getPosition() : null;
@ -83,4 +82,9 @@ public class FollowTargetGoal extends GoalSelector {
public void end() {
entityCreature.setPathTo(null);
}
private float getDistance(@NotNull Position a, @NotNull Position b) {
return MathUtils.square(a.getX() - b.getX()) +
MathUtils.square(a.getZ() - b.getZ());
}
}