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
}
Aggregations