109 lines
2.2 KiB
Java
109 lines
2.2 KiB
Java
package net.minecraft.world.entity.ai.goal;
|
|
|
|
import java.util.EnumSet;
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
/**
|
|
* This is an internal object used by the GoalSelector to choose between Goals.
|
|
* In most cases, it should not be constructed directly.
|
|
*
|
|
* For information on how individual methods work, see the javadocs for Goal:
|
|
* {@link net.minecraft.entity.ai.goal.Goal}
|
|
*/
|
|
public class WrappedGoal extends Goal {
|
|
private final Goal goal;
|
|
private final int priority;
|
|
private boolean isRunning;
|
|
|
|
public WrappedGoal(int priority, Goal goal) {
|
|
this.priority = priority;
|
|
this.goal = goal;
|
|
}
|
|
|
|
public boolean canBeReplacedBy(WrappedGoal other) {
|
|
return this.isInterruptable() && other.getPriority() < this.getPriority();
|
|
}
|
|
|
|
@Override
|
|
public boolean canUse() {
|
|
return this.goal.canUse();
|
|
}
|
|
|
|
@Override
|
|
public boolean canContinueToUse() {
|
|
return this.goal.canContinueToUse();
|
|
}
|
|
|
|
@Override
|
|
public boolean isInterruptable() {
|
|
return this.goal.isInterruptable();
|
|
}
|
|
|
|
@Override
|
|
public void start() {
|
|
if (!this.isRunning) {
|
|
this.isRunning = true;
|
|
this.goal.start();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void stop() {
|
|
if (this.isRunning) {
|
|
this.isRunning = false;
|
|
this.goal.stop();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public boolean requiresUpdateEveryTick() {
|
|
return this.goal.requiresUpdateEveryTick();
|
|
}
|
|
|
|
@Override
|
|
protected int adjustedTickDelay(int adjustment) {
|
|
return this.goal.adjustedTickDelay(adjustment);
|
|
}
|
|
|
|
@Override
|
|
public void tick() {
|
|
this.goal.tick();
|
|
}
|
|
|
|
@Override
|
|
public void setFlags(EnumSet<Goal.Flag> flagSet) {
|
|
this.goal.setFlags(flagSet);
|
|
}
|
|
|
|
@Override
|
|
public EnumSet<Goal.Flag> getFlags() {
|
|
return this.goal.getFlags();
|
|
}
|
|
|
|
public boolean isRunning() {
|
|
return this.isRunning;
|
|
}
|
|
|
|
public int getPriority() {
|
|
return this.priority;
|
|
}
|
|
|
|
/**
|
|
* Gets the private goal enclosed by this WrappedGoal.
|
|
*/
|
|
public Goal getGoal() {
|
|
return this.goal;
|
|
}
|
|
|
|
public boolean equals(@Nullable Object object) {
|
|
if (this == object) {
|
|
return true;
|
|
} else {
|
|
return object != null && this.getClass() == object.getClass() ? this.goal.equals(((WrappedGoal)object).goal) : false;
|
|
}
|
|
}
|
|
|
|
public int hashCode() {
|
|
return this.goal.hashCode();
|
|
}
|
|
}
|