use of net.minecraft.world.entity.ai.goal.Goal in project MagicPlugin by elBukkit.
the class MagicGoal method getSubDescription.
protected String getSubDescription() {
List<String> goalDescriptions = new ArrayList<>();
for (Goal goal : goals) {
String goalDescription = goal.toString();
if (goal == currentGoal) {
goalDescription = ChatColor.AQUA + goalDescription;
} else {
goalDescription = ChatColor.DARK_AQUA + goalDescription;
}
goalDescriptions.add(goalDescription);
}
return ChatColor.DARK_GRAY + " [" + StringUtils.join(goalDescriptions, " ") + ChatColor.DARK_GRAY + "]";
}
use of net.minecraft.world.entity.ai.goal.Goal in project MagicPlugin by elBukkit.
the class MobUtils method removeGoal.
protected boolean removeGoal(GoalSelector selector, Mob mob, Entity entity, GoalType goalType) {
// TODO: Is there a cleaner way?
try {
Goal targetGoal = getGoal(goalType, entity, mob, new MemoryConfiguration());
Collection<WrappedGoal> available = selector.getAvailableGoals();
List<Goal> found = new ArrayList<>();
for (WrappedGoal wrappedGoal : available) {
if (targetGoal.getClass().isAssignableFrom(wrappedGoal.getGoal().getClass())) {
found.add(wrappedGoal.getGoal());
}
}
for (Goal removeGoal : found) {
selector.removeGoal(removeGoal);
}
} catch (Exception ex) {
platform.getLogger().log(Level.WARNING, "Error removing goal: " + goalType + " from " + entity.getType(), ex);
return false;
}
return true;
}
use of net.minecraft.world.entity.ai.goal.Goal in project MagicPlugin by elBukkit.
the class MobUtils method addGoal.
protected boolean addGoal(GoalSelector selector, Mob mob, Entity entity, GoalType goalType, int priority, ConfigurationSection config) {
try {
Goal goal = getGoal(goalType, entity, mob, config);
if (goal == null) {
return false;
}
selector.addGoal(priority, goal);
} catch (Exception ex) {
platform.getLogger().log(Level.WARNING, "Error creating goal: " + goalType + " on " + entity.getType(), ex);
return false;
}
return true;
}
use of net.minecraft.world.entity.ai.goal.Goal in project MagicPlugin by elBukkit.
the class MobUtils method removeGoal.
protected boolean removeGoal(GoalSelector selector, Mob mob, Entity entity, GoalType goalType) {
// TODO: Is there a cleaner way?
try {
Goal targetGoal = getGoal(goalType, entity, mob, new MemoryConfiguration());
Collection<WrappedGoal> available = selector.getAvailableGoals();
List<Goal> found = new ArrayList<>();
for (WrappedGoal wrappedGoal : available) {
if (targetGoal.getClass().isAssignableFrom(wrappedGoal.getGoal().getClass())) {
found.add(wrappedGoal.getGoal());
}
}
for (Goal removeGoal : found) {
selector.removeGoal(removeGoal);
}
} catch (Exception ex) {
platform.getLogger().log(Level.WARNING, "Error removing goal: " + goalType + " from " + entity.getType(), ex);
return false;
}
return true;
}
use of net.minecraft.world.entity.ai.goal.Goal in project MagicPlugin by elBukkit.
the class MobUtils method getGoals.
private List<Goal> getGoals(Entity entity, Mob mob, ConfigurationSection config, String logContext) {
List<Goal> goals = new ArrayList<>();
List<GoalConfiguration> goalConfigurations = GoalConfiguration.fromList(config, "goals", platform.getLogger(), logContext);
if (goalConfigurations != null) {
Collections.sort(goalConfigurations);
for (GoalConfiguration goalConfig : goalConfigurations) {
try {
Goal goal = getGoal(goalConfig.getGoalType(), entity, mob, goalConfig.getConfiguration());
if (goal != null) {
goals.add(goal);
}
} catch (Exception ex) {
platform.getLogger().log(Level.WARNING, "Error creating goal: " + goalConfig.getGoalType() + " on mob " + entity.getType(), ex);
}
}
}
if (goals.isEmpty()) {
goals.add(new IdleGoal());
}
return goals;
}
Aggregations