Views
Actions
Difference between revisions of "Effects/1.16"
(Copy Mob Effects to MC1.16 archive) |
(No difference)
|
Revision as of 03:58, 27 July 2021
An Effect
is what handles the specific logic on the entity it is on. For example, Effects#SPEED
adds an attribute modifier that affects the movement speed while Effects#WITHER
attacks the entity from a DamageSource
whenever the potion effect is ready to be applied.
Creating an Effect
You can create an Effect
using two methods. The first creates a regular Effect
and applies the logic in some event method. The other method involves extending the Effect
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 Effect
or InstantEffect
.
Here are the classes and methods to review:
Class | Usage |
---|---|
Effect |
The basic effect class. Should be used if the effect happens over time. |
InstantEffect |
An extended version of the effect class. Should be used if the effect happens only once and instantly. |
Method | Description |
---|---|
isReady |
Determines how fast an effect should call performEffect while applied. This is overridden by InstantEffect to occur after one tick. If too fast, the server will not have enough time to execute the damage on the entity.
|
performEffect |
Executes the logic on the entity when called. |
isInstant |
Determines if the effect is instant. Returns true in InstantEffect .
|
affectEntity |
Executes the logic on the entity when called. isInstant 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 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.
Effects need to be registered/1.16.
EffectInstance
To allow greater customization, each effect is passed in as an EffectInstance
which allows the user to specify additional information for what the effect should do.