Search in sources :

Example 6 with ScoreObjective

use of net.minecraft.scoreboard.ScoreObjective in project SpongeCommon by SpongePowered.

the class SpongeObjective method addScore.

@Override
public void addScore(Score score) throws IllegalArgumentException {
    if (this.scores.containsKey(score.getName())) {
        throw new IllegalArgumentException(String.format("A score with the name %s already exists!", SpongeTexts.toLegacy(score.getName())));
    }
    this.scores.put(score.getName(), score);
    SpongeScore spongeScore = (SpongeScore) score;
    for (ScoreObjective objective : this.objectives.values()) {
        this.addScoreToScoreboard(objective.scoreboard, spongeScore.getScoreFor(objective));
    }
}
Also used : ScoreObjective(net.minecraft.scoreboard.ScoreObjective) IMixinScoreObjective(org.spongepowered.common.interfaces.IMixinScoreObjective)

Example 7 with ScoreObjective

use of net.minecraft.scoreboard.ScoreObjective in project SpongeCommon by SpongePowered.

the class SpongeObjective method updateScores.

public void updateScores(net.minecraft.scoreboard.Scoreboard scoreboard) {
    ScoreObjective objective = this.getObjectiveFor(scoreboard);
    for (Score score : this.getScores().values()) {
        SpongeScore spongeScore = (SpongeScore) score;
        this.addScoreToScoreboard(scoreboard, spongeScore.getScoreFor(objective));
    }
}
Also used : Score(org.spongepowered.api.scoreboard.Score) ScoreObjective(net.minecraft.scoreboard.ScoreObjective) IMixinScoreObjective(org.spongepowered.common.interfaces.IMixinScoreObjective)

Example 8 with ScoreObjective

use of net.minecraft.scoreboard.ScoreObjective 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 ScoreObjective

use of net.minecraft.scoreboard.ScoreObjective in project Hyperium by HyperiumClient.

the class AboveHeadRenderer method render.

@InvokeEvent
public void render(RenderPlayerEvent event) {
    if (levelhead == null || levelhead.getDisplayManager() == null || levelhead.getDisplayManager().getMasterConfig() == null || !levelhead.getDisplayManager().getMasterConfig().isEnabled()) {
        return;
    }
    EntityPlayer player = event.getEntity();
    int o = 0;
    for (AboveHeadDisplay display : levelhead.getDisplayManager().getAboveHead()) {
        int index = display.getIndex();
        int extraHead = levelhead.getLevelheadPurchaseStates().getExtraHead();
        if (index > extraHead || !display.getConfig().isEnabled())
            continue;
        LevelheadTag levelheadTag = display.getCache().get(player.getUniqueID());
        if (display.loadOrRender(player) && levelheadTag != null && !(levelheadTag instanceof NullLevelheadTag)) {
            if ((event.getEntity().getUniqueID().equals(Levelhead.getInstance().userUuid) && !display.getConfig().isShowSelf() || !Hyperium.INSTANCE.getHandlers().getHypixelDetector().isHypixel())) {
                continue;
            }
            if (player.getDistanceSqToEntity(Minecraft.getMinecraft().thePlayer) < 64 * 64) {
                double offset = 0.3;
                Scoreboard scoreboard = player.getWorldScoreboard();
                ScoreObjective objective = scoreboard.getObjectiveInDisplaySlot(2);
                if (objective != null && event.getEntity().getDistanceSqToEntity(Minecraft.getMinecraft().thePlayer) < 10 * 10) {
                    offset *= 2;
                }
                if (player.getUniqueID().equals(levelhead.userUuid) && !Settings.SHOW_OWN_NAME)
                    offset -= .3;
                if (Hyperium.INSTANCE.getCosmetics().getDeadmau5Cosmetic().isPurchasedBy(event.getEntity().getUniqueID())) {
                    HyperiumPurchase packageIfReady = PurchaseApi.getInstance().getPackageIfReady(event.getEntity().getUniqueID());
                    if (packageIfReady != null) {
                        AbstractHyperiumPurchase purchase = packageIfReady.getPurchase(EnumPurchaseType.DEADMAU5_COSMETIC);
                        if (purchase != null) {
                            if (event.getEntity().getUniqueID() != Minecraft.getMinecraft().thePlayer.getUniqueID()) {
                                if (((EarsCosmetic) purchase).isEnabled()) {
                                    offset += .3;
                                }
                            } else if (Settings.EARS_STATE.equalsIgnoreCase("on")) {
                                offset += .2;
                            }
                        }
                    }
                }
                offset += levelhead.getDisplayManager().getMasterConfig().getOffset();
                renderName(event, levelheadTag, player, event.getX(), event.getY() + offset + o * .3D, event.getZ());
            }
        }
        o++;
    }
}
Also used : ScoreObjective(net.minecraft.scoreboard.ScoreObjective) AbstractHyperiumPurchase(cc.hyperium.purchases.AbstractHyperiumPurchase) HyperiumPurchase(cc.hyperium.purchases.HyperiumPurchase) Scoreboard(net.minecraft.scoreboard.Scoreboard) AbstractHyperiumPurchase(cc.hyperium.purchases.AbstractHyperiumPurchase) EarsCosmetic(cc.hyperium.purchases.packages.EarsCosmetic) EntityPlayer(net.minecraft.entity.player.EntityPlayer) AboveHeadDisplay(cc.hyperium.mods.levelhead.display.AboveHeadDisplay) InvokeEvent(cc.hyperium.event.InvokeEvent)

