Record Class PlaceTemporaryBlockEffect

java.lang.Object
java.lang.Record
johnsmith.enchantmentcore.api.enchantment.spellfield.effect.block.PlaceTemporaryBlockEffect
Record Components:
block - The temporary Block to place in the world.
lifetime - The LevelBasedValue duration (in ticks) the temporary block remains stable before decaying.
decayDuration - The LevelBasedValue duration (in ticks) of the block-breaking crack animation prior to restoration.
requireAir - Whether placement should be restricted to replaceable blocks (such as air, grass, or fluids).
restorePrevious - Whether the original block state should be restored upon expiration (if false, restores air).
evaluator - The TopologyEvaluator governing deterministic threshold or probabilistic block selection.
All Implemented Interfaces:
SpellFieldBlockEffect, SpellFieldEffect

public record PlaceTemporaryBlockEffect(net.minecraft.world.level.block.Block block, net.minecraft.world.item.enchantment.LevelBasedValue lifetime, net.minecraft.world.item.enchantment.LevelBasedValue decayDuration, boolean requireAir, boolean restorePrevious, TopologyEvaluator evaluator) extends Record implements SpellFieldBlockEffect
A SpellFieldBlockEffect that temporarily places a configured Block at target coordinates and schedules automatic restoration via TransientBlockTracker.

