MobEffect is what handles the specific logic on the entity it is on. For example,
MobEffects#MOVEMENT_SPEED adds an attribute modifier that affects the movement speed while
MobEffects#WITHER attacks the entity from a
DamageSource whenever the mob effect is ready to be applied.
You can create a
MobEffect using two methods. The first creates a regular
MobEffect and applies the logic in some event method. The other method involves extending the
MobEffect class and overriding specific methods when needed. This documentation will focus on the second method.
There are four methods that are important depending on the type of mob effect you are creating. In each scenario, you should take into account whether you should extend
Here are the classes and methods to review:
||The basic mob effect class. Should be used if the mob effect happens over time.|
||An extended version of the mob effect class. Should be used if the mob effect happens only once and instantly.|
||Determines how fast a mob effect should call |
||Executes the logic on the entity when called.|
||Determines if the mob effect is instant. Returns true in |
||Executes the logic on the entity when called. |
If you are only modifying an entity
Attribute, then there is no need to extend the class. When constructing the mob effect instance, chain
addAttributeModifier and select the specific attribute, it's unique id, the amount to affect by, and the operation to apply the amount with.
Mob Effects need to be registered.
To allow greater customization, each mob effect is passed in as a
MobEffectInstance which allows the user to specify additional information for what the mob effect should do.