Example 10 with ScoreObjective

use of net.minecraft.scoreboard.ScoreObjective in project takumicraft by TNTModders.

the class RenderPlayerSP method renderEntityName.

/**
 * Allows the render to do state modifications necessary before the model is rendered.
 */
/*    @Override
    protected void preRenderCallback(AbstractClientPlayer entitylivingbaseIn, float partialTickTime) {
        float f = 0.9375F;
        GlStateManager.scale(0.9375F, 0.9375F, 0.9375F);
    }*/
@Override
protected void renderEntityName(AbstractClientPlayer entityIn, double x, double y, double z, String name, double distanceSq) {
    if (distanceSq < 100.0D) {
        Scoreboard scoreboard = entityIn.getWorldScoreboard();
        ScoreObjective scoreobjective = scoreboard.getObjectiveInDisplaySlot(2);
        if (scoreobjective != null) {
            Score score = scoreboard.getOrCreateScore(entityIn.getName(), scoreobjective);
            this.renderLivingLabel(entityIn, score.getScorePoints() + " " + scoreobjective.getDisplayName(), x, y, z, 64);
            y += (double) ((float) this.getFontRendererFromRenderManager().FONT_HEIGHT * 1.15F * 0.025F);
        }
    }
    super.renderEntityName(entityIn, x, y, z, name, distanceSq);
}
Also used : Score(net.minecraft.scoreboard.Score) ScoreObjective(net.minecraft.scoreboard.ScoreObjective) Scoreboard(net.minecraft.scoreboard.Scoreboard)

Aggregations

ScoreObjective (net.minecraft.scoreboard.ScoreObjective)22 IMixinScoreObjective (org.spongepowered.common.interfaces.IMixinScoreObjective)10 Score (net.minecraft.scoreboard.Score)7 Scoreboard (net.minecraft.scoreboard.Scoreboard)7 SpongeObjective (org.spongepowered.common.scoreboard.SpongeObjective)4 ScaledResolution (net.minecraft.client.gui.ScaledResolution)3 ScorePlayerTeam (net.minecraft.scoreboard.ScorePlayerTeam)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 IScoreCriteria (net.minecraft.scoreboard.IScoreCriteria)2 Score (org.spongepowered.api.scoreboard.Score)2 Overwrite (org.spongepowered.asm.mixin.Overwrite)2 IMixinScore (org.spongepowered.common.interfaces.IMixinScore)2 SpongeScore (org.spongepowered.common.scoreboard.SpongeScore)2 ConfigOpt (cc.hyperium.config.ConfigOpt)1 EventBus (cc.hyperium.event.EventBus)1 InvokeEvent (cc.hyperium.event.InvokeEvent)1 RenderScoreboardEvent (cc.hyperium.event.render.RenderScoreboardEvent)1