Search in sources :

Example 6 with EntityTickContext

use of org.spongepowered.common.event.tracking.phase.tick.EntityTickContext in project SpongeCommon by SpongePowered.

the class TrackingUtil method tickRidingEntity.

public static void tickRidingEntity(final net.minecraft.world.entity.Entity entity) {
    checkArgument(entity instanceof Entity, "Entity %s is not an instance of SpongeAPI's Entity!", entity);
    checkNotNull(entity, "Cannot capture on a null ticking entity!");
    if (!((TrackableBridge) entity).bridge$shouldTick()) {
        return;
    }
    final EntityTickContext tickContext = TickPhase.Tick.ENTITY.createPhaseContext(PhaseTracker.SERVER).source(entity);
    try (final EntityTickContext context = tickContext;
        final Timing entityTiming = ((TimingBridge) entity.getType()).bridge$timings()) {
        entityTiming.startTiming();
        if (entity instanceof CreatorTrackedBridge) {
            ((CreatorTrackedBridge) entity).tracker$getNotifierUUID().ifPresent(context::notifier);
            ((CreatorTrackedBridge) entity).tracker$getCreatorUUID().ifPresent(context::creator);
        }
        context.buildAndSwitch();
        entity.rideTick();
        if (ShouldFire.MOVE_ENTITY_EVENT) {
            SpongeCommonEventFactory.callNaturalMoveEntityEvent(entity);
        }
        if (ShouldFire.ROTATE_ENTITY_EVENT) {
            SpongeCommonEventFactory.callNaturalRotateEntityEvent(entity);
        }
    } catch (final Exception e) {
        PhasePrinter.printExceptionFromPhase(PhaseTracker.getInstance().stack, e, tickContext);
    }
}
Also used : TickableBlockEntity(net.minecraft.world.level.block.entity.TickableBlockEntity) BlockEntity(org.spongepowered.api.block.entity.BlockEntity) Entity(org.spongepowered.api.entity.Entity) EntityTickContext(org.spongepowered.common.event.tracking.phase.tick.EntityTickContext) TileEntityTickContext(org.spongepowered.common.event.tracking.phase.tick.TileEntityTickContext) CreatorTrackedBridge(org.spongepowered.common.bridge.CreatorTrackedBridge) Timing(co.aikar.timings.Timing) TimingBridge(org.spongepowered.common.bridge.TimingBridge)

Aggregations

EntityTickContext (org.spongepowered.common.event.tracking.phase.tick.EntityTickContext)6 Timing (co.aikar.timings.Timing)4 Entity (org.spongepowered.api.entity.Entity)4 TileEntityTickContext (org.spongepowered.common.event.tracking.phase.tick.TileEntityTickContext)4 TickableBlockEntity (net.minecraft.world.level.block.entity.TickableBlockEntity)2 BlockEntity (org.spongepowered.api.block.entity.BlockEntity)2 TileEntity (org.spongepowered.api.block.tileentity.TileEntity)2 StackFrame (org.spongepowered.api.event.CauseStackManager.StackFrame)2 CreatorTrackedBridge (org.spongepowered.common.bridge.CreatorTrackedBridge)2 TimingBridge (org.spongepowered.common.bridge.TimingBridge)2 IMixinTileEntity (org.spongepowered.common.interfaces.block.tile.IMixinTileEntity)2 IMixinEntity (org.spongepowered.common.interfaces.entity.IMixinEntity)2 EntityFallingBlock (net.minecraft.entity.item.EntityFallingBlock)1 InventoryMenu (net.minecraft.world.inventory.InventoryMenu)1 Player (org.spongepowered.api.entity.living.player.Player)1 User (org.spongepowered.api.entity.living.player.User)1 PlayerInventoryBridge (org.spongepowered.common.bridge.world.entity.player.PlayerInventoryBridge)1 UnwindingPhaseContext (org.spongepowered.common.event.tracking.UnwindingPhaseContext)1 ContainerSlotTransaction (org.spongepowered.common.event.tracking.context.transaction.inventory.ContainerSlotTransaction)1 CommandPhaseContext (org.spongepowered.common.event.tracking.phase.general.CommandPhaseContext)1