mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-26 19:18:12 +01:00
Added getter and setter for the entity in GoalSelector
This commit is contained in:
parent
92b06b6992
commit
aa4ee97710
@ -22,13 +22,12 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public abstract class EntityCreature extends LivingEntity implements NavigableEntity {
|
||||
|
||||
// TODO all pathfinding requests should be process in another thread
|
||||
private final ReentrantLock pathLock = new ReentrantLock();
|
||||
private final Object pathLock = new Object();
|
||||
|
||||
private final PFPathingEntity pathingEntity = new PFPathingEntity(this);
|
||||
private HydrazinePathFinder pathFinder;
|
||||
@ -315,17 +314,16 @@ public abstract class EntityCreature extends LivingEntity implements NavigableEn
|
||||
|
||||
@Override
|
||||
public void pathFindingTick(float speed) {
|
||||
this.pathLock.lock();
|
||||
NavigableEntity.super.pathFindingTick(speed);
|
||||
this.pathLock.unlock();
|
||||
synchronized (pathLock){
|
||||
NavigableEntity.super.pathFindingTick(speed);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setPathTo(@Nullable Position position) {
|
||||
this.pathLock.lock();
|
||||
final boolean result = NavigableEntity.super.setPathTo(position);
|
||||
this.pathLock.unlock();
|
||||
return result;
|
||||
synchronized (pathLock){
|
||||
return NavigableEntity.super.setPathTo(position);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -7,7 +7,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public abstract class GoalSelector {
|
||||
|
||||
protected final EntityCreature entityCreature;
|
||||
protected EntityCreature entityCreature;
|
||||
|
||||
public GoalSelector(@NotNull EntityCreature entityCreature) {
|
||||
this.entityCreature = entityCreature;
|
||||
@ -59,4 +59,27 @@ public abstract class GoalSelector {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the entity behind the goal selector.
|
||||
*
|
||||
* @return the entity
|
||||
*/
|
||||
@NotNull
|
||||
public EntityCreature getEntityCreature() {
|
||||
return entityCreature;
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the entity affected by the goal selector.
|
||||
* <p>
|
||||
* WARNING: this does not add the goal selector to {@code entityCreature},
|
||||
* this only change the internal entity field. Be sure to remove the goal from
|
||||
* the previous entity and add it to the new one using {@link EntityCreature#getGoalSelectors()}.
|
||||
*
|
||||
* @param entityCreature the new affected entity
|
||||
*/
|
||||
public void setEntityCreature(@NotNull EntityCreature entityCreature) {
|
||||
this.entityCreature = entityCreature;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user