Class Damage
java.lang.Object
net.minestom.server.entity.damage.Damage
- All Implemented Interfaces:
Taggable, TagReadable, TagWritable
- Direct Known Subclasses:
EntityDamage, EntityProjectileDamage, PositionalDamage
Represents a type of damage, required when calling
LivingEntity.damage(Damage)
and retrieved in EntityDamageEvent.
This class can be extended if you need to include custom fields and/or methods.
-
Constructor Summary
ConstructorsConstructorDescriptionDamage(RegistryKey<DamageType> type, @Nullable Entity source, @Nullable Entity attacker, @Nullable Point sourcePosition, float amount) Creates a new damage type. -
Method Summary
Modifier and TypeMethodDescriptionbuildDeathMessage(Player killed) Builds the death message linked to this damage type.buildDeathScreenText(Player killed) Builds the text sent to a player in his death screen.static EntityDamagefromEntity(Entity entity, float amount) Convenient method to create anEntityDamage.static EntityDamagefromPlayer(Player player, float amount) Convenient method to create anEntityDamage.static PositionalDamagefromPosition(RegistryKey<DamageType> type, Point sourcePosition, float amount) static DamagefromProjectile(@Nullable Entity shooter, Entity projectile, float amount) Convenient method to create anEntityProjectileDamage.floatGets the "attacker" of the damage.protected SoundEventgetGenericSound(LivingEntity entity) protected SoundEventgetPlayerSound(Player player) getSound(LivingEntity entity) Sound event to play when the given entity is hit by this damage.Gets the direct source of the damage.Gets the position of the source of the damage, or null if there is none.getType()Gets the type of this damage.intGets the integer id of the damage type that has been setvoidsetAmount(float amount) Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Taggable
getAndSetTag, getAndUpdateTag, getTag, hasTag, removeTag, setTag, updateAndGetTag, updateTag
-
Constructor Details
-
Damage
public Damage(RegistryKey<DamageType> type, @Nullable @Nullable Entity source, @Nullable @Nullable Entity attacker, @Nullable @Nullable Point sourcePosition, float amount) Creates a new damage type.- Parameters:
type- the type of this damagesource- The source of the damage. For direct hits (melee), this will be the same as the attacker. For indirect hits (projectiles), this will be the projectileattacker- The attacker that initiated this damagesourcePosition- The position of the source of damageamount- amount of damage
-
-
Method Details
-
getType
Gets the type of this damage.It does not have to be unique to this object.
- Returns:
- the damage type
-
getTypeId
public int getTypeId()Gets the integer id of the damage type that has been set- Returns:
- The integer id of the damage type
-
getAttacker
-
getSource
-
getSourcePosition
-
buildDeathMessage
Builds the death message linked to this damage type.Used in
Player.kill()to broadcast the proper message.- Parameters:
killed- the player who has been killed- Returns:
- the death message, null to do not send anything
-
fromProjectile
public static Damage fromProjectile(@Nullable @Nullable Entity shooter, Entity projectile, float amount) Convenient method to create anEntityProjectileDamage.- Parameters:
shooter- the shooterprojectile- the actual projectileamount- amount of damage- Returns:
- a new
EntityProjectileDamage
-
fromPlayer
Convenient method to create anEntityDamage.- Parameters:
player- the player damageramount- amount of damage- Returns:
- a new
EntityDamage
-
fromEntity
Convenient method to create anEntityDamage.- Parameters:
entity- the entity damageramount- amount of damage- Returns:
- a new
EntityDamage
-
fromPosition
public static PositionalDamage fromPosition(RegistryKey<DamageType> type, Point sourcePosition, float amount) -
buildDeathScreenText
-
getSound
Sound event to play when the given entity is hit by this damage. Possible to return null if no sound should be played- Parameters:
entity- the entity hit by this damage- Returns:
- the sound to play when the given entity is hurt by this damage type. Can be null if no sound should play
-
getGenericSound
-
getPlayerSound
-
tagHandler
- Specified by:
tagHandlerin interfaceTaggable
-
getAmount
public float getAmount() -
setAmount
public void setAmount(float amount)
-