Search in sources :

Example 1 with AddBlockEventTransaction

use of org.spongepowered.common.event.tracking.context.transaction.block.AddBlockEventTransaction 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);
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) SpongeBlockSnapshot(org.spongepowered.common.block.SpongeBlockSnapshot) Optional(java.util.Optional) WeakReference(java.lang.ref.WeakReference) AddBlockEventTransaction(org.spongepowered.common.event.tracking.context.transaction.block.AddBlockEventTransaction) Nullable(org.checkerframework.checker.nullness.qual.Nullable) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) RemoveBlockEntity(org.spongepowered.common.event.tracking.context.transaction.block.RemoveBlockEntity) ReplaceBlockEntity(org.spongepowered.common.event.tracking.context.transaction.block.ReplaceBlockEntity)

Aggregations

WeakReference (java.lang.ref.WeakReference)1 Optional (java.util.Optional)1 ServerLevel (net.minecraft.server.level.ServerLevel)1 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)1 Nullable (org.checkerframework.checker.nullness.qual.Nullable)1 SpongeBlockSnapshot (org.spongepowered.common.block.SpongeBlockSnapshot)1 AddBlockEventTransaction (org.spongepowered.common.event.tracking.context.transaction.block.AddBlockEventTransaction)1 RemoveBlockEntity (org.spongepowered.common.event.tracking.context.transaction.block.RemoveBlockEntity)1 ReplaceBlockEntity (org.spongepowered.common.event.tracking.context.transaction.block.ReplaceBlockEntity)1