public static interface InteractEntityEvent.Attack extends InteractEntityEvent
Entity
is being
"attacked". The uniqueness of this event is that all
DamageSource
s can deal varying amounts of damage with varying
modifiers based on various reasons. Due to this ambiguous variety of
information that is possible to provide, the InteractEntityEvent.Attack
can be summarized as so:
An Arrow
,
that was shot by a Skeleton
,
with an enchanted ItemTypes.BOW
ItemStack
,
when the World
Difficulty
was set to
Difficulties.HARD
,
will deal possibly "5" damage to any Entity
it hits.
The issue with representing this type of "logic flow" is that a
particular amount of damage from a DamageSource
, even if
specified to a particular DamageType
, has no static finalized
amount of damage to deal to a particular Entity
. To properly
represent this, a DamageSource
has various "states" such as:
DamageSource.isAbsolute()
or
DamageSource.isBypassingArmor()
. Quite simply, the
DamageSource
will always be the "first" element within a
Cause
that can be retrieved from CauseTracked.getCause()
.
Next, any additional "aides" in attacking the Entity
will
be included in order of "priority of relation" to "attacking" the
entity. In short, if another Entity
is considered a "team
member" to the attacking Entity
, the "team member" may be a
second element within the Cause
. The same can be said if an
Arrow
was shot from a Dispenser
that was triggered by a
Player
flipping a switch.
Continuing with the notion of "modifiers" to damage, the "base"
damage is modified or added onto after various unknown methods are
called or processed on the damage. Optimally, these modifiers can be
traced to a particular object, be it an ItemStack
,
Difficulty
, or simply an Attribute
. The interesting part
is that these "modifiers" do not just define a static value to add to
the "base" damage, they are usually a loose form of a Function
that are applied to the "base" damage. Given that Cause
has a
unique capability of storing any and every Object
willing to be
passed into it, we can easily represent these "sources" of "modifiers"
in a Cause
. Now, knowning the "source" will not provide enough
information, so a DamageModifierType
is provided with a
DamageModifier
to paint the fullest picture of "explaining" the
DamageModifier
as to why it is present, and why it is
"modifying" the "base" damage. Finally, we can associate a
DamageModifier
with a Function
that is passed the
current "damage" into Function.apply(Object)
, being added to the
current "damage". After all DamageModifier
Function
s
are "applied", the overall "damage" is now the final damage to actually
throw a DamageEntityEvent
.
Note that due to the mechanics of the game, DamageModifier
s
are always ordered in the order of which they apply their modifier onto
the "base" damage. The implementation for getFinalDamage()
can
be exemplified like so:
double damage = this.baseDamage;
for (Map.Entry<DamageModifier, Function<? super Double, Double>> entry : this.modifierFunctions.entrySet()) {
damage += checkNotNull(entry.getValue().apply(damage));
}
return damage;
After which, the "final" damage is simply the summation of the
"base" damage and all "modified damage" for each DamageModifier
prorivded in this event.
Coming forward, it is possible to further customize not only the
"base" damage, but override pre-existing DamageModifier
Function
s by calling
setDamage(DamageModifier, Function)
at which point the
end result may be undefined. However, if a custom DamageModifier
that aims to alter the "final" damage based on some custom
circumstances, calling setDamage(DamageModifier, Function)
on a
new DamageModifier
instance, easily created from the
DamageModifierBuilder
, the provided pairing will be added at the
"end" of the list for "modifying" the "base" damage.
Note that this event is intended for processing incomming damage to
an Entity
prior to any DamageModifier
s associated with
the TargetEntityEvent.getTargetEntity()
. The DamageEntityEvent
is used
to process the various DamageModifier
s of which originate or are
associated with the targeted Entity
.
InteractEntityEvent.Attack, InteractEntityEvent.Use
Modifier and Type | Method and Description |
---|---|
double |
getBaseDamage()
Gets the "base" damage to deal to the targeted
Entity . |
double |
getDamage(DamageModifier damageModifier)
Gets the damage for the provided
DamageModifier . |
double |
getFinalDamage()
Gets the final damage that will be passed into the proceeding
DamageEntityEvent . |
List<Tuple<DamageModifier,Function<? super Double,Double>>> |
getModifiers()
|
double |
getOriginalDamage()
Gets the original "raw" amount of damage to deal to the targeted
Entity . |
Map<DamageModifier,Double> |
getOriginalDamages()
Gets an immutable
Map of all original
DamageModifier s and their associated "modified" damage. |
double |
getOriginalFinalDamage()
Gets the original "final" amount of damage after all original
DamageModifier s are applied to getOriginalDamage() . |
List<Tuple<DamageModifier,Function<? super Double,Double>>> |
getOriginalFunctions()
|
double |
getOriginalModifierDamage(DamageModifier damageModifier)
Gets the original damage for the provided
DamageModifier . |
boolean |
isModifierApplicable(DamageModifier damageModifier)
Checks whether the provided
DamageModifier is applicable to
the current available DamageModifier s. |
void |
setBaseDamage(double baseDamage)
Sets the "base" damage to deal to the targeted
Entity . |
void |
setDamage(DamageModifier damageModifier,
Function<? super Double,Double> function)
Sets the provided
Function to be used for the given
DamageModifier . |
getInteractionPoint
isCancelled, setCancelled
getCause
getTargetEntity
getCallbacks
double getOriginalDamage()
Entity
.double getOriginalFinalDamage()
DamageModifier
s are applied to getOriginalDamage()
.
The "final" damage is considered the amount of health being lost by
the Entity
, if health is tracked.Map<DamageModifier,Double> getOriginalDamages()
Map
of all original
DamageModifier
s and their associated "modified" damage. Note
that ordering is not retained.double getOriginalModifierDamage(DamageModifier damageModifier)
DamageModifier
. If
the provided DamageModifier
was not included in
getOriginalDamages()
, an IllegalArgumentException
is thrown.damageModifier
- The original damage modifierList<Tuple<DamageModifier,Function<? super Double,Double>>> getOriginalFunctions()
double getBaseDamage()
Entity
. The
"base" damage is the original value before passing along the chain
of Function
s for all known DamageModifier
s.void setBaseDamage(double baseDamage)
Entity
. The
"base" damage is the original value before passing along the chain
of Function
s for all known DamageModifier
s.baseDamage
- The base damagedouble getFinalDamage()
DamageEntityEvent
. The final damage is the end result of the
getBaseDamage()
being applied in
Function.apply(Object)
available from all the Tuple
s
of DamageModifier
to Function
in
getOriginalFunctions()
.boolean isModifierApplicable(DamageModifier damageModifier)
DamageModifier
is applicable to
the current available DamageModifier
s.damageModifier
- The damage modifier to checkdouble getDamage(DamageModifier damageModifier)
DamageModifier
. Providing
that isModifierApplicable(DamageModifier)
returns
true
, the cached "damage" for the
DamageModifier
is returned.damageModifier
- The damage modifier to get the damage forvoid setDamage(DamageModifier damageModifier, Function<? super Double,Double> function)
Function
to be used for the given
DamageModifier
. If the DamageModifier
is already
included in getModifiers()
, the Function
replaces
the existing function. If there is no Tuple
for the
DamageModifier
, a new one is created and added to the end
of the list of Function
s to be applied to the
getBaseDamage()
.
If needing to create a custom DamageModifier
is required,
usage of the DamageModifierBuilder
is recommended.
damageModifier
- The damage modifierfunction
- The function to map to the modifierList<Tuple<DamageModifier,Function<? super Double,Double>>> getModifiers()
Tuple
s of DamageModifier
keyed
to their representative Function
s. All
DamageModifier
s are applicable to the entity based on the
DamageSource
and any possible invulnerabilities due to the
DamageSource
.