001    package cpw.mods.fml.common.registry;
002    
003    import java.util.Map;
004    
005    import com.google.common.base.Objects;
006    import com.google.common.collect.HashMultiset;
007    import com.google.common.collect.Maps;
008    import com.google.common.collect.Multiset;
009    
010    import cpw.mods.fml.common.ModContainer;
011    
012    import net.minecraft.src.Item;
013    import net.minecraft.src.NBTTagCompound;
014    
015    public class ItemData {
016    
017        private static Map<String, Multiset<String>> modOrdinals = Maps.newHashMap();
018        public final String modId;
019        public final String itemType;
020        public final int itemId;
021        public final int ordinal;
022    
023        public ItemData(Item item, ModContainer mc)
024        {
025            this.itemId = item.shiftedIndex;
026            this.itemType = item.getClass().getName();
027            this.modId = mc.getModId();
028            if (!modOrdinals.containsKey(mc.getModId()))
029            {
030                modOrdinals.put(mc.getModId(), HashMultiset.<String>create());
031            }
032            this.ordinal = modOrdinals.get(mc.getModId()).add(itemType, 1);
033        }
034    
035        public ItemData(NBTTagCompound tag)
036        {
037            this.modId = tag.getString("ModId");
038            this.itemType = tag.getString("ItemType");
039            this.itemId = tag.getInteger("ItemId");
040            this.ordinal = tag.getInteger("ordinal");
041        }
042    
043        public NBTTagCompound toNBT()
044        {
045            NBTTagCompound tag = new NBTTagCompound();
046            tag.setString("ModId", modId);
047            tag.setString("ItemType", itemType);
048            tag.setInteger("ItemId", itemId);
049            tag.setInteger("ordinal", ordinal);
050            return tag;
051        }
052    
053        @Override
054        public int hashCode()
055        {
056            return Objects.hashCode(modId, itemType, itemId, ordinal);
057        }
058    
059        @Override
060        public boolean equals(Object obj)
061        {
062            try
063            {
064                ItemData other = (ItemData) obj;
065                return Objects.equal(modId, other.modId) && Objects.equal(itemType, other.itemType) && Objects.equal(itemId, other.itemId) && Objects.equal(ordinal, other.ordinal);
066            }
067            catch (ClassCastException cce)
068            {
069                return false;
070            }
071        }
072    }