use of org.spongepowered.common.block.SpongeBlockSnapshot in project SpongeCommon by SpongePowered.
the class AddTileEntity method captureState.
@Override
protected void captureState() {
super.captureState();
@Nullable final BlockEntity existingTile = this.chunkSupplier.get().getBlockEntity(this.affectedPosition, LevelChunk.EntityCreationType.CHECK);
final SpongeBlockSnapshot added = TrackingUtil.createPooledSnapshot(this.originalState, this.affectedPosition, BlockChangeFlags.NONE, Constants.World.DEFAULT_BLOCK_CHANGE_LIMIT, this.added, this.worldSupplier, Optional::empty, Optional::empty);
final SpongeBlockSnapshot existing = TrackingUtil.createPooledSnapshot(this.originalState, this.affectedPosition, BlockChangeFlags.NONE, Constants.World.DEFAULT_BLOCK_CHANGE_LIMIT, existingTile, this.worldSupplier, Optional::empty, Optional::empty);
existing.blockChange = BlockChange.MODIFY;
this.oldSnapshot = existing;
this.addedSnapshot = added;
}
use of org.spongepowered.common.block.SpongeBlockSnapshot in project SpongeCommon by SpongePowered.
the class ReplaceBlockEntity method captureState.
@Override
protected void captureState() {
super.captureState();
final BlockState currentState = this.worldSupplier.get().getBlockState(this.affectedPosition);
final SpongeBlockSnapshot snapshot = TrackingUtil.createPooledSnapshot(currentState, this.affectedPosition, BlockChangeFlags.NONE, Constants.World.DEFAULT_BLOCK_CHANGE_LIMIT, this.removed, this.worldSupplier, Optional::empty, Optional::empty);
snapshot.blockChange = BlockChange.MODIFY;
this.removedSnapshot = snapshot;
}
use of org.spongepowered.common.block.SpongeBlockSnapshot in project SpongeCommon by SpongePowered.
the class LocationBasedTickPhaseState method postBlockTransactionApplication.
@Override
public void postBlockTransactionApplication(final T context, final BlockChange blockChange, final BlockTransactionReceipt receipt) {
// If we do not have a notifier at this point then there is no need to attempt to retrieve one from the chunk
context.applyNotifierIfAvailable(user -> {
final SpongeBlockSnapshot original = (SpongeBlockSnapshot) receipt.originalBlock();
final Block block = (Block) original.state().type();
final BlockPos changedBlockPos = original.getBlockPos();
original.getServerWorld().ifPresent(worldServer -> {
final LevelChunkBridge changedMixinChunk = (LevelChunkBridge) worldServer.getChunkAt(changedBlockPos);
changedMixinChunk.bridge$addTrackedBlockPosition(block, changedBlockPos, user, PlayerTracker.Type.NOTIFIER);
// to have new owners, which we can gather from the context.
if (blockChange == BlockChange.PLACE) {
context.applyOwnerIfAvailable(owner -> {
// We can do this when we check for notifiers because owners will always have a notifier set
// if not, well, file a bug report and find out the corner case that owners are set but not notifiers with block changes.
changedMixinChunk.bridge$addTrackedBlockPosition(block, changedBlockPos, owner, PlayerTracker.Type.CREATOR);
});
}
});
});
}
use of org.spongepowered.common.block.SpongeBlockSnapshot in project SpongeCommon by SpongePowered.
the class BlockEventTickPhaseState method postBlockTransactionApplication.
@Override
public void postBlockTransactionApplication(final BlockEventTickContext context, final BlockChange blockChange, final BlockTransactionReceipt receipt) {
final Block block = (Block) receipt.originalBlock().state().type();
final SpongeBlockSnapshot original = (SpongeBlockSnapshot) receipt.originalBlock();
final BlockPos changedBlockPos = original.getBlockPos();
original.getServerWorld().ifPresent(worldServer -> {
final LevelChunkBridge changedMixinChunk = (LevelChunkBridge) worldServer.getChunkAt(changedBlockPos);
changedMixinChunk.bridge$getBlockCreatorUUID(changedBlockPos).ifPresent(owner -> changedMixinChunk.bridge$addTrackedBlockPosition(block, changedBlockPos, owner, PlayerTracker.Type.CREATOR));
changedMixinChunk.bridge$getBlockNotifierUUID(changedBlockPos).ifPresent(user -> changedMixinChunk.bridge$addTrackedBlockPosition(block, changedBlockPos, user, PlayerTracker.Type.NOTIFIER));
});
}
use of org.spongepowered.common.block.SpongeBlockSnapshot in project SpongeCommon by SpongePowered.
the class TransactionSink method logBlockEvent.
@SuppressWarnings("ConstantConditions")
default void logBlockEvent(final BlockState state, final TrackedWorldBridge serverWorld, final BlockPos pos, final TrackableBlockEventDataBridge blockEvent) {
final WeakReference<ServerLevel> worldRef = new WeakReference<>((ServerLevel) serverWorld);
final Supplier<ServerLevel> worldSupplier = () -> Objects.requireNonNull(worldRef.get(), "ServerWorld dereferenced");
@Nullable final BlockEntity tileEntity = ((ServerLevel) serverWorld).getBlockEntity(pos);
final SpongeBlockSnapshot original = TrackingUtil.createPooledSnapshot(state, pos, BlockChangeFlags.NONE, Constants.World.DEFAULT_BLOCK_CHANGE_LIMIT, tileEntity, worldSupplier, Optional::empty, Optional::empty);
original.blockChange = BlockChange.MODIFY;
final AddBlockEventTransaction transaction = new AddBlockEventTransaction(original, blockEvent);
this.logTransaction(transaction);
}
Aggregations