Entity Goal System
Overview
The Goal System is the core AI behavior framework in Minecraft, controlling how entities make decisions and execute actions. It is divided into two main components: goalSelector (daily behavior goals) and targetSelector (attack/target goals).
Core Concepts
goalSelector
Manages daily behaviors like wandering, attacking, breeding, etc. Lower priority numbers execute first.
| Priority | Typical Use |
|---|---|
| 0 | Critical (e.g., float when in water) |
| 1-2 | Combat (e.g., melee attack) |
| 3-4 | Movement (e.g., random wander) |
| 5+ | Idle behaviors |
targetSelector
Manages target selection and tracking, used for hostile mobs to find and track attack targets.
Lifecycle Methods
Goals have a clear lifecycle:
| Stage | Method | Description |
|---|---|---|
| Can Use | canUse() | Check if goal can be activated |
| Start | start() | Called when goal starts executing |
| Tick | tick() | Called each tick while goal is active |
| Can Continue | canContinueToUse() | Check if goal should continue |
| Stop | stop() | Called when goal stops |
Common Goal Classes
Movement Goals
| Goal Class | Description |
|---|---|
FloatGoal | Float in water |
RandomStrollGoal | Random wandering |
LookAtPlayerGoal | Look at player |
MoveTowardsTargetGoal | Move toward target |
BreedGoal | Find mate and breed |
Combat Goals
| Goal Class | Description |
|---|---|
MeleeAttackGoal | Melee attack target |
RangedAttackGoal | Ranged attack |
HurtByTargetGoal | Attack what hurt it |
Usage Examples
js
// Add goal
const FloatGoal = Java.loadClass("net.minecraft.world.entity.ai.goal.FloatGoal");
mob.goalSelector.addGoal(0, new FloatGoal(mob));
// Add target goal
const NearestAttackableTargetGoal = Java.loadClass("net.minecraft.world.entity.ai.targeting.NearestAttackableTargetGoal");
mob.targetSelector.addGoal(0, new NearestAttackableTargetGoal(mob, Player.class, true));Notes
- Goal priority: Lower number = higher priority
- Only one goal per priority level in each selector
- Use
removeGoalto clear goals - For 1.19+, consider using Brain system instead