Safely handles repeated applications from persistent spell field anchors and chunk unload/reload cycles by verifying that the target chunk is actively ticking blocks and by consulting TransientBlockTracker to preserve the true pre-spell BlockState and BlockEntity metadata.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    JSON field key for the temporary block to place.
    static final com.mojang.serialization.MapCodec<PlaceTemporaryBlockEffect>
    MapCodec for serializing and deserializing PlaceTemporaryBlockEffect definitions.
    static final String
    JSON field key for the visual crack decay duration in ticks.
    static final String
    JSON field key for the topological threshold/probability evaluator.
    static final String
    Registry path identifier for this spell field block effect.
    Supplies the JSON property keys that hold LevelBasedValue definitions for data transformation.
    static final String
    JSON field key for the stable lifetime duration in ticks.
    static final String
    JSON field key for restricting placement to replaceable blocks.
    static final String
    JSON field key for toggling restoration of the prior block state versus air.
  • Constructor Summary

    Constructors
    Constructor
    Description
    PlaceTemporaryBlockEffect(net.minecraft.world.level.block.Block block, net.minecraft.world.item.enchantment.LevelBasedValue lifetime, net.minecraft.world.item.enchantment.LevelBasedValue decayDuration, boolean requireAir, boolean restorePrevious)
    Constructs a PlaceTemporaryBlockEffect using the default TopologyEvaluator.PROBABILISTIC evaluator.
    PlaceTemporaryBlockEffect(net.minecraft.world.level.block.Block block, net.minecraft.world.item.enchantment.LevelBasedValue lifetime, net.minecraft.world.item.enchantment.LevelBasedValue decayDuration, boolean requireAir, boolean restorePrevious, TopologyEvaluator evaluator)
    Creates an instance of a PlaceTemporaryBlockEffect record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    apply(net.minecraft.server.level.ServerLevel level, int enchantmentLevel, net.minecraft.world.item.enchantment.EnchantedItemInUse context, net.minecraft.world.entity.Entity spatialReference, net.minecraft.world.phys.Vec3 epicenter, net.minecraft.core.BlockPos pos, float scalar, Set<net.minecraft.core.BlockPos> modifiedBlocks)
    Applies the temporary block placement at the target coordinate and registers restoration with TransientBlockTracker.
    net.minecraft.world.level.block.Block
    Returns the value of the block record component.
    com.mojang.serialization.MapCodec<? extends SpellFieldBlockEffect>
    Retrieves the MapCodec responsible for serializing and deserializing this effect.
    net.minecraft.world.item.enchantment.LevelBasedValue
    Returns the value of the decayDuration record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    Returns the value of the evaluator record component.
    float
    getPriority(int enchantmentLevel)
    Returns the execution priority of this block effect based on the evaluator's threshold.
    final int
    Returns a hash code value for this object.
    net.minecraft.world.item.enchantment.LevelBasedValue
    Returns the value of the lifetime record component.
    boolean
    Returns the value of the requireAir record component.
    boolean
    Returns the value of the restorePrevious record component.
    final String
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • BLOCK

      public static final String BLOCK
      JSON field key for the temporary block to place.
      See Also:
    • LIFETIME

      public static final String LIFETIME
      JSON field key for the stable lifetime duration in ticks.
      See Also:
    • DECAY_DURATION

      public static final String DECAY_DURATION
      JSON field key for the visual crack decay duration in ticks.
      See Also:
    • REQUIRE_AIR

      public static final String REQUIRE_AIR
      JSON field key for restricting placement to replaceable blocks.
      See Also:
    • RESTORE_PREVIOUS

      public static final String RESTORE_PREVIOUS
      JSON field key for toggling restoration of the prior block state versus air.
      See Also:
    • EVALUATOR

      public static final String EVALUATOR
      JSON field key for the topological threshold/probability evaluator.
      See Also:
    • KEY

      public static final String KEY
      Registry path identifier for this spell field block effect.
      See Also:
    • KEY_PROVIDER

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

      public static final com.mojang.serialization.MapCodec<PlaceTemporaryBlockEffect> CODEC
      MapCodec for serializing and deserializing PlaceTemporaryBlockEffect definitions.
  • Constructor Details

    • PlaceTemporaryBlockEffect

      public PlaceTemporaryBlockEffect(net.minecraft.world.level.block.Block block, net.minecraft.world.item.enchantment.LevelBasedValue lifetime, net.minecraft.world.item.enchantment.LevelBasedValue decayDuration, boolean requireAir, boolean restorePrevious)
      Constructs a PlaceTemporaryBlockEffect using the default TopologyEvaluator.PROBABILISTIC evaluator.
      Parameters:
      block - The temporary block to place.
      lifetime - The stable duration in ticks before decay begins.
      decayDuration - The crack animation duration in ticks before restoration.
      requireAir - Whether placement requires a replaceable existing block state.
      restorePrevious - Whether to restore the previous block state rather than air upon expiration.
    • PlaceTemporaryBlockEffect

      public PlaceTemporaryBlockEffect(net.minecraft.world.level.block.Block block, net.minecraft.world.item.enchantment.LevelBasedValue lifetime, net.minecraft.world.item.enchantment.LevelBasedValue decayDuration, boolean requireAir, boolean restorePrevious, TopologyEvaluator evaluator)
      Creates an instance of a PlaceTemporaryBlockEffect record class.
      Parameters:
      block - the value for the block record component
      lifetime - the value for the lifetime record component
      decayDuration - the value for the decayDuration record component
      requireAir - the value for the requireAir record component
      restorePrevious - the value for the restorePrevious record component
      evaluator - the value for the evaluator record component
  • Method Details

    • getPriority

      public float getPriority(int enchantmentLevel)
      Returns the execution priority of this block effect based on the evaluator's threshold.
      Specified by:
      getPriority in interface SpellFieldBlockEffect
      Parameters:
      enchantmentLevel - The active level of the enchantment.
      Returns:
      The priority scalar.
    • apply

      public void apply(net.minecraft.server.level.ServerLevel level, int enchantmentLevel, net.minecraft.world.item.enchantment.EnchantedItemInUse context, net.minecraft.world.entity.Entity spatialReference, net.minecraft.world.phys.Vec3 epicenter, net.minecraft.core.BlockPos pos, float scalar, Set<net.minecraft.core.BlockPos> modifiedBlocks)
      Applies the temporary block placement at the target coordinate and registers restoration with TransientBlockTracker.

      Guards against modifying unloaded or non-ticking chunks via Level.shouldTickBlocksAt(BlockPos). If the target coordinate is already tracked by TransientBlockTracker, the original pre-spell BlockState and BlockEntity NBT are retained so that re-application on chunk reload does not overwrite the restoration state with the temporary block itself.

      Specified by:
      apply in interface SpellFieldBlockEffect
      Parameters:
      level - The executing server level.
      enchantmentLevel - The level of the spell field enchantment.
      context - The item usage context triggering the spell field.
      spatialReference - The anchor entity or focal point of the spell field.
      epicenter - The exact spatial origin vector of the spell field.
      pos - The target block coordinate.
      scalar - The active topological multiplier for the target.
      modifiedBlocks - A mutable set tracking all block coordinates modified during this execution cycle.
    • codec

      public com.mojang.serialization.MapCodec<? extends SpellFieldBlockEffect> codec()
      Description copied from interface: SpellFieldEffect
      Retrieves the MapCodec responsible for serializing and deserializing this effect.
      Specified by:
      codec in interface SpellFieldEffect
      Returns:
      The registered MapCodec 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 '=='.
      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.
    • block

      public net.minecraft.world.level.block.Block block()
      Returns the value of the block record component.
      Returns:
      the value of the block record component
    • lifetime

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

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

      public boolean requireAir()
      Returns the value of the requireAir record component.
      Returns:
      the value of the requireAir record component
    • restorePrevious

      public boolean restorePrevious()
      Returns the value of the restorePrevious record component.
      Returns:
      the value of the restorePrevious record component
    • evaluator

      public TopologyEvaluator evaluator()
      Returns the value of the evaluator record component.
      Returns:
      the value of the evaluator record component