Record Class ExplosionDefinition

java.lang.Object
java.lang.Record
johnsmith.enchantmentcore.api.enchantment.effect.ExplosionDefinition
Record Components:
radius - The LevelBasedValue governing 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 optional ContextAwarePredicate identifying 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.
  • Field Details

    • RADIUS

      public static final String RADIUS
      JSON field key for the explosion radius.
      See Also:
    • CREATE_FIRE

      public static final String CREATE_FIRE
      JSON field key for toggling fire creation.
      See Also:
    • DAMAGE_ENTITIES

      public static final String DAMAGE_ENTITIES
      JSON field key for toggling entity blast damage.
      See Also:
    • EXPLOSION_INTERACTION

      public static final String EXPLOSION_INTERACTION
      JSON field key for the block interaction type.
      See Also:
    • IMMUNE_FILTER

      public static final String IMMUNE_FILTER
      JSON field key for the entity immunity predicate filter.
      See Also:
    • SMALL_PARTICLES

      public static final String SMALL_PARTICLES
      JSON field key for custom small explosion particles.
      See Also:
    • LARGE_PARTICLES

      public static final String LARGE_PARTICLES
      JSON field key for custom large explosion emitter particles.
      See Also:
    • SOUND

      public static final String SOUND
      JSON field key for the custom detonation sound event.
      See Also:
    • KEY_PROVIDER

      public static final LevelBasedKeyProvider KEY_PROVIDER
      Supplies the JSON property keys holding LevelBasedValue definitions for data transformation.
    • CODEC

      public static final com.mojang.serialization.Codec<ExplosionDefinition> CODEC
      Codec for serializing and deserializing ExplosionDefinition instances from JSON.
  • Constructor Details

    • ExplosionDefinition

      public ExplosionDefinition()
      Constructs a default ExplosionDefinition (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 a ExplosionDefinition record class.
      Parameters:
      radius - the value for the radius record component
      createFire - the value for the createFire record component
      damageEntities - the value for the damageEntities record component
      interaction - the value for the interaction record component
      immuneFilter - the value for the immuneFilter record component
      smallParticles - the value for the smallParticles record component
      largeParticles - the value for the largeParticles record component
      sound - the value for the sound record 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 evaluate radius().
      source - The entity attributed as the cause of the explosion, or null.
      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 an ExplosionDefinition.ExplosionInteraction constant to its corresponding vanilla Level.ExplosionInteraction.
      Parameters:
      interaction - The Enchantment Core explosion interaction constant.
      Returns:
      The corresponding vanilla Level.ExplosionInteraction.
    • withRadius

      public ExplosionDefinition withRadius(net.minecraft.world.item.enchantment.LevelBasedValue radius)
      Returns a copy of this definition with the specified radius.
      Parameters:
      radius - The new LevelBasedValue radius.
      Returns:
      A new ExplosionDefinition instance.
    • withCreateFire

      public ExplosionDefinition withCreateFire(boolean createFire)
      Returns a copy of this definition with the specified fire creation flag.
      Parameters:
      createFire - Whether the explosion should create fire.
      Returns:
      A new ExplosionDefinition instance.
    • withDamageEntities

      public ExplosionDefinition withDamageEntities(boolean damageEntities)
      Returns a copy of this definition with the specified entity damage flag.
      Parameters:
      damageEntities - Whether the explosion should damage entities.
      Returns:
      A new ExplosionDefinition instance.
    • withInteraction

      public ExplosionDefinition withInteraction(ExplosionDefinition.ExplosionInteraction interaction)
      Returns a copy of this definition with the specified block interaction mode.
      Parameters:
      interaction - The new ExplosionDefinition.ExplosionInteraction mode.
      Returns:
      A new ExplosionDefinition instance.
    • 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 ExplosionDefinition instance.
    • 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 ExplosionDefinition instance.
    • 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 ExplosionDefinition instance.
    • 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 ExplosionDefinition instance.
    • toString

      public final String 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.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • radius

      public net.minecraft.world.item.enchantment.LevelBasedValue radius()
      Returns the value of the radius record component.
      Returns:
      the value of the radius record component
    • createFire

      public boolean createFire()
      Returns the value of the createFire record component.
      Returns:
      the value of the createFire record component
    • damageEntities

      public boolean damageEntities()
      Returns the value of the damageEntities record component.
      Returns:
      the value of the damageEntities record component
    • interaction

      Returns the value of the interaction record component.
      Returns:
      the value of the interaction record component
    • immuneFilter

      public Optional<net.minecraft.advancements.criterion.ContextAwarePredicate> immuneFilter()
      Returns the value of the immuneFilter record component.
      Returns:
      the value of the immuneFilter record component
    • smallParticles

      public Optional<net.minecraft.core.particles.ParticleOptions> smallParticles()
      Returns the value of the smallParticles record component.
      Returns:
      the value of the smallParticles record component
    • largeParticles

      public Optional<net.minecraft.core.particles.ParticleOptions> largeParticles()
      Returns the value of the largeParticles record component.
      Returns:
      the value of the largeParticles record component
    • sound

      public Optional<net.minecraft.core.Holder<net.minecraft.sounds.SoundEvent>> sound()
      Returns the value of the sound record component.
      Returns:
      the value of the sound record component