Goals
The EdGoal system provides an AI-like behavior framework for EdEntity objects. Goals represent specific tasks or behaviors that entities can execute in sequence.
Overview
The goal system operates on a queue-based approach where entities execute goals one at a time. When a goal completes, the entity automatically moves to the next goal in the queue. This allows for creating complex behavior sequences and AI patterns.
EdGoal Base Class
The EdGoal abstract class serves as the foundation for all entity behaviors.
Core Properties
EdEntity getEntity()
Description: Returns the entity this goal is assigned to
Returns: EdEntity that will execute this goal
Usage: Entity access within goal logic
void setEntity(EdEntity entity)
Description: Sets the entity that will execute this goal
Parameters:
entity- Target entityUsage: Goal assignment (automatically called by the system)
boolean isForceStopped()
Description: Checks if the goal was forcefully stopped
Returns: True if force stopped, false otherwise
Usage: Cleanup logic, state checking
Lifecycle Management
void init()
Description: Initializes and starts the goal execution
Usage: Called automatically by the entity system
void start()
Description: Abstract method called when the goal begins
Usage: Override to implement goal initialization logic
boolean shouldExecute()
Description: Abstract method that determines if the goal should continue
Returns: True to continue execution, false to complete the goal
Usage: Override to implement goal completion conditions
void tick()
Description: Abstract method called every game tick while the goal is active
Usage: Override to implement goal behavior per tick
void forceStop()
Description: Forces the goal to stop without triggering the next goal
Usage: Emergency stops, goal cancellation
boolean isRunning()
Description: Checks if the goal is currently executing
Returns: True if running, false otherwise
Usage: Goal state checking, conditional logic
Event Callbacks
void setStartRunnable(Runnable startRunnable)
Description: Sets a callback to run when the goal starts
Parameters:
startRunnable- Code to execute on startUsage: Custom initialization, event handling
void setEndRunnable(Runnable endRunnable)
Description: Sets a callback to run when the goal ends
Parameters:
endRunnable- Code to execute on completionUsage: Cleanup logic, completion events
void setEachTickRunnable(Runnable eachTickRunnable)
Description: Sets a callback to run every tick during execution
Parameters:
eachTickRunnable- Code to execute each tickUsage: Additional per-tick logic, monitoring
Built-in Goal Implementations
EdGoalMove
Moves an entity to a specific location with customizable movement behavior.
Parameters:
moveGoal- Target position vectorspeed- Movement speed (blocks per tick)
Configuration Options:
setAffectY(boolean)- Whether to move vertically (default: true)setSendRotation(boolean)- Whether to rotate towards target (default: true)setSendRotationEachTick(boolean)- Whether to update rotation each tick (default: false)setInvertRotation(boolean)- Whether to invert rotation calculations (default: false)
Usage Example:
EdGoalFollowEntity
Makes an entity follow another entity or player at a specified distance.
Parameters:
target- EntityHolder wrapping the target to followfollowDistance- Distance to maintain from targetspeed- Movement speedduration- How long to follow (in seconds)
Usage Example:
EdGoalOrbit
Makes an entity orbit around a central point with customizable radius and speed.
Parameters:
center- Center point to orbit aroundradius- Orbital radius in blocksangularSpeed- Angular speed (radians per tick)clockwise- Direction of orbitticksDuration- Duration in ticks (0 for infinite)
Configuration Options:
setAffectY(boolean)- Whether to orbit verticallysetSendRotation(boolean)- Whether to face the centersetSendRotationEachTick(boolean)- Update rotation each tick
Usage Example:
EdGoalParabolicMove
Moves an entity in a parabolic arc to a target location.
Parameters:
end- Target end positionheight- Arc height modifierduration- Movement duration in milliseconds
Usage Example:
EdGoalArchMove
Moves an entity in a simple sinusoidal arc to a target location.
Parameters:
end- Target positionspeed- Movement speedduration- Movement duration in milliseconds
Usage Example:
EdGoalDelay
Creates a delay/wait period in the goal sequence.
Parameters:
delayTicks- Number of ticks to wait (20 ticks = 1 second)
Utility Methods:
getProgress()- Returns completion percentage (0.0 to 1.0)getRemainingTicks()- Returns ticks remaininggetRemainingSeconds()- Returns seconds remaining
Usage Example:
EntityHolder Utility
The EntityHolder class provides a unified way to reference both Bukkit entities and EdEntities.
Creating Custom Goals
Basic Custom Goal Structure
Advanced Custom Goal Example
Goal with Conditions
Goal Sequence Examples
Simple Patrol Route
Complex Behavior Sequence
Animation Sequence
Last updated