类 BlockSnapshot
java.lang.Object
net.neoforged.neoforge.common.util.BlockSnapshot
Represents a captured snapshot of a block, including the level, position, state, BE data, and setBlock flags.
Used to record the prior state and unwind changes if the change was denied, such as during BlockEvent.BreakEvent
.
-
字段概要
字段修饰符和类型字段说明private static final boolean
private final ResourceKey
<Level> private final int
private WeakReference
<LevelAccessor> private static final org.slf4j.Logger
private final @Nullable CompoundTag
private final BlockPos
private final BlockState
private @Nullable String
-
构造器概要
构造器限定符构造器说明private
BlockSnapshot
(ResourceKey<Level> dim, LevelAccessor level, BlockPos pos, BlockState state, @Nullable CompoundTag nbt, int flags) -
方法概要
修饰符和类型方法说明static BlockSnapshot
create
(ResourceKey<Level> dim, LevelAccessor level, BlockPos pos) Creates a new snapshot with the default block flags (and Block#UPDATE_CLIENTS
.static BlockSnapshot
create
(ResourceKey<Level> dim, LevelAccessor level, BlockPos pos, int flag) Creates a new snapshot of the data at the given position.boolean
private static @Nullable CompoundTag
getBlockEntityTag
(LevelAccessor level, BlockPos pos) Checks for a block entity at a given position, and saves it to NBT with full metadata if it exists.返回 the current (live) block state at the recorded position, not the snapshot's recorded state。返回 the recorded dimension key。int
getFlags()
@Nullable LevelAccessor
getLevel()
返回 the stored level, attempting to resolve it from the current server if it has gone out of scope。getPos()
返回 the recorded position。getState()
返回 the snapshot's recorded block state。@Nullable CompoundTag
getTag()
返回 the recorded block entity NBT data, if one was present。int
hashCode()
@Nullable BlockEntity
recreateBlockEntity
(HolderLookup.Provider provider) Recreates a block entity from the stored data (pos/state/NBT) of this block snapshot.boolean
restore()
CallsrestoreToLocation(net.minecraft.world.level.LevelAccessor, net.minecraft.core.BlockPos, int)
with the stored level, position, and block flags.boolean
restore
(int flags) CallsrestoreToLocation(net.minecraft.world.level.LevelAccessor, net.minecraft.core.BlockPos, int)
with the stored level, position, but custom block flags.boolean
restoreBlockEntity
(LevelAccessor level, BlockPos pos) Loads the storedBlockEntity
data if one exists at the given position.boolean
restoreToLocation
(LevelAccessor level, BlockPos pos, int flags) Restores this block snapshot to the target level and position with the specified flags.toString()
-
字段详细资料
-
DEBUG
private static final boolean DEBUG -
LOGGER
private static final org.slf4j.Logger LOGGER -
dim
-
pos
-
flags
private final int flags -
state
-
nbt
-
level
-
toString
-
-
构造器详细资料
-
BlockSnapshot
private BlockSnapshot(ResourceKey<Level> dim, LevelAccessor level, BlockPos pos, BlockState state, @Nullable @Nullable CompoundTag nbt, int flags)
-
-
方法详细资料
-
create
public static BlockSnapshot create(ResourceKey<Level> dim, LevelAccessor level, BlockPos pos, int flag) Creates a new snapshot of the data at the given position.- 参数:
dim
- The dimension of the changed blocklevel
- The level of the changed blockpos
- The position of the changed blockflag
- TheLevel.setBlock(BlockPos, BlockState, int)
flags that the block was changed with.- 返回:
- A captured block snapshot, containing the state and BE data from the given position.
-
create
Creates a new snapshot with the default block flags (and Block#UPDATE_CLIENTS
.- 另请参阅:
-
getDimension
返回 the recorded dimension key。- 返回:
- the recorded dimension key
-
getPos
返回 the recorded position。- 返回:
- the recorded position
-
getFlags
public int getFlags()- 返回:
- the recorded
Level.setBlock(BlockPos, BlockState, int)
flags
-
getTag
返回 the recorded block entity NBT data, if one was present。- 返回:
- the recorded block entity NBT data, if one was present
-
getState
返回 the snapshot's recorded block state。- 返回:
- the snapshot's recorded block state
-
getLevel
返回 the stored level, attempting to resolve it from the current server if it has gone out of scope。- 返回:
- the stored level, attempting to resolve it from the current server if it has gone out of scope
-
getCurrentState
返回 the current (live) block state at the recorded position, not the snapshot's recorded state。- 返回:
- the current (live) block state at the recorded position, not the snapshot's recorded state
-
recreateBlockEntity
Recreates a block entity from the stored data (pos/state/NBT) of this block snapshot.- 返回:
- The newly created block entity, or null if no NBT data was present, or it was invalid.
-
restoreToLocation
Restores this block snapshot to the target level and position with the specified flags.- 返回:
- true if the block was successfully updated, false otherwise.
-
restore
public boolean restore(int flags) CallsrestoreToLocation(net.minecraft.world.level.LevelAccessor, net.minecraft.core.BlockPos, int)
with the stored level, position, but custom block flags. -
restore
public boolean restore()CallsrestoreToLocation(net.minecraft.world.level.LevelAccessor, net.minecraft.core.BlockPos, int)
with the stored level, position, and block flags. -
restoreBlockEntity
Loads the storedBlockEntity
data if one exists at the given position.- 返回:
- true if any data was loaded
-
equals
-
hashCode
public int hashCode() -
toString
-
getBlockEntityTag
Checks for a block entity at a given position, and saves it to NBT with full metadata if it exists.
-