Record Class PlaceTemporaryBlockEffect
java.lang.Object
java.lang.Record
johnsmith.enchantmentcore.api.enchantment.spellfield.effect.block.PlaceTemporaryBlockEffect
- Record Components:
block- The temporaryBlockto place in the world.lifetime- TheLevelBasedValueduration (in ticks) the temporary block remains stable before decaying.decayDuration- TheLevelBasedValueduration (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 (iffalse, restores air).evaluator- TheTopologyEvaluatorgoverning 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
FieldsModifier and TypeFieldDescriptionstatic final StringJSON field key for the temporary block to place.static final com.mojang.serialization.MapCodec<PlaceTemporaryBlockEffect> MapCodec for serializing and deserializingPlaceTemporaryBlockEffectdefinitions.static final StringJSON field key for the visual crack decay duration in ticks.static final StringJSON field key for the topological threshold/probability evaluator.static final StringRegistry path identifier for this spell field block effect.static final LevelBasedKeyProviderSupplies the JSON property keys that holdLevelBasedValuedefinitions for data transformation.static final StringJSON field key for the stable lifetime duration in ticks.static final StringJSON field key for restricting placement to replaceable blocks.static final StringJSON field key for toggling restoration of the prior block state versus air. -
Constructor Summary
ConstructorsConstructorDescriptionPlaceTemporaryBlockEffect(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 aPlaceTemporaryBlockEffectusing the defaultTopologyEvaluator.PROBABILISTICevaluator.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 aPlaceTemporaryBlockEffectrecord class. -
Method Summary
Modifier and TypeMethodDescriptionvoidapply(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 withTransientBlockTracker.net.minecraft.world.level.block.Blockblock()Returns the value of theblockrecord component.com.mojang.serialization.MapCodec<? extends SpellFieldBlockEffect> codec()Retrieves theMapCodecresponsible for serializing and deserializing this effect.net.minecraft.world.item.enchantment.LevelBasedValueReturns the value of thedecayDurationrecord component.final booleanIndicates whether some other object is "equal to" this one.Returns the value of theevaluatorrecord component.floatgetPriority(int enchantmentLevel) Returns the execution priority of this block effect based on the evaluator's threshold.final inthashCode()Returns a hash code value for this object.net.minecraft.world.item.enchantment.LevelBasedValuelifetime()Returns the value of thelifetimerecord component.booleanReturns the value of therequireAirrecord component.booleanReturns the value of therestorePreviousrecord component.final StringtoString()Returns a string representation of this record class.
-
Field Details
-
BLOCK
-
LIFETIME
JSON field key for the stable lifetime duration in ticks.- See Also:
-
DECAY_DURATION
JSON field key for the visual crack decay duration in ticks.- See Also:
-
REQUIRE_AIR
JSON field key for restricting placement to replaceable blocks.- See Also:
-
RESTORE_PREVIOUS
JSON field key for toggling restoration of the prior block state versus air.- See Also:
-
EVALUATOR
JSON field key for the topological threshold/probability evaluator.- See Also:
-
KEY
Registry path identifier for this spell field block effect.- See Also:
-
KEY_PROVIDER
Supplies the JSON property keys that holdLevelBasedValuedefinitions for data transformation. -
CODEC
MapCodec for serializing and deserializingPlaceTemporaryBlockEffectdefinitions.
-
-
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 aPlaceTemporaryBlockEffectusing the defaultTopologyEvaluator.PROBABILISTICevaluator.- 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 aPlaceTemporaryBlockEffectrecord class.- Parameters:
block- the value for theblockrecord componentlifetime- the value for thelifetimerecord componentdecayDuration- the value for thedecayDurationrecord componentrequireAir- the value for therequireAirrecord componentrestorePrevious- the value for therestorePreviousrecord componentevaluator- the value for theevaluatorrecord 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:
getPriorityin interfaceSpellFieldBlockEffect- 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 withTransientBlockTracker.Guards against modifying unloaded or non-ticking chunks via
Level.shouldTickBlocksAt(BlockPos). If the target coordinate is already tracked byTransientBlockTracker, the original pre-spellBlockStateandBlockEntityNBT are retained so that re-application on chunk reload does not overwrite the restoration state with the temporary block itself.- Specified by:
applyin interfaceSpellFieldBlockEffect- 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
Description copied from interface:SpellFieldEffectRetrieves theMapCodecresponsible for serializing and deserializing this effect.- Specified by:
codecin interfaceSpellFieldEffect- Returns:
- The registered
MapCodecinstance.
-
toString
-
hashCode
-
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 thecomparemethod from their corresponding wrapper classes. -
block
-
lifetime
-
decayDuration
public net.minecraft.world.item.enchantment.LevelBasedValue decayDuration()Returns the value of thedecayDurationrecord component.- Returns:
- the value of the
decayDurationrecord component
-
requireAir
public boolean requireAir()Returns the value of therequireAirrecord component.- Returns:
- the value of the
requireAirrecord component
-
restorePrevious
public boolean restorePrevious()Returns the value of therestorePreviousrecord component.- Returns:
- the value of the
restorePreviousrecord component
-
evaluator
-