Search in sources :

Example 6 with IPhaseState

use of org.spongepowered.common.event.tracking.IPhaseState in project SpongeCommon by SpongePowered.

the class MixinWorldServer method onFireBlockEvent.

// special handling for Pistons since they use their own event system
@Redirect(method = "sendQueuedBlockEvents", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/WorldServer;fireBlockEvent(Lnet/minecraft/block/BlockEventData;)Z"))
private boolean onFireBlockEvent(net.minecraft.world.WorldServer worldIn, BlockEventData event) {
    final PhaseTracker phaseTracker = PhaseTracker.getInstance();
    final IPhaseState phaseState = phaseTracker.getCurrentState();
    if (phaseState.ignoresBlockEvent()) {
        return fireBlockEvent(event);
    }
    return TrackingUtil.fireMinecraftBlockEvent(worldIn, event);
}
Also used : PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) IPhaseState(org.spongepowered.common.event.tracking.IPhaseState) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 7 with IPhaseState

use of org.spongepowered.common.event.tracking.IPhaseState in project SpongeCommon by SpongePowered.

the class MixinWorldServer method onCallEntityUpdate.

@Override
public void onCallEntityUpdate(net.minecraft.entity.Entity entity) {
    final PhaseTracker phaseTracker = PhaseTracker.getInstance();
    final IPhaseState state = phaseTracker.getCurrentState();
    if (state.alreadyCapturingEntityTicks()) {
        entity.onUpdate();
        return;
    }
    TrackingUtil.tickEntity(entity);
    updateRotation(entity);
}
Also used : PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) IPhaseState(org.spongepowered.common.event.tracking.IPhaseState)

Example 8 with IPhaseState

use of org.spongepowered.common.event.tracking.IPhaseState in project SpongeCommon by SpongePowered.

the class MixinEntityPlayerMP method onDeath.

/**
 * @author blood - May 12th, 2016
 * @author gabizou - June 3rd, 2016
 *
 * @reason SpongeForge requires an overwrite so we do it here instead. This handles player death events.
 */
@Override
@Overwrite
public void onDeath(DamageSource cause) {
    // Sponge start
    DestructEntityEvent.Death event = SpongeCommonEventFactory.callDestructEntityEventDeath((EntityPlayerMP) (Object) this, cause);
    // Double check that the PhaseTracker is already capturing the Death phase
    final PhaseTracker phaseTracker;
    final boolean tracksEntityDeaths;
    if (!this.world.isRemote) {
        phaseTracker = PhaseTracker.getInstance();
        final PhaseData peek = phaseTracker.getCurrentPhaseData();
        final IPhaseState state = peek.state;
        tracksEntityDeaths = state.tracksEntityDeaths();
    } else {
        phaseTracker = null;
        tracksEntityDeaths = false;
    }
    try (PhaseContext<?> context = !tracksEntityDeaths ? EntityPhase.State.DEATH.createPhaseContext().source(this).setDamageSource((org.spongepowered.api.event.cause.entity.damage.source.DamageSource) cause).buildAndSwitch() : null) {
        // Sponge end
        boolean flag = this.world.getGameRules().getBoolean("showDeathMessages");
        this.connection.sendPacket(new SPacketCombatEvent(this.getCombatTracker(), SPacketCombatEvent.Event.ENTITY_DIED, flag));
        if (flag) {
            Team team = this.getTeam();
            if (team != null && team.getDeathMessageVisibility() != Team.EnumVisible.ALWAYS) {
                if (team.getDeathMessageVisibility() == Team.EnumVisible.HIDE_FOR_OTHER_TEAMS) {
                    this.mcServer.getPlayerList().sendMessageToAllTeamMembers((EntityPlayerMP) (Object) this, this.getCombatTracker().getDeathMessage());
                } else if (team.getDeathMessageVisibility() == Team.EnumVisible.HIDE_FOR_OWN_TEAM) {
                    this.mcServer.getPlayerList().sendMessageToTeamOrAllPlayers((EntityPlayerMP) (Object) this, this.getCombatTracker().getDeathMessage());
                }
            } else {
                this.mcServer.getPlayerList().sendMessage(this.getCombatTracker().getDeathMessage());
            }
        }
        this.spawnShoulderEntities();
        // Ignore keepInventory GameRule instead use keepInventory from Event
        if (!event.getKeepInventory() && !this.isSpectator()) {
            this.destroyVanishingCursedItems();
            this.inventory.dropAllItems();
        }
        for (ScoreObjective scoreobjective : this.getWorldScoreboard().getObjectivesFromCriteria(IScoreCriteria.DEATH_COUNT)) {
            Score score = this.getWorldScoreboard().getOrCreateScore(this.getName(), scoreobjective);
            score.incrementScore();
        }
        EntityLivingBase entitylivingbase = this.getAttackingEntity();
        if (entitylivingbase != null) {
            EntityList.EntityEggInfo entitylist$entityegginfo = EntityList.ENTITY_EGGS.get(EntityList.getKey(entitylivingbase));
            if (entitylist$entityegginfo != null) {
                this.addStat(entitylist$entityegginfo.entityKilledByStat);
            }
            entitylivingbase.awardKillScore((EntityPlayerMP) (Object) this, this.scoreValue, cause);
        }
        this.addStat(StatList.DEATHS);
        this.takeStat(StatList.TIME_SINCE_DEATH);
        this.extinguish();
        this.setFlag(0, false);
        this.getCombatTracker().reset();
        this.keepInventory = event.getKeepInventory();
    }
// Sponge - brackets
}
Also used : PhaseData(org.spongepowered.common.event.tracking.PhaseData) IPhaseState(org.spongepowered.common.event.tracking.IPhaseState) EntityList(net.minecraft.entity.EntityList) SPacketCombatEvent(net.minecraft.network.play.server.SPacketCombatEvent) Score(net.minecraft.scoreboard.Score) PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) ScoreObjective(net.minecraft.scoreboard.ScoreObjective) DestructEntityEvent(org.spongepowered.api.event.entity.DestructEntityEvent) EntityLivingBase(net.minecraft.entity.EntityLivingBase) IInteractionObject(net.minecraft.world.IInteractionObject) IMixinTeam(org.spongepowered.common.interfaces.IMixinTeam) Team(net.minecraft.scoreboard.Team) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) IMixinEntityPlayerMP(org.spongepowered.common.interfaces.entity.player.IMixinEntityPlayerMP) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 9 with IPhaseState

