Class CustomGoalSelector

java.lang.Object
net.minecraft.world.entity.ai.goal.GoalSelector
com.minecolonies.api.entity.CustomGoalSelector

public class CustomGoalSelector extends net.minecraft.world.entity.ai.goal.GoalSelector
A simplified goal selector, for more performance.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    Set<net.minecraft.world.entity.ai.goal.WrappedGoal>
    All goals added to this selector

    Fields inherited from class net.minecraft.world.entity.ai.goal.GoalSelector

    disabledFlags, lockedFlags
  • Constructor Summary

    Constructors
    Constructor
    Description
    CustomGoalSelector(@NotNull Supplier<net.minecraft.util.profiling.ProfilerFiller> profiler)
    Creates a new customgoalselector with the given profiler.
    CustomGoalSelector(@NotNull net.minecraft.world.entity.ai.goal.GoalSelector old)
    Create a new goalselector from an existing one, simply re-uses the references.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addGoal(int priority, net.minecraft.world.entity.ai.goal.Goal task)
    Add a now AITask.
    void
    disableControlFlag(net.minecraft.world.entity.ai.goal.Goal.Flag flag)
    Disables the given flag
    void
    enableControlFlag(net.minecraft.world.entity.ai.goal.Goal.Flag flag)
    Enables the given flag
    Stream<net.minecraft.world.entity.ai.goal.WrappedGoal>
    Gets all goals currently running
    void
    importFrom(net.minecraft.world.entity.ai.goal.GoalSelector selector)
    Imports values from another selector
    void
    removeGoal(net.minecraft.world.entity.ai.goal.Goal task)
    removes the indicated task from the entity's AI tasks.
    void
    setControlFlag(net.minecraft.world.entity.ai.goal.Goal.Flag flag, boolean enabled)
    Sets the flag to enabled or disabled
    void
    Ticks this selector, first checks running goals to stop, then checks all goals to see which should start running.

    Methods inherited from class net.minecraft.world.entity.ai.goal.GoalSelector

    getAvailableGoals, removeAllGoals, setNewGoalRate, tickRunningGoals

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • availableGoals

      public Set<net.minecraft.world.entity.ai.goal.WrappedGoal> availableGoals
      All goals added to this selector
  • Constructor Details

    • CustomGoalSelector

      public CustomGoalSelector(@NotNull @NotNull net.minecraft.world.entity.ai.goal.GoalSelector old)
      Create a new goalselector from an existing one, simply re-uses the references.
      Parameters:
      old - the old selector to use
    • CustomGoalSelector

      public CustomGoalSelector(@NotNull @NotNull Supplier<net.minecraft.util.profiling.ProfilerFiller> profiler)
      Creates a new customgoalselector with the given profiler.
      Parameters:
      profiler - the profiler to use, usually attached to a world object
  • Method Details

    • importFrom

      public void importFrom(net.minecraft.world.entity.ai.goal.GoalSelector selector)
      Imports values from another selector
      Parameters:
      selector - selector to import from
    • addGoal

      public void addGoal(int priority, net.minecraft.world.entity.ai.goal.Goal task)
      Add a now AITask. Args : priority, task
      Overrides:
      addGoal in class net.minecraft.world.entity.ai.goal.GoalSelector
    • removeGoal

      public void removeGoal(net.minecraft.world.entity.ai.goal.Goal task)
      removes the indicated task from the entity's AI tasks.
      Overrides:
      removeGoal in class net.minecraft.world.entity.ai.goal.GoalSelector
    • tick

      public void tick()
      Ticks this selector, first checks running goals to stop, then checks all goals to see which should start running. Finally ticks all running goals Performance wise this is about 6 times faster, when checking at the same rate as the vanilla one, resulting in about 3-4 times less time spent updating and executing AI goals. When updating non-running goals only every 4 ticks it goes up to about 10% of vanilla's time spent for the whole update goals and their execution.
      Overrides:
      tick in class net.minecraft.world.entity.ai.goal.GoalSelector
    • getRunningGoals

      public Stream<net.minecraft.world.entity.ai.goal.WrappedGoal> getRunningGoals()
      Gets all goals currently running
      Overrides:
      getRunningGoals in class net.minecraft.world.entity.ai.goal.GoalSelector
      Returns:
      the stream of running goals.
    • disableControlFlag

      public void disableControlFlag(net.minecraft.world.entity.ai.goal.Goal.Flag flag)
      Disables the given flag
      Overrides:
      disableControlFlag in class net.minecraft.world.entity.ai.goal.GoalSelector
      Parameters:
      flag - the flag to disable.
    • enableControlFlag

      public void enableControlFlag(net.minecraft.world.entity.ai.goal.Goal.Flag flag)
      Enables the given flag
      Overrides:
      enableControlFlag in class net.minecraft.world.entity.ai.goal.GoalSelector
      Parameters:
      flag - the flag to enable.
    • setControlFlag

      public void setControlFlag(net.minecraft.world.entity.ai.goal.Goal.Flag flag, boolean enabled)
      Sets the flag to enabled or disabled
      Overrides:
      setControlFlag in class net.minecraft.world.entity.ai.goal.GoalSelector
      Parameters:
      flag - Flag to set
      enabled - enable or disable it