use of org.spongepowered.common.event.tracking.context.transaction.block.RemoveBlockEntity in project SpongeCommon by SpongePowered.
the class ServerLevelMixin_Tracker method shadow$removeBlockEntity.
/**
* Technically an overwrite, but because this is simply an override, we can
* effectively do as we need to, which is determine if we are performing
* block transactional recording, go ahead and record transactions.
* <p>In the event that we are performing transaction recording, the following
* must be true:
* <ul>
* <li>This world instance is managed and verified by Sponge</li>
* <li>This world must {@link LevelBridge#bridge$isFake()} return {@code false}</li>
* <li>The {@link PhaseTracker#SERVER}'s {@link PhaseTracker#getSidedThread()} must be {@code ==} {@link Thread#currentThread()}</li
* <li>The current {@link IPhaseState} must be allowing to record transactions with an applicable {@link org.spongepowered.common.event.tracking.context.transaction.TransactionalCaptureSupplier}</li>
* </ul>
* After which, we may be able to appropriately associate the {@link net.minecraft.world.level.block.entity.BlockEntity}
* being removed with either an existing {@link ChangeBlock},
* or generate a new {@link RemoveBlockEntity} transaction
* that would otherwise be able to associate with either the current {@link IPhaseState} or a parent {@link GameTransaction}
* if this call is the result of a {@link org.spongepowered.common.event.tracking.context.transaction.effect.ProcessingSideEffect}..
*
* @param pos The position of the tile entity to remove
* @author gabizou - July 31st, 2020 - Minecraft 1.14.3
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void shadow$removeBlockEntity(final BlockPos pos) {
final BlockPos immutable = pos.immutable();
final net.minecraft.world.level.block.entity.BlockEntity tileentity = this.shadow$getBlockEntity(immutable);
if (tileentity == null) {
return;
}
if (this.bridge$isFake() || PhaseTracker.SERVER.getSidedThread() != Thread.currentThread()) {
// If we're fake or not on the server thread, well, we could effectively call
// out whoever is trying to remove tile entities asynchronously....
super.shadow$removeBlockEntity(immutable);
return;
}
// Otherwise, let's go on and check if we're recording transactions,
// and if so, log the tile entity removal (may associate with an existing transaction,
// or create a new transaction.
final PhaseContext<@NonNull ?> current = PhaseTracker.SERVER.getPhaseContext();
if (current.getTransactor().logTileRemoval(tileentity, () -> (ServerLevel) (Object) this)) {
final TileEntityPipeline pipeline = TileEntityPipeline.kickOff((ServerLevel) (Object) this, immutable).addEffect(RemoveTileEntityFromWorldEffect.getInstance()).addEffect(RemoveTileEntityFromChunkEffect.getInstance()).build();
pipeline.processEffects(current, new PipelineCursor(tileentity.getBlockState(), 0, immutable, tileentity, (Entity) null, Constants.World.DEFAULT_BLOCK_CHANGE_LIMIT));
return;
}
super.shadow$removeBlockEntity(immutable);
}
Aggregations