Class TransientBlockTracker
ServerLevel.
To survive chunk unloads and reloads without losing restoration state or desynchronizing from frozen
SpellFieldAnchorEntity instances in unloaded chunks, tracked blocks are partitioned into
chunk-keyed buckets (ChunkPos.pack(BlockPos)) and evaluated using relative tick counters
(remainingStableTicks and remainingDecayTicks).
Progression and block restoration are strictly gated behind ServerLevel.shouldTickBlocksAt(long),
ensuring that blocks in unloaded or border chunks pause their timers until the chunk re-enters an
active block-ticking state.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final com.mojang.serialization.Codec<TransientBlockTracker> Codec responsible for serializing and deserializing all chunk-partitioned transient block records.static final net.minecraft.world.level.saveddata.SavedDataType<TransientBlockTracker> Persistent data type definition registered with the level's data storage. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddBlock(net.minecraft.server.level.ServerLevel level, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState originalState, @Nullable net.minecraft.nbt.CompoundTag blockEntityData, int stableTicks, int decayTicks) Registers a block position for temporary modification using relative tick durations.voidaddBlock(net.minecraft.server.level.ServerLevel level, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState originalState, @Nullable net.minecraft.nbt.CompoundTag blockEntityData, long decayStartTick, long expiryTick) Registers a block position for temporary modification using absolute game-time timestamps.static TransientBlockTrackerget(net.minecraft.server.level.ServerLevel level) Retrieves the activeTransientBlockTrackerinstance for the specified server level, instantiating and registering a new tracker if one does not already exist.@Nullable net.minecraft.world.level.block.state.BlockStategetOriginalState(net.minecraft.core.BlockPos pos) Retrieves the original pre-modificationBlockStaterecorded for the specified coordinate.booleanisTracked(net.minecraft.core.BlockPos pos) Checks whether the specified block coordinate is currently undergoing a temporary modification managed by this tracker.voidtick(net.minecraft.server.level.ServerLevel level) Executes the per-tick evaluation loop for all tracked transient blocks in the given level.Methods inherited from class net.minecraft.world.level.saveddata.SavedData
isDirty, setDirty, setDirty
-
Field Details
-
CODEC
Codec responsible for serializing and deserializing all chunk-partitioned transient block records. -
TYPE
Persistent data type definition registered with the level's data storage.
-
-
Constructor Details
-
TransientBlockTracker
public TransientBlockTracker()
-
-
Method Details
-
get
Retrieves the activeTransientBlockTrackerinstance for the specified server level, instantiating and registering a new tracker if one does not already exist.- Parameters:
level- The target server level.- Returns:
- The bound
TransientBlockTrackerinstance.
-
isTracked
public boolean isTracked(net.minecraft.core.BlockPos pos) Checks whether the specified block coordinate is currently undergoing a temporary modification managed by this tracker.- Parameters:
pos- The block coordinate to query.- Returns:
trueif the position is actively tracked and awaiting restoration,falseotherwise.
-
getOriginalState
public @Nullable net.minecraft.world.level.block.state.BlockState getOriginalState(net.minecraft.core.BlockPos pos) Retrieves the original pre-modificationBlockStaterecorded for the specified coordinate.Used by temporary block effects during repeated spell field ticks or post-chunk-reload ticks to prevent overwriting the true original block state with the temporary block's own state.
- Parameters:
pos- The block coordinate to query.- Returns:
- The original
BlockStatescheduled for restoration, ornullif the position is not tracked.
-
addBlock
public void addBlock(net.minecraft.server.level.ServerLevel level, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState originalState, @Nullable net.minecraft.nbt.CompoundTag blockEntityData, long decayStartTick, long expiryTick) Registers a block position for temporary modification using absolute game-time timestamps.Converts the provided timestamps into relative tick durations and delegates to
addBlock(ServerLevel, BlockPos, BlockState, CompoundTag, int, int).- Parameters:
level- The server level containing the block.pos- The coordinate position of the modified block.originalState- The original block state to restore upon expiration.blockEntityData- The serialized NBT metadata of the original block entity, ornullif none existed.decayStartTick- The absolute game time tick when the block-breaking decay animation should begin.expiryTick- The absolute game time tick when the original block state should be restored.
-
addBlock
public void addBlock(net.minecraft.server.level.ServerLevel level, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState originalState, @Nullable net.minecraft.nbt.CompoundTag blockEntityData, int stableTicks, int decayTicks) Registers a block position for temporary modification using relative tick durations.If the position is already tracked, its original
BlockStateandBlockEntityNBT are preserved while its remaining lifetime and decay timers are refreshed to the maximum of the existing and incoming durations.- Parameters:
level- The server level containing the block.pos- The coordinate position of the modified block.originalState- The original block state to restore upon expiration.blockEntityData- The serialized NBT metadata of the original block entity, ornullif none existed.stableTicks- The number of active chunk ticks before decay animation begins.decayTicks- The number of active chunk ticks over which the decay animation plays before restoration.
-
tick
public void tick(net.minecraft.server.level.ServerLevel level) Executes the per-tick evaluation loop for all tracked transient blocks in the given level.Chunks that are currently unloaded or outside the active block-ticking simulation distance (
ServerLevel.shouldTickBlocksAt(long)returnsfalse) are skipped without decrementing their timers or discarding their restoration entries.- Parameters:
level- The executing server level.
-