use of org.spongepowered.common.bridge.world.level.block.entity.BlockEntityBridge in project SpongeCommon by SpongePowered.
the class TrackingUtil method tickTileEntity.
@SuppressWarnings({ "unused", "try" })
public static void tickTileEntity(final TrackedWorldBridge mixinWorldServer, final TickableBlockEntity tile) {
checkArgument(tile instanceof BlockEntity, "ITickable %s is not a TileEntity!", tile);
checkNotNull(tile, "Cannot capture on a null ticking tile entity!");
final net.minecraft.world.level.block.entity.BlockEntity tileEntity = (net.minecraft.world.level.block.entity.BlockEntity) tile;
final BlockEntityBridge mixinTileEntity = (BlockEntityBridge) tile;
final BlockPos pos = tileEntity.getBlockPos();
final LevelChunkBridge chunk = ((ActiveChunkReferantBridge) tile).bridge$getActiveChunk();
if (!((TrackableBridge) tileEntity).bridge$shouldTick()) {
return;
}
if (chunk == null) {
((ActiveChunkReferantBridge) tile).bridge$setActiveChunk((TrackedLevelChunkBridge) tileEntity.getLevel().getChunkAt(tileEntity.getBlockPos()));
}
final TileEntityTickContext context = TickPhase.Tick.TILE_ENTITY.createPhaseContext(PhaseTracker.SERVER).source(mixinTileEntity);
try (final PhaseContext<?> phaseContext = context) {
if (tile instanceof CreatorTrackedBridge) {
// Add notifier and owner so we don't have to perform lookups during the phases and other processing
((CreatorTrackedBridge) tile).tracker$getNotifierUUID().ifPresent(phaseContext::notifier);
// Allow the tile entity to validate the owner of itself. As long as the tile entity
// chunk is already loaded and activated, and the tile entity has already loaded
// the owner of itself.
((CreatorTrackedBridge) tile).tracker$getCreatorUUID().ifPresent(phaseContext::creator);
}
// Finally, switch the context now that we have the owner and notifier
phaseContext.buildAndSwitch();
try (final Timing timing = ((TimingBridge) tileEntity.getType()).bridge$timings().startTiming()) {
tile.tick();
}
// otherwise the viewing players update this during their ticking
if (tileEntity instanceof ViewableInventoryBridge) {
final Set<ServerPlayer> players = ((ViewableInventoryBridge) tileEntity).viewableBridge$getViewers();
if (players.size() > 0) {
players.forEach(player -> player.containerMenu.broadcastChanges());
}
}
} catch (final Exception e) {
PhasePrinter.printExceptionFromPhase(PhaseTracker.getInstance().stack, e, context);
}
// We delay clearing active chunk if TE is invalidated during tick so we must remove it after
if (tileEntity.isRemoved()) {
((ActiveChunkReferantBridge) tileEntity).bridge$setActiveChunk(null);
}
}
use of org.spongepowered.common.bridge.world.level.block.entity.BlockEntityBridge in project SpongeCommon by SpongePowered.
the class TileOnLoadDuringAddToWorldEffect method processSideEffect.
@Override
public EffectResult processSideEffect(final BlockPipeline pipeline, final PipelineCursor oldState, final BlockState newState, final SpongeBlockChangeFlag flag, final int limit) {
@Nullable final BlockEntity tileEntity = oldState.tileEntity;
if (tileEntity == null) {
return EffectResult.NULL_RETURN;
}
((BlockEntityBridge) tileEntity).bridge$onLoad();
return EffectResult.NULL_PASS;
}
Aggregations