base mod created

This commit is contained in:
Mohammad-Ali Minaie
2018-10-08 09:07:47 -04:00
parent 0a7700c356
commit b86dedad2f
7848 changed files with 584664 additions and 1 deletions

View File

@@ -0,0 +1,13 @@
package net.minecraft.stats;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public interface IStatType
{
/**
* Formats a given stat for human consumption.
*/
@SideOnly(Side.CLIENT)
String format(int number);
}

View File

@@ -0,0 +1,96 @@
package net.minecraft.stats;
import java.util.BitSet;
import javax.annotation.Nullable;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class RecipeBook
{
protected final BitSet recipes = new BitSet();
/** Recipes the player has not yet seen, so the GUI can play an animation */
protected final BitSet newRecipes = new BitSet();
protected boolean isGuiOpen;
protected boolean isFilteringCraftable;
public void copyFrom(RecipeBook that)
{
this.recipes.clear();
this.newRecipes.clear();
this.recipes.or(that.recipes);
this.newRecipes.or(that.newRecipes);
}
public void unlock(IRecipe recipe)
{
if (!recipe.isDynamic())
{
this.recipes.set(getRecipeId(recipe));
}
}
public boolean isUnlocked(@Nullable IRecipe recipe)
{
return this.recipes.get(getRecipeId(recipe));
}
public void lock(IRecipe recipe)
{
int i = getRecipeId(recipe);
this.recipes.clear(i);
this.newRecipes.clear(i);
}
@Deprecated //DO NOT USE
protected static int getRecipeId(@Nullable IRecipe recipe)
{
int ret = CraftingManager.REGISTRY.getIDForObject(recipe);
if (ret == -1)
{
ret = ((net.minecraftforge.registries.ForgeRegistry<IRecipe>)net.minecraftforge.fml.common.registry.ForgeRegistries.RECIPES).getID(recipe.getRegistryName());
if (ret == -1)
throw new IllegalArgumentException(String.format("Attempted to get the ID for a unknown recipe: %s Name: %s", recipe, recipe.getRegistryName()));
}
return ret;
}
@SideOnly(Side.CLIENT)
public boolean isNew(IRecipe recipe)
{
return this.newRecipes.get(getRecipeId(recipe));
}
public void markSeen(IRecipe recipe)
{
this.newRecipes.clear(getRecipeId(recipe));
}
public void markNew(IRecipe recipe)
{
this.newRecipes.set(getRecipeId(recipe));
}
@SideOnly(Side.CLIENT)
public boolean isGuiOpen()
{
return this.isGuiOpen;
}
public void setGuiOpen(boolean open)
{
this.isGuiOpen = open;
}
@SideOnly(Side.CLIENT)
public boolean isFilteringCraftable()
{
return this.isFilteringCraftable;
}
public void setFilteringCraftable(boolean shouldFilter)
{
this.isFilteringCraftable = shouldFilter;
}
}

View File