use of org.spongepowered.common.event.tracking.IPhaseState in project SpongeCommon by SpongePowered.

the class MixinItemStack method capturePlayerOnBlockDestroyed.

@SuppressWarnings("unchecked")
@Inject(method = "onBlockDestroyed", at = @At("HEAD"))
private void capturePlayerOnBlockDestroyed(World worldIn, IBlockState blockIn, BlockPos pos, EntityPlayer playerIn, CallbackInfo ci) {
    if (!worldIn.isRemote) {
        final PhaseTracker phaseTracker = PhaseTracker.getInstance();
        final PhaseData peek = phaseTracker.getCurrentPhaseData();
        final IPhaseState state = peek.state;
        state.capturePlayerUsingStackToBreakBlock((ItemStack) this, (EntityPlayerMP) playerIn, peek.context);
    }
}
Also used : PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) PhaseData(org.spongepowered.common.event.tracking.PhaseData) IPhaseState(org.spongepowered.common.event.tracking.IPhaseState) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 10 with IPhaseState

use of org.spongepowered.common.event.tracking.IPhaseState in project SpongeCommon by SpongePowered.

the class ExplosionContext method populateFromCurrentState.

@SuppressWarnings("unchecked")
public ExplosionContext populateFromCurrentState() {
    final PhaseData currentPhaseData = PhaseTracker.getInstance().getCurrentPhaseData();
    ((IPhaseState) currentPhaseData.state).appendContextPreExplosion(this, currentPhaseData.context);
    return this;
}
Also used : PhaseData(org.spongepowered.common.event.tracking.PhaseData) IPhaseState(org.spongepowered.common.event.tracking.IPhaseState)

Aggregations

IPhaseState (org.spongepowered.common.event.tracking.IPhaseState)26 PhaseTracker (org.spongepowered.common.event.tracking.PhaseTracker)20 PhaseData (org.spongepowered.common.event.tracking.PhaseData)10 Redirect (org.spongepowered.asm.mixin.injection.Redirect)7 IBlockState (net.minecraft.block.state.IBlockState)5 Overwrite (org.spongepowered.asm.mixin.Overwrite)5 BlockPos (net.minecraft.util.math.BlockPos)4 LocatableBlock (org.spongepowered.api.world.LocatableBlock)4 IMixinWorldServer (org.spongepowered.common.interfaces.world.IMixinWorldServer)4 EntityItem (net.minecraft.entity.item.EntityItem)3 CauseStackManager (org.spongepowered.api.event.CauseStackManager)3 World (org.spongepowered.api.world.World)3 ArrayList (java.util.ArrayList)2 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 Chunk (net.minecraft.world.chunk.Chunk)2 BlockState (org.spongepowered.api.block.BlockState)2 Entity (org.spongepowered.api.entity.Entity)2 Player (org.spongepowered.api.entity.living.player.Player)2 StackFrame (org.spongepowered.api.event.CauseStackManager.StackFrame)2