Search in sources :

Example 1 with PrepareBlockDropsTransaction

use of org.spongepowered.common.event.tracking.context.transaction.block.PrepareBlockDropsTransaction in project SpongeCommon by SpongePowered.

the class TransactionSink method logBlockDrops.

@SuppressWarnings("ConstantConditions")
default EffectTransactor logBlockDrops(final Level serverWorld, final BlockPos pos, final BlockState state, @Nullable final BlockEntity tileEntity) {
    final WeakReference<ServerLevel> worldRef = new WeakReference<>((ServerLevel) serverWorld);
    final Supplier<ServerLevel> worldSupplier = () -> Objects.requireNonNull(worldRef.get(), "ServerWorld dereferenced");
    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 PrepareBlockDropsTransaction transaction = new PrepareBlockDropsTransaction(pos, state, original);
    this.logTransaction(transaction);
    return this.pushEffect(new ResultingTransactionBySideEffect(PrepareBlockDrops.getInstance()));
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) SpongeBlockSnapshot(org.spongepowered.common.block.SpongeBlockSnapshot) Optional(java.util.Optional) PrepareBlockDropsTransaction(org.spongepowered.common.event.tracking.context.transaction.block.PrepareBlockDropsTransaction) WeakReference(java.lang.ref.WeakReference)

Aggregations

WeakReference (java.lang.ref.WeakReference)1 Optional (java.util.Optional)1 ServerLevel (net.minecraft.server.level.ServerLevel)1 SpongeBlockSnapshot (org.spongepowered.common.block.SpongeBlockSnapshot)1 PrepareBlockDropsTransaction (org.spongepowered.common.event.tracking.context.transaction.block.PrepareBlockDropsTransaction)1