Interface AttackEntityEvent
-
- All Superinterfaces:
Cancellable
,Event
- All Known Implementing Classes:
AbstractAttackEntityEvent
public interface AttackEntityEvent extends Event, Cancellable
Represents the base event for when anEntity
is being "attacked". The uniqueness of this event is that allDamageSource
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, theAttackEntityEvent
can be summarized as so:An
ArrowEntity
, that was shot by aSkeleton
, with an enchantedItemTypes.BOW
ItemStack
, when theWorld
Difficulty
was set toDifficulties.HARD
, will deal possibly "5" damage to anyEntity
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 particularDamageType
, has no static finalized amount of damage to deal to a particularEntity
. To properly represent this, aDamageSource
has various "states" such as:DamageSource.isAbsolute()
, orDamageSource.isBypassingArmor()
. Quite simply, theDamageSource
will always be the "first" element within aCause
that can be retrieved fromEvent.cause()
.Next, any additional "aides" in attacking the
Entity
will be included in order of "priority of relation" to "attacking" the entity. In short, if anotherEntity
is considered a "team member" to the attackingEntity
, the "team member" may be a second element within theCause
. The same can be said if anArrowEntity
was shot from aDispenser
that was triggered by aPlayer
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 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 aFunction
that are applied to the "base" damage. Given thatCause
has a unique capability of storing any and everyObject
willing to be passed into it, we can easily represent these "sources" of "modifiers" in aCause
. Now, knowing the "source" will not provide enough information, so aDamageModifierType
is provided with aDamageModifier
to paint the fullest picture of "explaining" theDamageModifier
as to why it is present, and why it is "modifying" the "base" damage. Finally, we can associate aDamageModifier
with aFunction
that is passed the current "damage" intoFunction.apply(Object)
, being added to the current "damage". After allDamageModifier
Function
s are "applied", the overall "damage" is now the final damage to actually throw aAttackEntityEvent
.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 forfinalOutputDamage()
can be exemplified like so:double damage = this.baseDamage;<br /> 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
provided in this event.Coming forward, it is possible to further customize not only the "base" damage, but override pre-existing
DamageModifier
Function
s by callingsetOutputDamage(DamageModifier, DoubleUnaryOperator)
at which point the end result may be undefined. However, if a customDamageModifier
that aims to alter the "final" damage based on some custom circumstances, callingsetOutputDamage(DamageModifier, DoubleUnaryOperator)
on a newDamageModifier
instance, easily created from theDamageModifier.Builder
, 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 incoming damage to an
Entity
prior to anyDamageModifier
s associated with theentity()
. TheAttackEntityEvent
is used to process the variousDamageModifier
s of which originate or are associated with the targetedEntity
.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ABSORPTION
For use with aDamageModifier
where it's type is aDamageModifierTypes.ABSORPTION
and theCause
contains aPotionEffect
.static java.lang.String
BOOTS
For use with aDamageModifier
where it's type is aDamageModifierTypes.ARMOR
and theCause
contains anItemStackSnapshot
for "boots".static java.lang.String
CHESTPLATE
For use with aDamageModifier
where it's type is aDamageModifierTypes.ARMOR
and theCause
contains anItemStackSnapshot
for a "chestplate".static java.lang.String
CREATOR
For use with aDamageModifier
where the root cause is "created" by an object, usually theEntity
orLiving
entity.static java.lang.String
GENERAL_ARMOR
For use with aDamageModifier
where it's type is aDamageModifierTypes.ARMOR
and theCause
contains anItemStackSnapshot
.static java.lang.String
HARD_HAT_ARMOR
For use with aDamageModifier
where it's type is aDamageModifierTypes.HARD_HAT
and theCause
contains anItemStackSnapshot
, usually a helmet.static java.lang.String
HELMET
For use with aDamageModifier
where it's type is aDamageModifierTypes.ARMOR
and theCause
contains anItemStackSnapshot
for a "helmet".static java.lang.String
LEGGINGS
For use with aDamageModifier
where it's type is aDamageModifierTypes.ARMOR
and theCause
contains anItemStackSnapshot
for "leggings".static java.lang.String
NOTIFIER
For use with aDamageSource
where it is either aBlockDamageSource
orEntityDamageSource
such that it was last "notified" by the object represented in the cause.static java.lang.String
RESISTANCE
For use with aDamageModifier
where it's type is aDamageModifierTypes.HARD_HAT
and theCause
contains aPotionEffect
.static java.lang.String
SHIELD
or use with aDamageModifier
where its type is aDamageModifierTypes.SHIELD
and theCause
contains anItemStackSnapshot
(in Vanilla, a shield).static java.lang.String
SOURCE
For use with theDamageSource
that is known as the "source" of the damage.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
addDamageModifierAfter(DamageModifier damageModifier, java.util.function.DoubleUnaryOperator function, java.util.Set<DamageModifierType> after)
Adds the providedDamageModifier
andFunction
to the list of modifiers, such that the modifier will appear in order after any current modifiers whose type are included in the providedSet
ofDamageModifierType
s.void
addDamageModifierBefore(DamageModifier damageModifier, java.util.function.DoubleUnaryOperator function, java.util.Set<DamageModifierType> before)
Adds the providedDamageModifier
andFunction
to the list of modifiers, such that theSet
containingDamageModifierType
s provided inbefore
will appear after the provided damage modifier.double
baseOutputDamage()
Gets the "base" damage to deal to the targetedEntity
.Entity
entity()
Gets theEntity
.double
finalOutputDamage()
Gets the final damage that will be passed into the proceedingAttackEntityEvent
.boolean
isModifierApplicable(DamageModifier damageModifier)
Checks whether the providedDamageModifier
is applicable to the current availableDamageModifier
s.float
knockbackModifier()
Gets the knock back modifier.java.util.List<DamageFunction>
modifiers()
double
originalDamage()
Gets the original "raw" amount of damage to deal to the targetedEntity
.java.util.Map<DamageModifier,java.lang.Double>
originalDamages()
Gets anImmutableMap
of all originalDamageModifier
s and their associated "modified" damage.double
originalFinalDamage()
Gets the original "final" amount of damage after all originalDamageModifier
s are applied tooriginalDamage()
.java.util.List<DamageFunction>
originalFunctions()
double
originalModifierDamage(DamageModifier damageModifier)
Gets the original damage for the providedDamageModifier
.double
outputDamage(DamageModifier damageModifier)
Gets the damage for the providedDamageModifier
.void
setBaseOutputDamage(double baseDamage)
Sets the "base" damage to deal to the targetedEntity
.void
setKnockbackModifier(float modifier)
Sets the knock back modifier.void
setOutputDamage(DamageModifier damageModifier, java.util.function.DoubleUnaryOperator function)
Sets the providedFunction
to be used for the givenDamageModifier
.-
Methods inherited from interface org.spongepowered.api.event.Cancellable
isCancelled, setCancelled
-
-
-
-
Field Detail
-
SOURCE
static final java.lang.String SOURCE
For use with theDamageSource
that is known as the "source" of the damage.- See Also:
- Constant Field Values
-
HARD_HAT_ARMOR
static final java.lang.String HARD_HAT_ARMOR
For use with aDamageModifier
where it's type is aDamageModifierTypes.HARD_HAT
and theCause
contains anItemStackSnapshot
, usually a helmet.- See Also:
- Constant Field Values
-
SHIELD
static final java.lang.String SHIELD
or use with aDamageModifier
where its type is aDamageModifierTypes.SHIELD
and theCause
contains anItemStackSnapshot
(in Vanilla, a shield).- See Also:
- Constant Field Values
-
GENERAL_ARMOR
static final java.lang.String GENERAL_ARMOR
For use with aDamageModifier
where it's type is aDamageModifierTypes.ARMOR
and theCause
contains anItemStackSnapshot
. Separate from hard hat but still considered as "armor" where it will absorb a certain amount of damage before dealing damage to the wearer.- See Also:
- Constant Field Values
-
HELMET
static final java.lang.String HELMET
For use with aDamageModifier
where it's type is aDamageModifierTypes.ARMOR
and theCause
contains anItemStackSnapshot
for a "helmet".- See Also:
- Constant Field Values
-
CHESTPLATE
static final java.lang.String CHESTPLATE
For use with aDamageModifier
where it's type is aDamageModifierTypes.ARMOR
and theCause
contains anItemStackSnapshot
for a "chestplate".- See Also:
- Constant Field Values
-
LEGGINGS
static final java.lang.String LEGGINGS
For use with aDamageModifier
where it's type is aDamageModifierTypes.ARMOR
and theCause
contains anItemStackSnapshot
for "leggings".- See Also:
- Constant Field Values
-
BOOTS
static final java.lang.String BOOTS
For use with aDamageModifier
where it's type is aDamageModifierTypes.ARMOR
and theCause
contains anItemStackSnapshot
for "boots".- See Also:
- Constant Field Values
-
RESISTANCE
static final java.lang.String RESISTANCE
For use with aDamageModifier
where it's type is aDamageModifierTypes.HARD_HAT
and theCause
contains aPotionEffect
.- See Also:
- Constant Field Values
-
ABSORPTION
static final java.lang.String ABSORPTION
For use with aDamageModifier
where it's type is aDamageModifierTypes.ABSORPTION
and theCause
contains aPotionEffect
.- See Also:
- Constant Field Values
-
CREATOR
static final java.lang.String CREATOR
For use with aDamageModifier
where the root cause is "created" by an object, usually theEntity
orLiving
entity.- See Also:
- Constant Field Values
-
NOTIFIER
static final java.lang.String NOTIFIER
For use with aDamageSource
where it is either aBlockDamageSource
orEntityDamageSource
such that it was last "notified" by the object represented in the cause.Usually this is used where a
Player
interacted with the nowDamageSource
such that they- See Also:
- Constant Field Values
-
-
Method Detail
-
originalDamage
double originalDamage()
Gets the original "raw" amount of damage to deal to the targetedEntity
.- Returns:
- The original "raw" damage
-
originalFinalDamage
double originalFinalDamage()
Gets the original "final" amount of damage after all originalDamageModifier
s are applied tooriginalDamage()
. The "final" damage is considered the amount of health being lost by theEntity
, if health is tracked.- Returns:
- The final amount of damage to originally deal
-
originalDamages
java.util.Map<DamageModifier,java.lang.Double> originalDamages()
Gets anImmutableMap
of all originalDamageModifier
s and their associated "modified" damage. Note that ordering is not retained.- Returns:
- An immutable map of the original modified damages
-
originalModifierDamage
double originalModifierDamage(DamageModifier damageModifier)
Gets the original damage for the providedDamageModifier
. If the providedDamageModifier
was not included inoriginalDamages()
, anIllegalArgumentException
is thrown.- Parameters:
damageModifier
- The original damage modifier- Returns:
- The original damage change
-
originalFunctions
java.util.List<DamageFunction> originalFunctions()
- Returns:
- The list of damage modifier functions
-
baseOutputDamage
double baseOutputDamage()
Gets the "base" damage to deal to the targetedEntity
. The "base" damage is the original value before passing along the chain ofFunction
s for all knownDamageModifier
s.- Returns:
- The base damage
-
setBaseOutputDamage
void setBaseOutputDamage(double baseDamage)
Sets the "base" damage to deal to the targetedEntity
. The "base" damage is the original value before passing along the chain ofFunction
s for all knownDamageModifier
s.- Parameters:
baseDamage
- The base damage
-
finalOutputDamage
double finalOutputDamage()
Gets the final damage that will be passed into the proceedingAttackEntityEvent
. The final damage is the end result of thebaseOutputDamage()
being applied inFunction.apply(Object)
available from all theTuple
s ofDamageModifier
toFunction
inoriginalFunctions()
.- Returns:
- The final damage to deal
-
isModifierApplicable
boolean isModifierApplicable(DamageModifier damageModifier)
Checks whether the providedDamageModifier
is applicable to the current availableDamageModifier
s.- Parameters:
damageModifier
- The damage modifier to check- Returns:
- True if the damage modifier is relevant to this event
-
outputDamage
double outputDamage(DamageModifier damageModifier)
Gets the damage for the providedDamageModifier
. Providing thatisModifierApplicable(DamageModifier)
returnstrue
, the cached "damage" for theDamageModifier
is returned.- Parameters:
damageModifier
- The damage modifier to get the damage for- Returns:
- The modifier
-
setOutputDamage
void setOutputDamage(DamageModifier damageModifier, java.util.function.DoubleUnaryOperator function)
Sets the providedFunction
to be used for the givenDamageModifier
. If theDamageModifier
is already included inmodifiers()
, theFunction
replaces the existing function. If there is noTuple
for theDamageModifier
, a new one is created and added to the end of the list ofFunction
s to be applied to thebaseOutputDamage()
.If needing to create a custom
DamageModifier
is required, usage of theDamageModifier.Builder
is recommended.- Parameters:
damageModifier
- The damage modifierfunction
- The function to map to the modifier
-
addDamageModifierBefore
void addDamageModifierBefore(DamageModifier damageModifier, java.util.function.DoubleUnaryOperator function, java.util.Set<DamageModifierType> before)
Adds the providedDamageModifier
andFunction
to the list of modifiers, such that theSet
containingDamageModifierType
s provided inbefore
will appear after the provided damage modifier.- Parameters:
damageModifier
- The damage modifier to addfunction
- The associated functionbefore
- The set containing the modifier types to come after the provided modifier
-
addDamageModifierAfter
void addDamageModifierAfter(DamageModifier damageModifier, java.util.function.DoubleUnaryOperator function, java.util.Set<DamageModifierType> after)
Adds the providedDamageModifier
andFunction
to the list of modifiers, such that the modifier will appear in order after any current modifiers whose type are included in the providedSet
ofDamageModifierType
s.- Parameters:
damageModifier
- The damage modifier to addfunction
- The associated functionafter
- The set of modifier types to come before the new modifier
-
modifiers
java.util.List<DamageFunction> modifiers()
Gets a list of simpleTuple
s ofDamageModifier
keyed to their representativeFunction
s. AllDamageModifier
s are applicable to the entity based on theDamageSource
and any possible invulnerabilities due to theDamageSource
.- Returns:
- A list of damage modifiers to functions
-
knockbackModifier
float knockbackModifier()
Gets the knock back modifier. The modifier itself will apply to the momentum of the attacked entity.- Returns:
- The knock back modifier
-
setKnockbackModifier
void setKnockbackModifier(float modifier)
Sets the knock back modifier. The modifier itself will apply to the momentum of the attacked entity.- Parameters:
modifier
- The knock back modifier to set
-
-