@@ -0,0 +1,152 @@
package net.minecraft.stats;
import com.google.common.collect.Lists;
import java.util.Collections;
import java.util.List;
import net.minecraft.advancements.CriteriaTriggers;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.NBTTagString;
import net.minecraft.network.play.server.SPacketRecipeBook;
import net.minecraft.util.ResourceLocation;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class RecipeBookServer extends RecipeBook
{
private static final Logger LOGGER = LogManager.getLogger();
public void add(List<IRecipe> recipesIn, EntityPlayerMP player)
{
List<IRecipe> list = Lists.<IRecipe>newArrayList();
for (IRecipe irecipe : recipesIn)
{
if (!this.recipes.get(getRecipeId(irecipe)) && !irecipe.isDynamic())
{
this.unlock(irecipe);
this.markNew(irecipe);
list.add(irecipe);
CriteriaTriggers.RECIPE_UNLOCKED.trigger(player, irecipe);
}
}
this.sendPacket(SPacketRecipeBook.State.ADD, player, list);
}
public void remove(List<IRecipe> recipesIn, EntityPlayerMP player)
{
List<IRecipe> list = Lists.<IRecipe>newArrayList();
for (IRecipe irecipe : recipesIn)
{
if (this.recipes.get(getRecipeId(irecipe)))
{
this.lock(irecipe);
list.add(irecipe);
}
}
this.sendPacket(SPacketRecipeBook.State.REMOVE, player, list);
}
private void sendPacket(SPacketRecipeBook.State state, EntityPlayerMP player, List<IRecipe> recipesIn)
{
net.minecraftforge.common.ForgeHooks.sendRecipeBook(player.connection, state, recipesIn, Collections.emptyList(), this.isGuiOpen, this.isFilteringCraftable);
}
public NBTTagCompound write()
{
NBTTagCompound nbttagcompound = new NBTTagCompound();
nbttagcompound.setBoolean("isGuiOpen", this.isGuiOpen);
nbttagcompound.setBoolean("isFilteringCraftable", this.isFilteringCraftable);
NBTTagList nbttaglist = new NBTTagList();
for (IRecipe irecipe : this.getRecipes())
{
nbttaglist.appendTag(new NBTTagString(((ResourceLocation)CraftingManager.REGISTRY.getNameForObject(irecipe)).toString()));
}
nbttagcompound.setTag("recipes", nbttaglist);
NBTTagList nbttaglist1 = new NBTTagList();
for (IRecipe irecipe1 : this.getDisplayedRecipes())
{
nbttaglist1.appendTag(new NBTTagString(((ResourceLocation)CraftingManager.REGISTRY.getNameForObject(irecipe1)).toString()));
}
nbttagcompound.setTag("toBeDisplayed", nbttaglist1);
return nbttagcompound;
}
public void read(NBTTagCompound tag)
{
this.isGuiOpen = tag.getBoolean("isGuiOpen");
this.isFilteringCraftable = tag.getBoolean("isFilteringCraftable");
NBTTagList nbttaglist = tag.getTagList("recipes", 8);
for (int i = 0; i < nbttaglist.tagCount(); ++i)
{
ResourceLocation resourcelocation = new ResourceLocation(nbttaglist.getStringTagAt(i));
IRecipe irecipe = CraftingManager.getRecipe(resourcelocation);
if (irecipe == null)
{
LOGGER.info("Tried to load unrecognized recipe: {} removed now.", (Object)resourcelocation);
}
else
{
this.unlock(irecipe);
}
}
NBTTagList nbttaglist1 = tag.getTagList("toBeDisplayed", 8);
for (int j = 0; j < nbttaglist1.tagCount(); ++j)
{
ResourceLocation resourcelocation1 = new ResourceLocation(nbttaglist1.getStringTagAt(j));
IRecipe irecipe1 = CraftingManager.getRecipe(resourcelocation1);
if (irecipe1 == null)
{
LOGGER.info("Tried to load unrecognized recipe: {} removed now.", (Object)resourcelocation1);
}
else
{
this.markNew(irecipe1);
}
}
}
private List<IRecipe> getRecipes()
{
List<IRecipe> list = Lists.<IRecipe>newArrayList();
for (int i = this.recipes.nextSetBit(0); i >= 0; i = this.recipes.nextSetBit(i + 1))
{
list.add(CraftingManager.REGISTRY.getObjectById(i));
}
return list;
}
private List<IRecipe> getDisplayedRecipes()
{
List<IRecipe> list = Lists.<IRecipe>newArrayList();
for (int i = this.newRecipes.nextSetBit(0); i >= 0; i = this.newRecipes.nextSetBit(i + 1))
{
list.add(CraftingManager.REGISTRY.getObjectById(i));
}
return list;
}
public void init(EntityPlayerMP player)
{
net.minecraftforge.common.ForgeHooks.sendRecipeBook(player.connection, SPacketRecipeBook.State.INIT, this.getRecipes(), this.getDisplayedRecipes(), this.isGuiOpen, this.isFilteringCraftable);
}
}

View File

@@ -0,0 +1,195 @@
package net.minecraft.stats;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Locale;
import net.minecraft.scoreboard.IScoreCriteria;
import net.minecraft.scoreboard.ScoreCriteriaStat;
import net.minecraft.util.IJsonSerializable;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class StatBase
{
/** The Stat ID */
public final String statId;
/** The Stat name */
private final ITextComponent statName;
public boolean isIndependent;
private final IStatType formatter;
private final IScoreCriteria objectiveCriteria;
private Class <? extends IJsonSerializable > serializableClazz;
private static final NumberFormat numberFormat = NumberFormat.getIntegerInstance(Locale.US);
public static IStatType simpleStatType = new IStatType()
{
/**
* Formats a given stat for human consumption.
*/
@SideOnly(Side.CLIENT)
public String format(int number)
{
return StatBase.numberFormat.format((long)number);
}
};
private static final DecimalFormat decimalFormat = new DecimalFormat("########0.00");
public static IStatType timeStatType = new IStatType()
{
/**
* Formats a given stat for human consumption.
*/
@SideOnly(Side.CLIENT)
public String format(int number)
{
double d0 = (double)number / 20.0D;
double d1 = d0 / 60.0D;
double d2 = d1 / 60.0D;
double d3 = d2 / 24.0D;
double d4 = d3 / 365.0D;
if (d4 > 0.5D)
{
return StatBase.decimalFormat.format(d4) + " y";
}
else if (d3 > 0.5D)
{
return StatBase.decimalFormat.format(d3) + " d";
}
else if (d2 > 0.5D)
{
return StatBase.decimalFormat.format(d2) + " h";
}
else
{
return d1 > 0.5D ? StatBase.decimalFormat.format(d1) + " m" : d0 + " s";
}
}
};
public static IStatType distanceStatType = new IStatType()
{
/**
* Formats a given stat for human consumption.
*/
@SideOnly(Side.CLIENT)
public String format(int number)
{
double d0 = (double)number / 100.0D;
double d1 = d0 / 1000.0D;
if (d1 > 0.5D)
{
return StatBase.decimalFormat.format(d1) + " km";
}
else
{
return d0 > 0.5D ? StatBase.decimalFormat.format(d0) + " m" : number + " cm";
}
}
};
public static IStatType divideByTen = new IStatType()
{
/**
* Formats a given stat for human consumption.
*/
@SideOnly(Side.CLIENT)
public String format(int number)
{
return StatBase.decimalFormat.format((double)number * 0.1D);
}
};
public StatBase(String statIdIn, ITextComponent statNameIn, IStatType formatterIn)
{
this.statId = statIdIn;
this.statName = statNameIn;
this.formatter = formatterIn;
this.objectiveCriteria = new ScoreCriteriaStat(this);
IScoreCriteria.INSTANCES.put(this.objectiveCriteria.getName(), this.objectiveCriteria);
}
public StatBase(String statIdIn, ITextComponent statNameIn)
{
this(statIdIn, statNameIn, simpleStatType);
}
/**
* Initializes the current stat as independent (i.e., lacking prerequisites for being updated) and returns the
* current instance.
*/
public StatBase initIndependentStat()
{
this.isIndependent = true;
return this;
}
/**
* Register the stat into StatList.
*/
public StatBase registerStat()
{
if (StatList.ID_TO_STAT_MAP.containsKey(this.statId))
{
throw new RuntimeException("Duplicate stat id: \"" + (StatList.ID_TO_STAT_MAP.get(this.statId)).statName + "\" and \"" + this.statName + "\" at id " + this.statId);
}
else
{
StatList.ALL_STATS.add(this);
StatList.ID_TO_STAT_MAP.put(this.statId, this);
return this;
}
}
@SideOnly(Side.CLIENT)
public String format(int number)
{
return this.formatter.format(number);
}
public ITextComponent getStatName()
{
ITextComponent itextcomponent = this.statName.createCopy();
itextcomponent.getStyle().setColor(TextFormatting.GRAY);
return itextcomponent;
}
public boolean equals(Object p_equals_1_)
{
if (this == p_equals_1_)
{
return true;
}
else if (p_equals_1_ != null && this.getClass() == p_equals_1_.getClass())
{
StatBase statbase = (StatBase)p_equals_1_;
return this.statId.equals(statbase.statId);
}
else
{
return false;
}
}
public int hashCode()
{
return this.statId.hashCode();
}
public String toString()
{
return "Stat{id=" + this.statId + ", nameId=" + this.statName + ", awardLocallyOnly=" + this.isIndependent + ", formatter=" + this.formatter + ", objectiveCriteria=" + this.objectiveCriteria + '}';
}
/**
* 1.8.9
*/
public IScoreCriteria getCriteria()
{
return this.objectiveCriteria;
}
public Class <? extends IJsonSerializable > getSerializableClazz()
{
return this.serializableClazz;
}
}

