Record Class ExplosionDefinition
java.lang.Object
java.lang.Record
johnsmith.enchantmentcore.api.enchantment.effect.ExplosionDefinition
- Record Components:
radius- TheLevelBasedValuegoverning the base blast radius of the explosion.createFire- Whether the explosion ignites fires on surrounding blocks.damageEntities- Whether the explosion inflicts blast damage to nearby entities.interaction- The block destruction behavior of the explosion (ExplosionDefinition.ExplosionInteraction).immuneFilter- An optionalContextAwarePredicateidentifying entities immune to blast damage from this explosion.smallParticles- Optional custom particle options for minor blast particles.largeParticles- Optional custom particle options for major emitter blast particles.sound- Optional custom sound event played upon detonation.
public record ExplosionDefinition(net.minecraft.world.item.enchantment.LevelBasedValue radius, boolean createFire, boolean damageEntities, ExplosionDefinition.ExplosionInteraction interaction, Optional<net.minecraft.advancements.criterion.ContextAwarePredicate> immuneFilter, Optional<net.minecraft.core.particles.ParticleOptions> smallParticles, Optional<net.minecraft.core.particles.ParticleOptions> largeParticles, Optional<net.minecraft.core.Holder<net.minecraft.sounds.SoundEvent>> sound)
extends Record
Reusable data-driven configuration record describing the parameters of an explosion triggered by
ExplosionEffect or ExplodeEffect.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumSerializable representation of vanillaLevel.ExplosionInteractionblock interaction behaviors. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final com.mojang.serialization.Codec<ExplosionDefinition> Codec for serializing and deserializingExplosionDefinitioninstances from JSON.static final StringJSON field key for toggling fire creation.static final StringJSON field key for toggling entity blast damage.static final StringJSON field key for the block interaction type.static final StringJSON field key for the entity immunity predicate filter.static final LevelBasedKeyProviderSupplies the JSON property keys holdingLevelBasedValuedefinitions for data transformation.static final StringJSON field key for custom large explosion emitter particles.static final StringJSON field key for the explosion radius.static final StringJSON field key for custom small explosion particles.static final StringJSON field key for the custom detonation sound event. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a defaultExplosionDefinition(radius 1, fire enabled, entity damage enabled, TNT interaction).ExplosionDefinition(net.minecraft.world.item.enchantment.LevelBasedValue radius, boolean createFire, boolean damageEntities, ExplosionDefinition.ExplosionInteraction interaction, Optional<net.minecraft.advancements.criterion.ContextAwarePredicate> immuneFilter, Optional<net.minecraft.core.particles.ParticleOptions> smallParticles, Optional<net.minecraft.core.particles.ParticleOptions> largeParticles, Optional<net.minecraft.core.Holder<net.minecraft.sounds.SoundEvent>> sound) Creates an instance of aExplosionDefinitionrecord class. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns the value of thecreateFirerecord component.booleanReturns the value of thedamageEntitiesrecord component.final booleanIndicates whether some other object is "equal to" this one.voidexplode(net.minecraft.server.level.ServerLevel level, int enchantmentLevel, net.minecraft.world.entity.Entity source, net.minecraft.world.phys.Vec3 pos, float scalar) Detonates an explosion in the specified server level using this definition's parameters.static net.minecraft.world.level.Level.ExplosionInteractionMaps anExplosionDefinition.ExplosionInteractionconstant to its corresponding vanillaLevel.ExplosionInteraction.final inthashCode()Returns a hash code value for this object.Optional<net.minecraft.advancements.criterion.ContextAwarePredicate> Returns the value of theimmuneFilterrecord component.Returns the value of theinteractionrecord component.Optional<net.minecraft.core.particles.ParticleOptions> Returns the value of thelargeParticlesrecord component.net.minecraft.world.item.enchantment.LevelBasedValueradius()Returns the value of theradiusrecord component.Optional<net.minecraft.core.particles.ParticleOptions> Returns the value of thesmallParticlesrecord component.Optional<net.minecraft.core.Holder<net.minecraft.sounds.SoundEvent>> sound()Returns the value of thesoundrecord component.final StringtoString()Returns a string representation of this record class.withCreateFire(boolean createFire) Returns a copy of this definition with the specified fire creation flag.withDamageEntities(boolean damageEntities) Returns a copy of this definition with the specified entity damage flag.withImmuneFilter(net.minecraft.advancements.criterion.ContextAwarePredicate immuneFilter) Returns a copy of this definition with the specified entity immunity predicate.withInteraction(ExplosionDefinition.ExplosionInteraction interaction) Returns a copy of this definition with the specified block interaction mode.withLargeParticles(net.minecraft.core.particles.ParticleOptions largeParticles) Returns a copy of this definition with custom large blast emitter particles.withRadius(net.minecraft.world.item.enchantment.LevelBasedValue radius) Returns a copy of this definition with the specified radius.withSmallParticles(net.minecraft.core.particles.ParticleOptions smallParticles) Returns a copy of this definition with custom small blast particles.withSound(net.minecraft.core.Holder<net.minecraft.sounds.SoundEvent> sound) Returns a copy of this definition with a custom detonation sound event.
-
Field Details
-
RADIUS
JSON field key for the explosion radius.- See Also:
-
CREATE_FIRE
JSON field key for toggling fire creation.- See Also:
-
DAMAGE_ENTITIES
JSON field key for toggling entity blast damage.- See Also:
-
EXPLOSION_INTERACTION
JSON field key for the block interaction type.- See Also:
-
IMMUNE_FILTER
JSON field key for the entity immunity predicate filter.- See Also:
-
SMALL_PARTICLES
JSON field key for custom small explosion particles.- See Also:
-
LARGE_PARTICLES
JSON field key for custom large explosion emitter particles.- See Also:
-
SOUND
JSON field key for the custom detonation sound event.- See Also:
-
KEY_PROVIDER
Supplies the JSON property keys holdingLevelBasedValuedefinitions for data transformation. -
CODEC
Codec for serializing and deserializingExplosionDefinitioninstances from JSON.
-
-
Constructor Details
-
ExplosionDefinition
public ExplosionDefinition()Constructs a defaultExplosionDefinition(radius 1, fire enabled, entity damage enabled, TNT interaction). -
ExplosionDefinition
public ExplosionDefinition(net.minecraft.world.item.enchantment.LevelBasedValue radius, boolean createFire, boolean damageEntities, ExplosionDefinition.ExplosionInteraction interaction, Optional<net.minecraft.advancements.criterion.ContextAwarePredicate> immuneFilter, Optional<net.minecraft.core.particles.ParticleOptions> smallParticles, Optional<net.minecraft.core.particles.ParticleOptions> largeParticles, Optional<net.minecraft.core.Holder<net.minecraft.sounds.SoundEvent>> sound) Creates an instance of aExplosionDefinitionrecord class.- Parameters:
radius- the value for theradiusrecord componentcreateFire- the value for thecreateFirerecord componentdamageEntities- the value for thedamageEntitiesrecord componentinteraction- the value for theinteractionrecord componentimmuneFilter- the value for theimmuneFilterrecord componentsmallParticles- the value for thesmallParticlesrecord componentlargeParticles- the value for thelargeParticlesrecord componentsound- the value for thesoundrecord component
-
-
Method Details
-
explode
public void explode(net.minecraft.server.level.ServerLevel level, int enchantmentLevel, net.minecraft.world.entity.Entity source, net.minecraft.world.phys.Vec3 pos, float scalar) Detonates an explosion in the specified server level using this definition's parameters.- Parameters:
level- The server level where the explosion occurs.enchantmentLevel- The active level of the enchantment, used to evaluateradius().source- The entity attributed as the cause of the explosion, ornull.pos- The world coordinates of the explosion center.scalar- A topological multiplier applied to the calculated explosion radius.
-
getVanillaInteraction
public static net.minecraft.world.level.Level.ExplosionInteraction getVanillaInteraction(ExplosionDefinition.ExplosionInteraction interaction) Maps anExplosionDefinition.ExplosionInteractionconstant to its corresponding vanillaLevel.ExplosionInteraction.- Parameters:
interaction- The Enchantment Core explosion interaction constant.- Returns:
- The corresponding vanilla
Level.ExplosionInteraction.
-
withRadius
Returns a copy of this definition with the specified radius.- Parameters:
radius- The newLevelBasedValueradius.- Returns:
- A new
ExplosionDefinitioninstance.
-
withCreateFire
Returns a copy of this definition with the specified fire creation flag.- Parameters:
createFire- Whether the explosion should create fire.- Returns:
- A new
ExplosionDefinitioninstance.
-
withDamageEntities
Returns a copy of this definition with the specified entity damage flag.- Parameters:
damageEntities- Whether the explosion should damage entities.- Returns:
- A new
ExplosionDefinitioninstance.
-
withInteraction
Returns a copy of this definition with the specified block interaction mode.- Parameters:
interaction- The newExplosionDefinition.ExplosionInteractionmode.- Returns:
- A new
ExplosionDefinitioninstance.
-
withImmuneFilter
public ExplosionDefinition withImmuneFilter(net.minecraft.advancements.criterion.ContextAwarePredicate immuneFilter) Returns a copy of this definition with the specified entity immunity predicate.- Parameters:
immuneFilter- The predicate matching entities immune to this explosion.- Returns:
- A new
ExplosionDefinitioninstance.
-
withSmallParticles
public ExplosionDefinition withSmallParticles(net.minecraft.core.particles.ParticleOptions smallParticles) Returns a copy of this definition with custom small blast particles.- Parameters:
smallParticles- The small particle options.- Returns:
- A new
ExplosionDefinitioninstance.
-
withLargeParticles
public ExplosionDefinition withLargeParticles(net.minecraft.core.particles.ParticleOptions largeParticles) Returns a copy of this definition with custom large blast emitter particles.- Parameters:
largeParticles- The large particle options.- Returns:
- A new
ExplosionDefinitioninstance.
-
withSound
public ExplosionDefinition withSound(net.minecraft.core.Holder<net.minecraft.sounds.SoundEvent> sound) Returns a copy of this definition with a custom detonation sound event.- Parameters:
sound- The sound event holder.- Returns:
- A new
ExplosionDefinitioninstance.
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
radius
public net.minecraft.world.item.enchantment.LevelBasedValue radius()Returns the value of theradiusrecord component.- Returns:
- the value of the
radiusrecord component
-
createFire
public boolean createFire()Returns the value of thecreateFirerecord component.- Returns:
- the value of the
createFirerecord component
-
damageEntities
public boolean damageEntities()Returns the value of thedamageEntitiesrecord component.- Returns:
- the value of the
damageEntitiesrecord component
-
interaction
Returns the value of theinteractionrecord component.- Returns:
- the value of the
interactionrecord component
-
immuneFilter
Returns the value of theimmuneFilterrecord component.- Returns:
- the value of the
immuneFilterrecord component
-
smallParticles
Returns the value of thesmallParticlesrecord component.- Returns:
- the value of the
smallParticlesrecord component
-
largeParticles
Returns the value of thelargeParticlesrecord component.- Returns:
- the value of the
largeParticlesrecord component
-
sound
Returns the value of thesoundrecord component.- Returns:
- the value of the
soundrecord component
-