Search in sources :

Example 1 with ScheduleUpdateTransaction

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

the class TransactionSink method logScheduledUpdate.

@SuppressWarnings("ConstantConditions")
default void logScheduledUpdate(final ServerLevel serverWorld, final TickNextTickData<?> data) {
    final WeakReference<ServerLevel> worldRef = new WeakReference<>(serverWorld);
    final Supplier<ServerLevel> worldSupplier = () -> Objects.requireNonNull(worldRef.get(), "ServerWorld dereferenced");
    @Nullable final BlockEntity tileEntity = serverWorld.getBlockEntity(data.pos);
    final BlockState existing = serverWorld.getBlockState(data.pos);
    final SpongeBlockSnapshot original = TrackingUtil.createPooledSnapshot(existing, data.pos, BlockChangeFlags.NONE, Constants.World.DEFAULT_BLOCK_CHANGE_LIMIT, tileEntity, worldSupplier, Optional::empty, Optional::empty);
    original.blockChange = BlockChange.MODIFY;
    final ScheduleUpdateTransaction transaction = new ScheduleUpdateTransaction(original, data);
    this.logTransaction(transaction);
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) SpongeBlockSnapshot(org.spongepowered.common.block.SpongeBlockSnapshot) BlockState(net.minecraft.world.level.block.state.BlockState) Optional(java.util.Optional) ScheduleUpdateTransaction(org.spongepowered.common.event.tracking.context.transaction.block.ScheduleUpdateTransaction) WeakReference(java.lang.ref.WeakReference) 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 BlockState (net.minecraft.world.level.block.state.BlockState)1 Nullable (org.checkerframework.checker.nullness.qual.Nullable)1 SpongeBlockSnapshot (org.spongepowered.common.block.SpongeBlockSnapshot)1 RemoveBlockEntity (org.spongepowered.common.event.tracking.context.transaction.block.RemoveBlockEntity)1 ReplaceBlockEntity (org.spongepowered.common.event.tracking.context.transaction.block.ReplaceBlockEntity)1 ScheduleUpdateTransaction (org.spongepowered.common.event.tracking.context.transaction.block.ScheduleUpdateTransaction)1