View File

@@ -0,0 +1,26 @@
package net.minecraft.stats;
import net.minecraft.util.text.ITextComponent;
public class StatBasic extends StatBase
{
public StatBasic(String statIdIn, ITextComponent statNameIn, IStatType typeIn)
{
super(statIdIn, statNameIn, typeIn);
}
public StatBasic(String statIdIn, ITextComponent statNameIn)
{
super(statIdIn, statNameIn);
}
/**
* Register the stat into StatList.
*/
public StatBase registerStat()
{
super.registerStat();
StatList.BASIC_STATS.add(this);
return this;
}
}

View File

@@ -0,0 +1,23 @@
package net.minecraft.stats;
import net.minecraft.item.Item;
import net.minecraft.util.text.ITextComponent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class StatCrafting extends StatBase
{
private final Item item;
public StatCrafting(String p_i45910_1_, String p_i45910_2_, ITextComponent statNameIn, Item p_i45910_4_)
{
super(p_i45910_1_ + p_i45910_2_, statNameIn);
this.item = p_i45910_4_;
}
@SideOnly(Side.CLIENT)
public Item getItem()
{
return this.item;
}
}

View File

@@ -0,0 +1,364 @@
package net.minecraft.stats;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nullable;
import net.minecraft.block.Block;
import net.minecraft.entity.EntityList;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.TextComponentTranslation;
public class StatList
{
protected static final Map<String, StatBase> ID_TO_STAT_MAP = Maps.<String, StatBase>newHashMap();
public static final List<StatBase> ALL_STATS = Lists.<StatBase>newArrayList();
public static final List<StatBase> BASIC_STATS = Lists.<StatBase>newArrayList();
public static final List<StatCrafting> USE_ITEM_STATS = Lists.<StatCrafting>newArrayList();
public static final List<StatCrafting> MINE_BLOCK_STATS = Lists.<StatCrafting>newArrayList();
/** number of times you've left a game */
public static final StatBase LEAVE_GAME = (new StatBasic("stat.leaveGame", new TextComponentTranslation("stat.leaveGame", new Object[0]))).initIndependentStat().registerStat();
public static final StatBase PLAY_ONE_MINUTE = (new StatBasic("stat.playOneMinute", new TextComponentTranslation("stat.playOneMinute", new Object[0]), StatBase.timeStatType)).initIndependentStat().registerStat();
public static final StatBase TIME_SINCE_DEATH = (new StatBasic("stat.timeSinceDeath", new TextComponentTranslation("stat.timeSinceDeath", new Object[0]), StatBase.timeStatType)).initIndependentStat().registerStat();
public static final StatBase SNEAK_TIME = (new StatBasic("stat.sneakTime", new TextComponentTranslation("stat.sneakTime", new Object[0]), StatBase.timeStatType)).initIndependentStat().registerStat();
public static final StatBase WALK_ONE_CM = (new StatBasic("stat.walkOneCm", new TextComponentTranslation("stat.walkOneCm", new Object[0]), StatBase.distanceStatType)).initIndependentStat().registerStat();
public static final StatBase CROUCH_ONE_CM = (new StatBasic("stat.crouchOneCm", new TextComponentTranslation("stat.crouchOneCm", new Object[0]), StatBase.distanceStatType)).initIndependentStat().registerStat();
public static final StatBase SPRINT_ONE_CM = (new StatBasic("stat.sprintOneCm", new TextComponentTranslation("stat.sprintOneCm", new Object[0]), StatBase.distanceStatType)).initIndependentStat().registerStat();
/** distance you have swam */
public static final StatBase SWIM_ONE_CM = (new StatBasic("stat.swimOneCm", new TextComponentTranslation("stat.swimOneCm", new Object[0]), StatBase.distanceStatType)).initIndependentStat().registerStat();
/** the distance you have fallen */
public static final StatBase FALL_ONE_CM = (new StatBasic("stat.fallOneCm", new TextComponentTranslation("stat.fallOneCm", new Object[0]), StatBase.distanceStatType)).initIndependentStat().registerStat();
public static final StatBase CLIMB_ONE_CM = (new StatBasic("stat.climbOneCm", new TextComponentTranslation("stat.climbOneCm", new Object[0]), StatBase.distanceStatType)).initIndependentStat().registerStat();
public static final StatBase FLY_ONE_CM = (new StatBasic("stat.flyOneCm", new TextComponentTranslation("stat.flyOneCm", new Object[0]), StatBase.distanceStatType)).initIndependentStat().registerStat();
public static final StatBase DIVE_ONE_CM = (new StatBasic("stat.diveOneCm", new TextComponentTranslation("stat.diveOneCm", new Object[0]), StatBase.distanceStatType)).initIndependentStat().registerStat();
public static final StatBase MINECART_ONE_CM = (new StatBasic("stat.minecartOneCm", new TextComponentTranslation("stat.minecartOneCm", new Object[0]), StatBase.distanceStatType)).initIndependentStat().registerStat();
public static final StatBase BOAT_ONE_CM = (new StatBasic("stat.boatOneCm", new TextComponentTranslation("stat.boatOneCm", new Object[0]), StatBase.distanceStatType)).initIndependentStat().registerStat();
public static final StatBase PIG_ONE_CM = (new StatBasic("stat.pigOneCm", new TextComponentTranslation("stat.pigOneCm", new Object[0]), StatBase.distanceStatType)).initIndependentStat().registerStat();
public static final StatBase HORSE_ONE_CM = (new StatBasic("stat.horseOneCm", new TextComponentTranslation("stat.horseOneCm", new Object[0]), StatBase.distanceStatType)).initIndependentStat().registerStat();
public static final StatBase AVIATE_ONE_CM = (new StatBasic("stat.aviateOneCm", new TextComponentTranslation("stat.aviateOneCm", new Object[0]), StatBase.distanceStatType)).initIndependentStat().registerStat();
/** the times you've jumped */
public static final StatBase JUMP = (new StatBasic("stat.jump", new TextComponentTranslation("stat.jump", new Object[0]))).initIndependentStat().registerStat();
/** the distance you've dropped (or times you've fallen?) */
public static final StatBase DROP = (new StatBasic("stat.drop", new TextComponentTranslation("stat.drop", new Object[0]))).initIndependentStat().registerStat();
public static final StatBase DAMAGE_DEALT = (new StatBasic("stat.damageDealt", new TextComponentTranslation("stat.damageDealt", new Object[0]), StatBase.divideByTen)).registerStat();
public static final StatBase DAMAGE_TAKEN = (new StatBasic("stat.damageTaken", new TextComponentTranslation("stat.damageTaken", new Object[0]), StatBase.divideByTen)).registerStat();
public static final StatBase DEATHS = (new StatBasic("stat.deaths", new TextComponentTranslation("stat.deaths", new Object[0]))).registerStat();
public static final StatBase MOB_KILLS = (new StatBasic("stat.mobKills", new TextComponentTranslation("stat.mobKills", new Object[0]))).registerStat();
/** the number of animals you have bred */
public static final StatBase ANIMALS_BRED = (new StatBasic("stat.animalsBred", new TextComponentTranslation("stat.animalsBred", new Object[0]))).registerStat();
/** counts the number of times you've killed a player */
public static final StatBase PLAYER_KILLS = (new StatBasic("stat.playerKills", new TextComponentTranslation("stat.playerKills", new Object[0]))).registerStat();
public static final StatBase FISH_CAUGHT = (new StatBasic("stat.fishCaught", new TextComponentTranslation("stat.fishCaught", new Object[0]))).registerStat();
public static final StatBase TALKED_TO_VILLAGER = (new StatBasic("stat.talkedToVillager", new TextComponentTranslation("stat.talkedToVillager", new Object[0]))).registerStat();
public static final StatBase TRADED_WITH_VILLAGER = (new StatBasic("stat.tradedWithVillager", new TextComponentTranslation("stat.tradedWithVillager", new Object[0]))).registerStat();
public static final StatBase CAKE_SLICES_EATEN = (new StatBasic("stat.cakeSlicesEaten", new TextComponentTranslation("stat.cakeSlicesEaten", new Object[0]))).registerStat();
public static final StatBase CAULDRON_FILLED = (new StatBasic("stat.cauldronFilled", new TextComponentTranslation("stat.cauldronFilled", new Object[0]))).registerStat();
public static final StatBase CAULDRON_USED = (new StatBasic("stat.cauldronUsed", new TextComponentTranslation("stat.cauldronUsed", new Object[0]))).registerStat();
public static final StatBase ARMOR_CLEANED = (new StatBasic("stat.armorCleaned", new TextComponentTranslation("stat.armorCleaned", new Object[0]))).registerStat();
public static final StatBase BANNER_CLEANED = (new StatBasic("stat.bannerCleaned", new TextComponentTranslation("stat.bannerCleaned", new Object[0]))).registerStat();
public static final StatBase BREWINGSTAND_INTERACTION = (new StatBasic("stat.brewingstandInteraction", new TextComponentTranslation("stat.brewingstandInteraction", new Object[0]))).registerStat();
public static final StatBase BEACON_INTERACTION = (new StatBasic("stat.beaconInteraction", new TextComponentTranslation("stat.beaconInteraction", new Object[0]))).registerStat();
public static final StatBase DROPPER_INSPECTED = (new StatBasic("stat.dropperInspected", new TextComponentTranslation("stat.dropperInspected", new Object[0]))).registerStat();
public static final StatBase HOPPER_INSPECTED = (new StatBasic("stat.hopperInspected", new TextComponentTranslation("stat.hopperInspected", new Object[0]))).registerStat();
public static final StatBase DISPENSER_INSPECTED = (new StatBasic("stat.dispenserInspected", new TextComponentTranslation("stat.dispenserInspected", new Object[0]))).registerStat();
public static final StatBase NOTEBLOCK_PLAYED = (new StatBasic("stat.noteblockPlayed", new TextComponentTranslation("stat.noteblockPlayed", new Object[0]))).registerStat();
public static final StatBase NOTEBLOCK_TUNED = (new StatBasic("stat.noteblockTuned", new TextComponentTranslation("stat.noteblockTuned", new Object[0]))).registerStat();
public static final StatBase FLOWER_POTTED = (new StatBasic("stat.flowerPotted", new TextComponentTranslation("stat.flowerPotted", new Object[0]))).registerStat();
public static final StatBase TRAPPED_CHEST_TRIGGERED = (new StatBasic("stat.trappedChestTriggered", new TextComponentTranslation("stat.trappedChestTriggered", new Object[0]))).registerStat();
public static final StatBase ENDERCHEST_OPENED = (new StatBasic("stat.enderchestOpened", new TextComponentTranslation("stat.enderchestOpened", new Object[0]))).registerStat();
public static final StatBase ITEM_ENCHANTED = (new StatBasic("stat.itemEnchanted", new TextComponentTranslation("stat.itemEnchanted", new Object[0]))).registerStat();
public static final StatBase RECORD_PLAYED = (new StatBasic("stat.recordPlayed", new TextComponentTranslation("stat.recordPlayed", new Object[0]))).registerStat();
public static final StatBase FURNACE_INTERACTION = (new StatBasic("stat.furnaceInteraction", new TextComponentTranslation("stat.furnaceInteraction", new Object[0]))).registerStat();
public static final StatBase CRAFTING_TABLE_INTERACTION = (new StatBasic("stat.craftingTableInteraction", new TextComponentTranslation("stat.workbenchInteraction", new Object[0]))).registerStat();
public static final StatBase CHEST_OPENED = (new StatBasic("stat.chestOpened", new TextComponentTranslation("stat.chestOpened", new Object[0]))).registerStat();
public static final StatBase SLEEP_IN_BED = (new StatBasic("stat.sleepInBed", new TextComponentTranslation("stat.sleepInBed", new Object[0]))).registerStat();
public static final StatBase OPEN_SHULKER_BOX = (new StatBasic("stat.shulkerBoxOpened", new TextComponentTranslation("stat.shulkerBoxOpened", new Object[0]))).registerStat();
private static final StatBase[] BLOCKS_STATS = new StatBase[4096];
private static final StatBase[] CRAFTS_STATS = new StatBase[32000];
/** Tracks the number of times a given block or item has been used. */
private static final StatBase[] OBJECT_USE_STATS = new StatBase[32000];
/** Tracks the number of times a given block or item has been broken. */
private static final StatBase[] OBJECT_BREAK_STATS = new StatBase[32000];
private static final StatBase[] OBJECTS_PICKED_UP_STATS = new StatBase[32000];
private static final StatBase[] OBJECTS_DROPPED_STATS = new StatBase[32000];
@Nullable
public static StatBase getBlockStats(Block blockIn)
{
return BLOCKS_STATS[Block.getIdFromBlock(blockIn)];
}
@Nullable
public static StatBase getCraftStats(Item itemIn)
{
return CRAFTS_STATS[Item.getIdFromItem(itemIn)];
}
@Nullable
public static StatBase getObjectUseStats(Item itemIn)
{
return OBJECT_USE_STATS[Item.getIdFromItem(itemIn)];
}
@Nullable
public static StatBase getObjectBreakStats(Item itemIn)
{
return OBJECT_BREAK_STATS[Item.getIdFromItem(itemIn)];
}
@Nullable
public static StatBase getObjectsPickedUpStats(Item itemIn)
{
return OBJECTS_PICKED_UP_STATS[Item.getIdFromItem(itemIn)];
}
@Nullable
public static StatBase getDroppedObjectStats(Item itemIn)
{
return OBJECTS_DROPPED_STATS[Item.getIdFromItem(itemIn)];
}
public static void init()
{
initMiningStats();
initStats();
initItemDepleteStats();
initCraftableStats();
initPickedUpAndDroppedStats();
}
/**
* Initializes statistics related to craftable items. Is only called after both block and item stats have been
* initialized.
*/
private static void initCraftableStats()
{
Set<Item> set = Sets.<Item>newHashSet();
for (IRecipe irecipe : CraftingManager.REGISTRY)
{
ItemStack itemstack = irecipe.getRecipeOutput();
if (!itemstack.isEmpty())
{
set.add(irecipe.getRecipeOutput().getItem());
}
}
for (ItemStack itemstack1 : FurnaceRecipes.instance().getSmeltingList().values())
{
set.add(itemstack1.getItem());
}
for (Item item : set)
{
if (item != null)
{
int i = Item.getIdFromItem(item);
String s = getItemName(item);
if (s != null)
{
CRAFTS_STATS[i] = (new StatCrafting("stat.craftItem.", s, new TextComponentTranslation("stat.craftItem", new Object[] {(new ItemStack(item)).getTextComponent()}), item)).registerStat();
}
}
}
replaceAllSimilarBlocks(CRAFTS_STATS, true);
}
private static void initMiningStats()
{
for (Block block : Block.REGISTRY)
{
Item item = Item.getItemFromBlock(block);
if (item != Items.AIR)
{
int i = Block.getIdFromBlock(block);
String s = getItemName(item);
if (s != null && block.getEnableStats())
{
BLOCKS_STATS[i] = (new StatCrafting("stat.mineBlock.", s, new TextComponentTranslation("stat.mineBlock", new Object[] {(new ItemStack(block)).getTextComponent()}), item)).registerStat();
MINE_BLOCK_STATS.add((StatCrafting)BLOCKS_STATS[i]);
}
}
}
replaceAllSimilarBlocks(BLOCKS_STATS, false);
}
private static void initStats()
{
for (Item item : Item.REGISTRY)
{
if (item != null)
{
int i = Item.getIdFromItem(item);
String s = getItemName(item);
if (s != null)
{
OBJECT_USE_STATS[i] = (new StatCrafting("stat.useItem.", s, new TextComponentTranslation("stat.useItem", new Object[] {(new ItemStack(item)).getTextComponent()}), item)).registerStat();
if (!(item instanceof ItemBlock))
{
USE_ITEM_STATS.add((StatCrafting)OBJECT_USE_STATS[i]);
}
}
}
}
replaceAllSimilarBlocks(OBJECT_USE_STATS, true);
}
private static void initItemDepleteStats()
{
for (Item item : Item.REGISTRY)
{
if (item != null)
{
int i = Item.getIdFromItem(item);
String s = getItemName(item);
if (s != null && item.isDamageable())
{
OBJECT_BREAK_STATS[i] = (new StatCrafting("stat.breakItem.", s, new TextComponentTranslation("stat.breakItem", new Object[] {(new ItemStack(item)).getTextComponent()}), item)).registerStat();
}
}
}
replaceAllSimilarBlocks(OBJECT_BREAK_STATS, true);
}
private static void initPickedUpAndDroppedStats()
{
for (Item item : Item.REGISTRY)
{
if (item != null)
{
int i = Item.getIdFromItem(item);
String s = getItemName(item);
if (s != null)
{
OBJECTS_PICKED_UP_STATS[i] = (new StatCrafting("stat.pickup.", s, new TextComponentTranslation("stat.pickup", new Object[] {(new ItemStack(item)).getTextComponent()}), item)).registerStat();
OBJECTS_DROPPED_STATS[i] = (new StatCrafting("stat.drop.", s, new TextComponentTranslation("stat.drop", new Object[] {(new ItemStack(item)).getTextComponent()}), item)).registerStat();
}
}
}
replaceAllSimilarBlocks(OBJECT_BREAK_STATS, true);
}
private static String getItemName(Item itemIn)
{
ResourceLocation resourcelocation = Item.REGISTRY.getNameForObject(itemIn);
return resourcelocation != null ? resourcelocation.toString().replace(':', '.') : null;
}
private static void replaceAllSimilarBlocks(StatBase[] stat, boolean useItemIds)
{
mergeStatBases(stat, Blocks.WATER, Blocks.FLOWING_WATER, useItemIds);
mergeStatBases(stat, Blocks.LAVA, Blocks.FLOWING_LAVA, useItemIds);
mergeStatBases(stat, Blocks.LIT_PUMPKIN, Blocks.PUMPKIN, useItemIds);
mergeStatBases(stat, Blocks.LIT_FURNACE, Blocks.FURNACE, useItemIds);
mergeStatBases(stat, Blocks.LIT_REDSTONE_ORE, Blocks.REDSTONE_ORE, useItemIds);
mergeStatBases(stat, Blocks.POWERED_REPEATER, Blocks.UNPOWERED_REPEATER, useItemIds);
mergeStatBases(stat, Blocks.POWERED_COMPARATOR, Blocks.UNPOWERED_COMPARATOR, useItemIds);
mergeStatBases(stat, Blocks.REDSTONE_TORCH, Blocks.UNLIT_REDSTONE_TORCH, useItemIds);
mergeStatBases(stat, Blocks.LIT_REDSTONE_LAMP, Blocks.REDSTONE_LAMP, useItemIds);
mergeStatBases(stat, Blocks.DOUBLE_STONE_SLAB, Blocks.STONE_SLAB, useItemIds);
mergeStatBases(stat, Blocks.DOUBLE_WOODEN_SLAB, Blocks.WOODEN_SLAB, useItemIds);
mergeStatBases(stat, Blocks.DOUBLE_STONE_SLAB2, Blocks.STONE_SLAB2, useItemIds);
mergeStatBases(stat, Blocks.GRASS, Blocks.DIRT, useItemIds);
mergeStatBases(stat, Blocks.FARMLAND, Blocks.DIRT, useItemIds);
}
private static void mergeStatBases(StatBase[] statBaseIn, Block block1, Block block2, boolean useItemIds)
{
int i;
int j;
if (useItemIds) {
i = Item.getIdFromItem(Item.getItemFromBlock(block1));
j = Item.getIdFromItem(Item.getItemFromBlock(block2));
} else {
i = Block.getIdFromBlock(block1);
j = Block.getIdFromBlock(block2);
}
if (statBaseIn[i] != null && statBaseIn[j] == null)
{
statBaseIn[j] = statBaseIn[i];
}
else
{
ALL_STATS.remove(statBaseIn[i]);
MINE_BLOCK_STATS.remove(statBaseIn[i]);
BASIC_STATS.remove(statBaseIn[i]);
statBaseIn[i] = statBaseIn[j];
}
}
public static StatBase getStatKillEntity(EntityList.EntityEggInfo eggInfo)
{
String s = EntityList.getTranslationName(eggInfo.spawnedID);
return s == null ? null : (new StatBase("stat.killEntity." + s, new TextComponentTranslation("stat.entityKill", new Object[] {new TextComponentTranslation("entity." + s + ".name", new Object[0])}))).registerStat();
}
public static StatBase getStatEntityKilledBy(EntityList.EntityEggInfo eggInfo)
{
String s = EntityList.getTranslationName(eggInfo.spawnedID);
return s == null ? null : (new StatBase("stat.entityKilledBy." + s, new TextComponentTranslation("stat.entityKilledBy", new Object[] {new TextComponentTranslation("entity." + s + ".name", new Object[0])}))).registerStat();
}
@Nullable
public static StatBase getOneShotStat(String statName)
{
return ID_TO_STAT_MAP.get(statName);
}
@Deprecated //MODDER DO NOT CALL THIS ITS JUST A EVENT CALLBACK FOR FORGE
public static void reinit()
{
ID_TO_STAT_MAP.clear();
BASIC_STATS.clear();
USE_ITEM_STATS.clear();
MINE_BLOCK_STATS.clear();
for (StatBase[] sb : new StatBase[][]{BLOCKS_STATS, CRAFTS_STATS, OBJECT_USE_STATS, OBJECT_BREAK_STATS, OBJECTS_PICKED_UP_STATS, OBJECTS_DROPPED_STATS})
{
for (int x = 0; x < sb.length; x++)
{
if (sb[x] != null)
{
ALL_STATS.remove(sb[x]);
sb[x] = null;
}
}
}
List<StatBase> unknown = Lists.newArrayList(ALL_STATS);
ALL_STATS.clear();
for (StatBase b : unknown)
b.registerStat();
initMiningStats();
initStats();
initItemDepleteStats();
initCraftableStats();
initPickedUpAndDroppedStats();
}
}

