Search in sources :

Example 1 with EntityList

use of net.minecraft.entity.EntityList 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)

Aggregations

EntityList (net.minecraft.entity.EntityList)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 SPacketCombatEvent (net.minecraft.network.play.server.SPacketCombatEvent)1 Score (net.minecraft.scoreboard.Score)1 ScoreObjective (net.minecraft.scoreboard.ScoreObjective)1 Team (net.minecraft.scoreboard.Team)1 IInteractionObject (net.minecraft.world.IInteractionObject)1 DestructEntityEvent (org.spongepowered.api.event.entity.DestructEntityEvent)1 Overwrite (org.spongepowered.asm.mixin.Overwrite)1 IPhaseState (org.spongepowered.common.event.tracking.IPhaseState)1 PhaseData (org.spongepowered.common.event.tracking.PhaseData)1 PhaseTracker (org.spongepowered.common.event.tracking.PhaseTracker)1 IMixinTeam (org.spongepowered.common.interfaces.IMixinTeam)1 IMixinEntityPlayerMP (org.spongepowered.common.interfaces.entity.player.IMixinEntityPlayerMP)1