Search in sources :

Example 1 with StatisticsManagerServer

use of net.minecraft.stats.StatisticsManagerServer in project malmo by Microsoft.

the class JSONWorldDataHelper method buildAchievementStats.

/**
 * Builds the basic achievement world data to be used as observation signals by the listener.
 * @param json a JSON object into which the achievement stats will be added.
 */
public static void buildAchievementStats(JsonObject json, EntityPlayerMP player) {
    StatisticsManagerServer sfw = player.getStatFile();
    json.addProperty("DistanceTravelled", sfw.readStat((StatBase) StatList.WALK_ONE_CM) + sfw.readStat((StatBase) StatList.SWIM_ONE_CM) + sfw.readStat((StatBase) StatList.DIVE_ONE_CM) + sfw.readStat((StatBase) StatList.FALL_ONE_CM));
    // TODO: there are many other ways of moving!
    json.addProperty("TimeAlive", sfw.readStat((StatBase) StatList.TIME_SINCE_DEATH));
    json.addProperty("MobsKilled", sfw.readStat((StatBase) StatList.MOB_KILLS));
    json.addProperty("PlayersKilled", sfw.readStat((StatBase) StatList.PLAYER_KILLS));
    json.addProperty("DamageTaken", sfw.readStat((StatBase) StatList.DAMAGE_TAKEN));
    json.addProperty("DamageDealt", sfw.readStat((StatBase) StatList.DAMAGE_DEALT));
/* Other potential reinforcement signals that may be worth researching:
        json.addProperty("BlocksDestroyed", sfw.readStat((StatBase)StatList.objectBreakStats) - but objectBreakStats is an array of 32000 StatBase objects - indexed by block type.);
        json.addProperty("Blocked", ev.player.isMovementBlocked()) - but isMovementBlocker() is a protected method (can get round this with reflection)
        */
}
Also used : StatisticsManagerServer(net.minecraft.stats.StatisticsManagerServer) StatBase(net.minecraft.stats.StatBase)

Example 2 with StatisticsManagerServer

use of net.minecraft.stats.StatisticsManagerServer in project SpongeCommon by SpongePowered.

the class StatisticDataProcessor method set.

@Override
protected boolean set(EntityPlayerMP player, Map<Statistic, Long> statMap) {
    checkNotNull(player, "null player");
    checkNotNull(statMap, "null stat map");
    StatisticsManagerServer stats = player.getStatFile();
    for (Entry<Statistic, Long> statEntry : statMap.entrySet()) {
        Long value = statEntry.getValue();
        StatBase stat = (StatBase) statEntry.getKey();
        int currentValue = stats.readStat(stat);
        if (value != null) {
            stats.increaseStat(player, (StatBase) statEntry.getKey(), (int) (value - currentValue));
        }
    }
    return true;
}
Also used : Statistic(org.spongepowered.api.statistic.Statistic) StatisticsManagerServer(net.minecraft.stats.StatisticsManagerServer) StatBase(net.minecraft.stats.StatBase)

Example 3 with StatisticsManagerServer

use of net.minecraft.stats.StatisticsManagerServer in project SpongeCommon by SpongePowered.

the class StatisticDataProcessor method getVal.

@Override
protected Optional<Map<Statistic, Long>> getVal(EntityPlayerMP player) {
    checkNotNull(player, "null player");
    StatisticsManagerServer stats = player.getStatFile();
    Map<StatBase, TupleIntJsonSerializable> data = ((IMixinStatisticsManager) stats).getStatsData();
    Map<Statistic, Long> statMap = Maps.newHashMap();
    for (Entry<StatBase, TupleIntJsonSerializable> statEntry : data.entrySet()) {
        statMap.put((Statistic) statEntry.getKey(), (long) statEntry.getValue().getIntegerValue());
    }
    return Optional.of(statMap);
}
Also used : TupleIntJsonSerializable(net.minecraft.util.TupleIntJsonSerializable) IMixinStatisticsManager(org.spongepowered.common.interfaces.statistic.IMixinStatisticsManager) Statistic(org.spongepowered.api.statistic.Statistic) StatisticsManagerServer(net.minecraft.stats.StatisticsManagerServer) StatBase(net.minecraft.stats.StatBase)

Aggregations

StatBase (net.minecraft.stats.StatBase)3 StatisticsManagerServer (net.minecraft.stats.StatisticsManagerServer)3 Statistic (org.spongepowered.api.statistic.Statistic)2 TupleIntJsonSerializable (net.minecraft.util.TupleIntJsonSerializable)1 IMixinStatisticsManager (org.spongepowered.common.interfaces.statistic.IMixinStatisticsManager)1