Search in sources :

Example 1 with StatBase

use of net.minecraft.stats.StatBase 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) {
    StatFileWriter sfw = player.getStatFile();
    json.addProperty("DistanceTravelled", sfw.readStat((StatBase) StatList.distanceWalkedStat) + sfw.readStat((StatBase) StatList.distanceSwumStat) + sfw.readStat((StatBase) StatList.distanceDoveStat) + sfw.readStat((StatBase) StatList.distanceFallenStat));
    // TODO: there are many other ways of moving!
    json.addProperty("TimeAlive", sfw.readStat((StatBase) StatList.timeSinceDeathStat));
    json.addProperty("MobsKilled", sfw.readStat((StatBase) StatList.mobKillsStat));
    json.addProperty("PlayersKilled", sfw.readStat((StatBase) StatList.playerKillsStat));
    json.addProperty("DamageTaken", sfw.readStat((StatBase) StatList.damageTakenStat));
/* 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 : StatFileWriter(net.minecraft.stats.StatFileWriter) StatBase(net.minecraft.stats.StatBase)

Example 2 with StatBase

use of net.minecraft.stats.StatBase in project ImmersiveEngineering by BluSunrize.

the class IEAchievements method init.

public static void init() {
    openManual = new AchievementIE("openManual", 0, 1, new ItemStack(IEContent.itemTool, 1, 3), null);
    craftHammer = new AchievementIE("craftHammer", 3, 2, IEContent.itemTool, openManual).setNormalCrafting();
    connectWire = new AchievementIE("connectWire", 0, -1, IEContent.itemWireCoil, openManual);
    blastfurnace = new AchievementIE("blastfurnace", 2, 1, new ItemStack(IEContent.blockStoneDevice, 1, BlockTypes_StoneDevices.BLAST_FURNACE.getMeta()), craftHammer);
    makeSteel = new AchievementIE("makeSteel", 2, -1, new ItemStack(IEContent.itemMetal, 1, 8), blastfurnace);
    placeConveyor = new AchievementIE("placeConveyor", 1, 3, ConveyorHandler.getConveyorStack(ImmersiveEngineering.MODID + ":conveyor"), openManual).setPlacement(new ItemStack(IEContent.blockConveyor));
    placeWindmill = new AchievementIE("placeWindmill", -1, 3, new ItemStack(IEContent.blockWoodenDevice1, 1, BlockTypes_WoodenDevice1.WINDMILL.getMeta()), openManual).setPlacement(new ItemStack(IEContent.blockWoodenDevice1, 1, BlockTypes_WoodenDevice1.WINDMILL.getMeta()), new ItemStack(IEContent.blockWoodenDevice1, 1, BlockTypes_WoodenDevice1.WINDMILL_ADVANCED.getMeta()));
    craftHeater = new AchievementIE("craftHeater", -2, 4, new ItemStack(IEContent.blockMetalDevice1, 1, BlockTypes_MetalDevice1.FURNACE_HEATER.getMeta()), openManual).setNormalCrafting();
    craftPump = new AchievementIE("craftPump", 2, 4, new ItemStack(IEContent.blockMetalDevice0, 1, BlockTypes_MetalDevice0.FLUID_PUMP.getMeta()), openManual).setNormalCrafting();
    placeFloodlight = new AchievementIE("placeFloodlight", -1, 5, new ItemStack(IEContent.blockMetalDevice1, 1, BlockTypes_MetalDevice1.FLOODLIGHT.getMeta()), openManual).setPlacement();
    mbImprovedBlastFurnace = new AchievementIE("mbImprovedBlastFurnace", 6, -3, new ItemStack(IEContent.blockStoneDevice, 1, BlockTypes_StoneDevices.BLAST_FURNACE_ADVANCED.getMeta()), makeSteel).setSpecial();
    mbMetalPress = new AchievementIE("mbMetalPress", 6, -2, new ItemStack(IEContent.blockMetalMultiblock, 1, BlockTypes_MetalMultiblock.METAL_PRESS.getMeta()), makeSteel).setSpecial();
    mbCrusher = new AchievementIE("mbCrusher", 6, -1, new ItemStack(IEContent.blockMetalMultiblock, 1, BlockTypes_MetalMultiblock.CRUSHER.getMeta()), makeSteel).setSpecial();
    mbSilo = new AchievementIE("mbSilo", 7, -2, new ItemStack(IEContent.blockMetalMultiblock, 1, BlockTypes_MetalMultiblock.SILO.getMeta()), craftHammer).setSpecial();
    mbDieselGen = new AchievementIE("mbDieselGen", 6, 0, new ItemStack(IEContent.blockMetalMultiblock, 1, BlockTypes_MetalMultiblock.DIESEL_GENERATOR.getMeta()), craftHammer).setSpecial();
    mbExcavator = new AchievementIE("mbExcavator", 6, 1, new ItemStack(IEContent.blockMetalMultiblock, 1, BlockTypes_MetalMultiblock.EXCAVATOR.getMeta()), craftHammer).setSpecial();
    mbArcFurnace = new AchievementIE("mbArcFurnace", 6, 2, new ItemStack(IEContent.blockMetalMultiblock, 1, BlockTypes_MetalMultiblock.ARC_FURNACE.getMeta()), craftHammer).setSpecial();
    craftWorkbench = new AchievementIE("craftWorkbench", 2, -3, new ItemStack(IEContent.blockWoodenDevice0, 1, BlockTypes_WoodenDevice0.WORKBENCH.getMeta()), makeSteel).setNormalCrafting();
    craftRevolver = new AchievementIE("craftRevolver", 3, -6, IEContent.itemRevolver, craftWorkbench).setNormalCrafting();
    ItemStack[] upgrades = new ItemStack[20];
    upgrades[18] = new ItemStack(IEContent.itemToolUpgrades, 1, 5);
    upgrades[19] = new ItemStack(IEContent.itemToolUpgrades, 1, 6);
    ItemStack revolver = new ItemStack(IEContent.itemRevolver);
    ((ItemRevolver) IEContent.itemRevolver).setContainedItems(revolver, upgrades);
    ((ItemRevolver) IEContent.itemRevolver).recalculateUpgrades(revolver);
    upgradeRevolver = new AchievementIE("upgradeRevolver", 4, -6, revolver, craftRevolver);
    if (!BulletHandler.homingCartridges.isEmpty())
        craftWolfPack = new AchievementIE("craftWolfPack", 4, -7, BulletHandler.getBulletStack("wolfpack"), craftRevolver).setCheckNBT(true).setBlueprintCrafting().setSpecial();
    ItemStack drill = new ItemStack(IEContent.itemDrill);
    ((ItemDrill) IEContent.itemDrill).setHead(drill, new ItemStack(IEContent.itemDrillhead));
    craftDrill = new AchievementIE("craftDrill", 1, -6, drill, craftWorkbench).setNormalCrafting();
    upgrades = new ItemStack[4];
    upgrades[0] = new ItemStack(IEContent.itemDrillhead);
    upgrades[1] = new ItemStack(IEContent.itemToolUpgrades, 1, 0);
    upgrades[2] = new ItemStack(IEContent.itemToolUpgrades, 1, 1);
    upgrades[3] = new ItemStack(IEContent.itemToolUpgrades, 3, 2);
    ItemStack drill2 = drill.copy();
    ((ItemDrill) IEContent.itemDrill).setContainedItems(drill2, upgrades);
    ((ItemDrill) IEContent.itemDrill).recalculateUpgrades(drill2);
    upgradeDrill = new AchievementIE("upgradeDrill", 0, -6, drill2, craftDrill);
    craftSkyhook = new AchievementIE("craftSkyhook", 1, -5, IEContent.itemSkyhook, craftWorkbench).setNormalCrafting();
    ItemStack hook = new ItemStack(IEContent.itemSkyhook);
    hook.addEnchantment(Enchantments.UNBREAKING, 1);
    //skyhookPro = new AchievementIE("skyhookPro", 0, -5, hook, craftSkyhook);
    craftChemthrower = new AchievementIE("craftChemthrower", 3, -5, IEContent.itemChemthrower, craftWorkbench).setNormalCrafting();
    craftRailgun = new AchievementIE("craftRailgun", 1, -7, IEContent.itemRailgun, craftWorkbench).setNormalCrafting();
    secret_birthdayParty = new AchievementIE("secret_birthdayParty", -4, -1, new ItemStack(IEContent.itemFakeIcons, 1, 0), null).setSpecial();
    secret_luckOfTheDraw = new AchievementIE("secret_luckOfTheDraw", -4, 1, new ItemStack(IEContent.itemFakeIcons, 1, 1), null).setSpecial();
    ieAchievementPage = new AchievementPage(ImmersiveEngineering.MODNAME, AchievementIE.achievements.toArray(new Achievement[AchievementIE.achievements.size()]));
    AchievementPage.registerAchievementPage(ieAchievementPage);
    statDistanceSkyhook = new StatBase("stat.skyhookOneCm", new TextComponentTranslation("stat.skyhookOneCm", new Object[0]), StatBase.distanceStatType) {

        @Override
        public StatBase registerStat() {
            super.registerStat();
            StatList.BASIC_STATS.add(12, this);
            return this;
        }
    }.initIndependentStat().registerStat();
}
Also used : ItemRevolver(blusunrize.immersiveengineering.common.items.ItemRevolver) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) AchievementPage(net.minecraftforge.common.AchievementPage) StatBase(net.minecraft.stats.StatBase) ItemStack(net.minecraft.item.ItemStack) ItemDrill(blusunrize.immersiveengineering.common.items.ItemDrill)

Example 3 with StatBase

use of net.minecraft.stats.StatBase in project minecolonies by Minecolonies.

the class Colony method readFromNBT.

/**
     * Read colony from saved data.
     *
     * @param compound compound to read from.
     */
private void readFromNBT(@NotNull final NBTTagCompound compound) {
    name = compound.getString(TAG_NAME);
    center = BlockPosUtil.readFromNBT(compound, TAG_CENTER);
    manualHiring = compound.getBoolean(TAG_MANUAL_HIRING);
    maxCitizens = compound.getInteger(TAG_MAX_CITIZENS);
    // Permissions
    permissions.loadPermissions(compound);
    //  Citizens before Buildings, because Buildings track the Citizens
    final NBTTagList citizenTagList = compound.getTagList(TAG_CITIZENS, NBT.TAG_COMPOUND);
    for (int i = 0; i < citizenTagList.tagCount(); ++i) {
        final NBTTagCompound citizenCompound = citizenTagList.getCompoundTagAt(i);
        final CitizenData data = CitizenData.createFromNBT(citizenCompound, this);
        citizens.put(data.getId(), data);
        topCitizenId = Math.max(topCitizenId, data.getId());
    }
    //  Buildings
    final NBTTagList buildingTagList = compound.getTagList(TAG_BUILDINGS, NBT.TAG_COMPOUND);
    for (int i = 0; i < buildingTagList.tagCount(); ++i) {
        final NBTTagCompound buildingCompound = buildingTagList.getCompoundTagAt(i);
        @Nullable final AbstractBuilding b = AbstractBuilding.createFromNBT(this, buildingCompound);
        if (b != null) {
            addBuilding(b);
        }
    }
    // Fields
    final NBTTagList fieldTagList = compound.getTagList(TAG_FIELDS, NBT.TAG_COMPOUND);
    for (int i = 0; i < fieldTagList.tagCount(); ++i) {
        final NBTTagCompound fieldCompound = fieldTagList.getCompoundTagAt(i);
        final Field f = Field.createFromNBT(this, fieldCompound);
        addField(f);
    }
    // Restore colony achievements
    final NBTTagList achievementTagList = compound.getTagList(TAG_ACHIEVEMENT_LIST, NBT.TAG_COMPOUND);
    for (int i = 0; i < achievementTagList.tagCount(); ++i) {
        final NBTTagCompound achievementCompound = achievementTagList.getCompoundTagAt(i);
        final String achievementKey = achievementCompound.getString(TAG_ACHIEVEMENT);
        final StatBase statBase = StatList.getOneShotStat(achievementKey);
        if (statBase instanceof Achievement) {
            colonyAchievements.add((Achievement) statBase);
        }
    }
    //  Workload
    workManager.readFromNBT(compound.getCompoundTag(TAG_WORK));
    // Waypoints
    final NBTTagList wayPointTagList = compound.getTagList(TAG_WAYPOINT, NBT.TAG_COMPOUND);
    for (int i = 0; i < wayPointTagList.tagCount(); ++i) {
        final NBTTagCompound blockAtPos = wayPointTagList.getCompoundTagAt(i);
        final BlockPos pos = BlockPosUtil.readFromNBT(blockAtPos, TAG_WAYPOINT);
        final IBlockState state = NBTUtil.readBlockState(blockAtPos);
        wayPoints.put(pos, state);
    }
    //Statistics
    final NBTTagCompound statisticsCompound = compound.getCompoundTag(TAG_STATISTICS);
    final NBTTagCompound minerStatisticsCompound = statisticsCompound.getCompoundTag(TAG_MINER_STATISTICS);
    final NBTTagCompound farmerStatisticsCompound = statisticsCompound.getCompoundTag(TAG_FARMER_STATISTICS);
    final NBTTagCompound guardStatisticsCompound = statisticsCompound.getCompoundTag(TAG_FARMER_STATISTICS);
    final NBTTagCompound builderStatisticsCompound = statisticsCompound.getCompoundTag(TAG_BUILDER_STATISTICS);
    final NBTTagCompound fishermanStatisticsCompound = statisticsCompound.getCompoundTag(TAG_FISHERMAN_STATISTICS);
    final NBTTagCompound lumberjackStatisticsCompound = statisticsCompound.getCompoundTag(TAG_LUMBERJACK_STATISTICS);
    minedOres = minerStatisticsCompound.getInteger(TAG_MINER_ORES);
    minedDiamonds = minerStatisticsCompound.getInteger(TAG_MINER_DIAMONDS);
    harvestedCarrots = farmerStatisticsCompound.getInteger(TAG_FARMER_CARROTS);
    harvestedPotatoes = farmerStatisticsCompound.getInteger(TAG_FARMER_POTATOES);
    harvestedWheat = farmerStatisticsCompound.getInteger(TAG_FARMER_WHEAT);
    killedMobs = guardStatisticsCompound.getInteger(TAG_GUARD_MOBS);
    builtHuts = builderStatisticsCompound.getInteger(TAG_BUILDER_HUTS);
    caughtFish = fishermanStatisticsCompound.getInteger(TAG_FISHERMAN_FISH);
    felledTrees = lumberjackStatisticsCompound.getInteger(TAG_LUMBERJACK_TREES);
    plantedSaplings = lumberjackStatisticsCompound.getInteger(TAG_LUMBERJACK_SAPLINGS);
    // Free blocks
    final NBTTagList freeBlockTagList = compound.getTagList(TAG_FREE_BLOCKS, NBT.TAG_STRING);
    for (int i = 0; i < freeBlockTagList.tagCount(); ++i) {
        freeBlocks.add(Block.getBlockFromName(freeBlockTagList.getStringTagAt(i)));
    }
    // Free positions
    final NBTTagList freePositionTagList = compound.getTagList(TAG_FREE_POSITIONS, NBT.TAG_COMPOUND);
    for (int i = 0; i < freePositionTagList.tagCount(); ++i) {
        final NBTTagCompound blockTag = freePositionTagList.getCompoundTagAt(i);
        final BlockPos block = BlockPosUtil.readFromNBT(blockTag, TAG_FREE_POSITIONS);
        freePositions.add(block);
    }
    if (compound.hasKey(TAG_HAPPINESS)) {
        this.overallHappiness = compound.getDouble(TAG_HAPPINESS);
    } else {
        this.overallHappiness = AVERAGE_HAPPINESS;
    }
    lastContactInHours = compound.getInteger(TAG_ABANDONED);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) Field(com.minecolonies.coremod.entity.ai.citizen.farmer.Field) IBlockState(net.minecraft.block.state.IBlockState) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) StatBase(net.minecraft.stats.StatBase) BlockPos(net.minecraft.util.math.BlockPos) NBTTagString(net.minecraft.nbt.NBTTagString) Achievement(net.minecraft.stats.Achievement) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

StatBase (net.minecraft.stats.StatBase)3 ItemDrill (blusunrize.immersiveengineering.common.items.ItemDrill)1 ItemRevolver (blusunrize.immersiveengineering.common.items.ItemRevolver)1 Field (com.minecolonies.coremod.entity.ai.citizen.farmer.Field)1 IBlockState (net.minecraft.block.state.IBlockState)1 ItemStack (net.minecraft.item.ItemStack)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 NBTTagList (net.minecraft.nbt.NBTTagList)1 NBTTagString (net.minecraft.nbt.NBTTagString)1 Achievement (net.minecraft.stats.Achievement)1 StatFileWriter (net.minecraft.stats.StatFileWriter)1 BlockPos (net.minecraft.util.math.BlockPos)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1 AchievementPage (net.minecraftforge.common.AchievementPage)1 Nullable (org.jetbrains.annotations.Nullable)1