Difference between revisions of "Mob Effects"

From Forge Community Wiki
(Categorize with Category:Game Effects by SizableShrimp#0755)
(Update to 1.17)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
An <code>Effect</code> is what handles the specific logic on the entity it is on. For example, <code>Effects#SPEED</code> adds an attribute modifier that affects the movement speed while <code>Effects#WITHER</code> attacks the entity from a <code>DamageSource</code> whenever the potion effect is ready to be applied.
+
A <code>MobEffect</code> is what handles the specific logic on the entity it is on. For example, <code>MobEffects#MOVEMENT_SPEED</code> adds an attribute modifier that affects the movement speed while <code>MobEffects#WITHER</code> attacks the entity from a <code>DamageSource</code> whenever the mob effect is ready to be applied.
  
== Creating an <code>Effect</code> ==
+
== Creating a <code>MobEffect</code> ==
  
You can create an <code>Effect</code> using two methods. The first creates a regular <code>Effect</code> and applies the logic in some event method. The other method involves extending the <code>Effect</code> class and overriding specific methods when needed. This documentation will focus on the second method.
+
You can create a <code>MobEffect</code> using two methods. The first creates a regular <code>MobEffect</code> and applies the logic in some event method. The other method involves extending the <code>MobEffect</code> 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 effect you are creating. In each scenario, you should take into account whether you should extend <code>Effect</code> or <code>InstantEffect</code>.
+
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 <code>MobEffect</code> or <code>InstantenousMobEffect</code>.
  
 
Here are the classes and methods to review:
 
Here are the classes and methods to review:
Line 12: Line 12:
 
!Class !!Usage  
 
!Class !!Usage  
 
|-
 
|-
|  <code>Effect</code>  ||  The basic effect class. Should be used if the effect happens over time.  
+
|  <code>MobEffect</code>  ||  The basic mob effect class. Should be used if the mob effect happens over time.  
 
|-
 
|-
|  <code>InstantEffect</code>  ||  An extended version of the effect class. Should be used if the effect happens only once and instantly.  
+
|  <code>InstantenousMobEffect</code>  ||  An extended version of the mob effect class. Should be used if the mob effect happens only once and instantly.  
 
|-
 
|-
 
|}
 
|}
Line 21: Line 21:
 
!Method !!Description  
 
!Method !!Description  
 
|-
 
|-
|  <code>isReady</code>  ||  Determines how fast an effect should call <code>performEffect</code> while applied. This is overridden by <code>InstantEffect</code> to occur after one tick. If too fast, the server will not have enough time to execute the damage on the entity.  
+
|  <code>isDurationEffectTick</code>  ||  Determines how fast a mob effect should call <code>applyEffectTick</code> while applied. This is overridden by <code>InstantenousMobEffect</code> to occur after one tick. If too fast, the server will not have enough time to execute the damage on the entity.  
 
|-
 
|-
|  <code>performEffect</code>  ||  Executes the logic on the entity when called.  
+
|  <code>applyEffectTick</code>  ||  Executes the logic on the entity when called.  
 
|-
 
|-
|  <code>isInstant</code>  ||  Determines if the effect is instant. Returns true in <code>InstantEffect</code>.  
+
|  <code>isInstantenous</code>  ||  Determines if the mob effect is instant. Returns true in <code>InstantenousMobEffect</code>.  
 
|-
 
|-
|  <code>affectEntity</code>  ||  Executes the logic on the entity when called. <code>isInstant</code> must return true for this to be called.  
+
|  <code>applyInstantenousEffect</code>  ||  Executes the logic on the entity when called. <code>isInstantenous</code> must return true for this to be called.  
 
|-
 
|-
 
|}
 
|}
  
If you are only modifying an entity <code>Attribute</code>, then there is no need to extend the class. When constructing the effect instance, chain <code>addAttributeModifier</code> and select the specific attribute, it's unique id, the amount to affect by, and the operation to apply the amount with.
+
If you are only modifying an entity <code>Attribute</code>, then there is no need to extend the class. When constructing the mob effect instance, chain <code>addAttributeModifier</code> and select the specific attribute, it's unique id, the amount to affect by, and the operation to apply the amount with.
  
Effects need to be [[Registration|registered]].
+
Mob Effects need to be [[Registration|registered]].
  
== <code>EffectInstance</code> ==
+
== <code>MobEffectInstance</code> ==
  
To allow greater customization, each effect is passed in as an <code>EffectInstance</code> which allows the user to specify additional information for what the effect should do.
+
To allow greater customization, each mob effect is passed in as a <code>MobEffectInstance</code> which allows the user to specify additional information for what the mob effect should do.
  
  
 
[[Category:Game Effects]]
 
[[Category:Game Effects]]

Latest revision as of 21:09, 2 August 2021

A 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.

Creating a MobEffect

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 MobEffect or InstantenousMobEffect.

Here are the classes and methods to review:

Class Usage
MobEffect The basic mob effect class. Should be used if the mob effect happens over time.
InstantenousMobEffect An extended version of the mob effect class. Should be used if the mob effect happens only once and instantly.
Method Description
isDurationEffectTick Determines how fast a mob effect should call applyEffectTick while applied. This is overridden by InstantenousMobEffect to occur after one tick. If too fast, the server will not have enough time to execute the damage on the entity.
applyEffectTick Executes the logic on the entity when called.
isInstantenous Determines if the mob effect is instant. Returns true in InstantenousMobEffect.
applyInstantenousEffect Executes the logic on the entity when called. isInstantenous must return true for this to be 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.

MobEffectInstance

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.