Search in sources :

Example 1 with PlayerTickContext

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

the class MixinNetHandlerPlayServer method onPlayerTick.

@Redirect(method = "update", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/EntityPlayerMP;onUpdateEntity()V"))
private void onPlayerTick(EntityPlayerMP player) {
    if (player.world.isRemote) {
        player.onUpdateEntity();
        return;
    }
    try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame();
        PlayerTickContext context = TickPhase.Tick.PLAYER.createPhaseContext().source(player).buildAndSwitch()) {
        Sponge.getCauseStackManager().pushCause(player);
        player.onUpdateEntity();
    }
}
Also used : PlayerTickContext(org.spongepowered.common.event.tracking.phase.tick.PlayerTickContext) CauseStackManager(org.spongepowered.api.event.CauseStackManager) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 2 with PlayerTickContext

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

the class ServerGamePacketListenerImplMixin_Tracker method tracker$wrapPlayerTickWithPhase.

@Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerPlayer;doTick()V"))
private void tracker$wrapPlayerTickWithPhase(final ServerPlayer player) {
    if (((PlatformEntityBridge) player).bridge$isFakePlayer() || ((LevelBridge) player.level).bridge$isFake()) {
        player.doTick();
        return;
    }
    try (final PlayerTickContext context = TickPhase.Tick.PLAYER.createPhaseContext(PhaseTracker.SERVER).source(player)) {
        context.buildAndSwitch();
        player.doTick();
    }
}
Also used : PlayerTickContext(org.spongepowered.common.event.tracking.phase.tick.PlayerTickContext) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Aggregations

Redirect (org.spongepowered.asm.mixin.injection.Redirect)2 PlayerTickContext (org.spongepowered.common.event.tracking.phase.tick.PlayerTickContext)2 CauseStackManager (org.spongepowered.api.event.CauseStackManager)1