Class DamageType
java.lang.Object
net.minestom.server.entity.damage.DamageType
- All Implemented Interfaces:
Taggable
,TagReadable
,TagWritable
- Direct Known Subclasses:
EntityDamage
,EntityProjectileDamage
Represents a type of damage, required when calling
LivingEntity.damage(DamageType, float)
and retrieved in EntityDamageEvent
.
This class can be extended if you need to include custom fields and/or methods.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DamageType
static final DamageType
static final DamageType
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription@Nullable Component
buildDeathMessage
(@NotNull Player killed) Builds the death message linked to this damage type.@Nullable Component
buildDeathScreenText
(@NotNull Player killed) Builds the text sent to a player in his death screen.static @NotNull EntityDamage
fromEntity
(@NotNull Entity entity) Convenient method to create anEntityDamage
.static @NotNull EntityDamage
fromPlayer
(@NotNull Player player) Convenient method to create anEntityDamage
.static @NotNull DamageType
fromProjectile
(@Nullable Entity shooter, @NotNull Entity projectile) Convenient method to create anEntityProjectileDamage
.protected SoundEvent
getGenericSound
(@NotNull LivingEntity entity) @NotNull String
Gets the identifier of this damage type.protected SoundEvent
getPlayerSound
(@NotNull Player player) @Nullable SoundEvent
getSound
(@NotNull LivingEntity entity) Sound event to play when the given entity is hit by this damage.@NotNull TagHandler
-
Field Details
-
VOID
-
GRAVITY
-
ON_FIRE
-
-
Constructor Details
-
DamageType
Creates a new damage type.- Parameters:
identifier
- the identifier of this damage type, does not need to be unique
-
-
Method Details
-
getIdentifier
Gets the identifier of this damage type.It does not have to be unique to this object.o
- Returns:
- the damage type identifier
-
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
@NotNull public static @NotNull DamageType fromProjectile(@Nullable @Nullable Entity shooter, @NotNull @NotNull Entity projectile) Convenient method to create anEntityProjectileDamage
.- Parameters:
shooter
- the shooterprojectile
- the actual projectile- Returns:
- a new
EntityProjectileDamage
-
fromPlayer
Convenient method to create anEntityDamage
.- Parameters:
player
- the player damager- Returns:
- a new
EntityDamage
-
fromEntity
Convenient method to create anEntityDamage
.- Parameters:
entity
- the entity damager- Returns:
- a new
EntityDamage
-
buildDeathScreenText
Builds the text sent to a player in his death screen.- Parameters:
killed
- the player who has been killed- Returns:
- the death screen text, null to do not send anything
-
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:
tagHandler
in interfaceTaggable
-