View File

@@ -0,0 +1,41 @@
package net.minecraft.stats;
import com.google.common.collect.Maps;
import java.util.Map;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.TupleIntJsonSerializable;
public class StatisticsManager
{
protected final Map<StatBase, TupleIntJsonSerializable> statsData = Maps.<StatBase, TupleIntJsonSerializable>newConcurrentMap();
public void increaseStat(EntityPlayer player, StatBase stat, int amount)
{
this.unlockAchievement(player, stat, this.readStat(stat) + amount);
}
/**
* Triggers the logging of an achievement and attempts to announce to server
*/
public void unlockAchievement(EntityPlayer playerIn, StatBase statIn, int p_150873_3_)
{
TupleIntJsonSerializable tupleintjsonserializable = this.statsData.get(statIn);
if (tupleintjsonserializable == null)
{
tupleintjsonserializable = new TupleIntJsonSerializable();
this.statsData.put(statIn, tupleintjsonserializable);
}
tupleintjsonserializable.setIntegerValue(p_150873_3_);
}
/**
* Reads the given stat and returns its value as an int.
*/
public int readStat(StatBase stat)
{
TupleIntJsonSerializable tupleintjsonserializable = this.statsData.get(stat);
return tupleintjsonserializable == null ? 0 : tupleintjsonserializable.getIntegerValue();
}
}

View File

@@ -0,0 +1,202 @@
package net.minecraft.stats;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonParser;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.play.server.SPacketStatistics;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.IJsonSerializable;
import net.minecraft.util.TupleIntJsonSerializable;
import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class StatisticsManagerServer extends StatisticsManager
{
private static final Logger LOGGER = LogManager.getLogger();
private final MinecraftServer mcServer;
private final File statsFile;
private final Set<StatBase> dirty = Sets.<StatBase>newHashSet();
private int lastStatRequest = -300;
public StatisticsManagerServer(MinecraftServer serverIn, File statsFileIn)
{
this.mcServer = serverIn;
this.statsFile = statsFileIn;
}
public void readStatFile()
{
if (this.statsFile.isFile())
{
try
{
this.statsData.clear();
this.statsData.putAll(this.parseJson(FileUtils.readFileToString(this.statsFile)));
}
catch (IOException ioexception)
{
LOGGER.error("Couldn't read statistics file {}", this.statsFile, ioexception);
}
catch (JsonParseException jsonparseexception)
{
LOGGER.error("Couldn't parse statistics file {}", this.statsFile, jsonparseexception);
}
}
}
public void saveStatFile()
{
try
{
FileUtils.writeStringToFile(this.statsFile, dumpJson(this.statsData));
}
catch (IOException ioexception)
{
LOGGER.error("Couldn't save stats", (Throwable)ioexception);
}
}
/**
* Triggers the logging of an achievement and attempts to announce to server
*/
public void unlockAchievement(EntityPlayer playerIn, StatBase statIn, int p_150873_3_)
{
super.unlockAchievement(playerIn, statIn, p_150873_3_);
this.dirty.add(statIn);
}
private Set<StatBase> getDirty()
{
Set<StatBase> set = Sets.newHashSet(this.dirty);
this.dirty.clear();
return set;
}
public Map<StatBase, TupleIntJsonSerializable> parseJson(String p_150881_1_)
{
JsonElement jsonelement = (new JsonParser()).parse(p_150881_1_);
if (!jsonelement.isJsonObject())
{
return Maps.<StatBase, TupleIntJsonSerializable>newHashMap();
}
else
{
JsonObject jsonobject = jsonelement.getAsJsonObject();
Map<StatBase, TupleIntJsonSerializable> map = Maps.<StatBase, TupleIntJsonSerializable>newHashMap();
for (Entry<String, JsonElement> entry : jsonobject.entrySet())
{
StatBase statbase = StatList.getOneShotStat(entry.getKey());
if (statbase != null)
{
TupleIntJsonSerializable tupleintjsonserializable = new TupleIntJsonSerializable();
if (((JsonElement)entry.getValue()).isJsonPrimitive() && ((JsonElement)entry.getValue()).getAsJsonPrimitive().isNumber())
{
tupleintjsonserializable.setIntegerValue(((JsonElement)entry.getValue()).getAsInt());
}
else if (((JsonElement)entry.getValue()).isJsonObject())
{
JsonObject jsonobject1 = ((JsonElement)entry.getValue()).getAsJsonObject();
if (jsonobject1.has("value") && jsonobject1.get("value").isJsonPrimitive() && jsonobject1.get("value").getAsJsonPrimitive().isNumber())
{
tupleintjsonserializable.setIntegerValue(jsonobject1.getAsJsonPrimitive("value").getAsInt());
}
if (jsonobject1.has("progress") && statbase.getSerializableClazz() != null)
{
try
{
Constructor <? extends IJsonSerializable > constructor = statbase.getSerializableClazz().getConstructor();
IJsonSerializable ijsonserializable = constructor.newInstance();
ijsonserializable.fromJson(jsonobject1.get("progress"));
tupleintjsonserializable.setJsonSerializableValue(ijsonserializable);
}
catch (Throwable throwable)
{
LOGGER.warn("Invalid statistic progress in {}", this.statsFile, throwable);
}
}
}
map.put(statbase, tupleintjsonserializable);
}
else
{
LOGGER.warn("Invalid statistic in {}: Don't know what {} is", this.statsFile, entry.getKey());
}
}
return map;
}
}
public static String dumpJson(Map<StatBase, TupleIntJsonSerializable> p_150880_0_)
{
JsonObject jsonobject = new JsonObject();
for (Entry<StatBase, TupleIntJsonSerializable> entry : p_150880_0_.entrySet())
{
if (((TupleIntJsonSerializable)entry.getValue()).getJsonSerializableValue() != null)
{
JsonObject jsonobject1 = new JsonObject();
jsonobject1.addProperty("value", Integer.valueOf(((TupleIntJsonSerializable)entry.getValue()).getIntegerValue()));
try
{
jsonobject1.add("progress", ((TupleIntJsonSerializable)entry.getValue()).getJsonSerializableValue().getSerializableElement());
}
catch (Throwable throwable)
{
LOGGER.warn("Couldn't save statistic {}: error serializing progress", ((StatBase)entry.getKey()).getStatName(), throwable);
}
jsonobject.add((entry.getKey()).statId, jsonobject1);
}
else
{
jsonobject.addProperty((entry.getKey()).statId, Integer.valueOf(((TupleIntJsonSerializable)entry.getValue()).getIntegerValue()));
}
}
return jsonobject.toString();
}
public void markAllDirty()
{
this.dirty.addAll(this.statsData.keySet());
}
public void sendStats(EntityPlayerMP player)
{
int i = this.mcServer.getTickCounter();
Map<StatBase, Integer> map = Maps.<StatBase, Integer>newHashMap();
if (i - this.lastStatRequest > 300)
{
this.lastStatRequest = i;
for (StatBase statbase : this.getDirty())
{
map.put(statbase, Integer.valueOf(this.readStat(statbase)));
}
}
player.connection.sendPacket(new SPacketStatistics(map));
}
}

View File

@@ -0,0 +1,7 @@
// Auto generated package-info by MCP
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
package net.minecraft.stats;
import mcp.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;