ID loading from the server save now works.

This commit is contained in:
Christian 2013-12-09 21:36:49 -05:00
parent eff9a3cedc
commit 4fc600010e
10 changed files with 265 additions and 318 deletions

View file

@ -5737,31 +5737,31 @@ net/minecraft/client/gui/inventory/CreativeCrafting.<init>(Lnet/minecraft/client
net/minecraft/client/gui/inventory/CreativeCrafting.func_71110_a(Lnet/minecraft/inventory/Container;Ljava/util/List;)V=|p_71110_1_,p_71110_2_
net/minecraft/client/gui/inventory/CreativeCrafting.func_71111_a(Lnet/minecraft/inventory/Container;ILnet/minecraft/item/ItemStack;)V=|p_71111_1_,p_71111_2_,p_71111_3_
net/minecraft/client/gui/inventory/CreativeCrafting.func_71112_a(Lnet/minecraft/inventory/Container;II)V=|p_71112_1_,p_71112_2_,p_71112_3_
net/minecraft/creativetab/CreativeTabs$2.<init>(ILjava/lang/String;)V=|p_i1845_1_,p_i1845_2_
net/minecraft/creativetab/CreativeTabs$2.func_151243_f()I=|
net/minecraft/creativetab/CreativeTabs$2.func_78016_d()Lnet/minecraft/item/Item;=|
net/minecraft/creativetab/CreativeTabs$10.<init>(ILjava/lang/String;)V=|p_i1842_1_,p_i1842_2_
net/minecraft/creativetab/CreativeTabs$10.func_78016_d()Lnet/minecraft/item/Item;=|
net/minecraft/creativetab/CreativeTabs$1.<init>(ILjava/lang/String;)V=|p_i1841_1_,p_i1841_2_
net/minecraft/creativetab/CreativeTabs$1.func_78016_d()Lnet/minecraft/item/Item;=|
net/minecraft/creativetab/CreativeTabs$3.<init>(ILjava/lang/String;)V=|p_i1846_1_,p_i1846_2_
net/minecraft/creativetab/CreativeTabs$3.<init>(ILjava/lang/String;)V=|p_i1845_1_,p_i1845_2_
net/minecraft/creativetab/CreativeTabs$3.func_151243_f()I=|
net/minecraft/creativetab/CreativeTabs$3.func_78016_d()Lnet/minecraft/item/Item;=|
net/minecraft/creativetab/CreativeTabs$8.<init>(ILjava/lang/String;)V=|p_i1851_1_,p_i1851_2_
net/minecraft/creativetab/CreativeTabs$8.func_78016_d()Lnet/minecraft/item/Item;=|
net/minecraft/creativetab/CreativeTabs$12.<init>(ILjava/lang/String;)V=|p_i1844_1_,p_i1844_2_
net/minecraft/creativetab/CreativeTabs$12.func_78016_d()Lnet/minecraft/item/Item;=|
net/minecraft/creativetab/CreativeTabs$11.<init>(ILjava/lang/String;)V=|p_i1843_1_,p_i1843_2_
net/minecraft/creativetab/CreativeTabs$11.<init>(ILjava/lang/String;)V=|p_i1842_1_,p_i1842_2_
net/minecraft/creativetab/CreativeTabs$11.func_78016_d()Lnet/minecraft/item/Item;=|
net/minecraft/creativetab/CreativeTabs$6.<init>(ILjava/lang/String;)V=|p_i1849_1_,p_i1849_2_
net/minecraft/creativetab/CreativeTabs$6.func_78016_d()Lnet/minecraft/item/Item;=|
net/minecraft/creativetab/CreativeTabs$4.<init>(ILjava/lang/String;)V=|p_i1847_1_,p_i1847_2_
net/minecraft/creativetab/CreativeTabs$2.<init>(ILjava/lang/String;)V=|p_i1841_1_,p_i1841_2_
net/minecraft/creativetab/CreativeTabs$2.func_78016_d()Lnet/minecraft/item/Item;=|
net/minecraft/creativetab/CreativeTabs$4.<init>(ILjava/lang/String;)V=|p_i1846_1_,p_i1846_2_
net/minecraft/creativetab/CreativeTabs$4.func_78016_d()Lnet/minecraft/item/Item;=|
net/minecraft/creativetab/CreativeTabs$7.<init>(ILjava/lang/String;)V=|p_i1850_1_,p_i1850_2_
net/minecraft/creativetab/CreativeTabs$7.func_78016_d()Lnet/minecraft/item/Item;=|
net/minecraft/creativetab/CreativeTabs$9.<init>(ILjava/lang/String;)V=|p_i1852_1_,p_i1852_2_
net/minecraft/creativetab/CreativeTabs$9.<init>(ILjava/lang/String;)V=|p_i1851_1_,p_i1851_2_
net/minecraft/creativetab/CreativeTabs$9.func_78016_d()Lnet/minecraft/item/Item;=|
net/minecraft/creativetab/CreativeTabs$5.<init>(ILjava/lang/String;)V=|p_i1848_1_,p_i1848_2_
net/minecraft/creativetab/CreativeTabs$1.<init>(ILjava/lang/String;)V=|p_i1844_1_,p_i1844_2_
net/minecraft/creativetab/CreativeTabs$1.func_78016_d()Lnet/minecraft/item/Item;=|
net/minecraft/creativetab/CreativeTabs$12.<init>(ILjava/lang/String;)V=|p_i1843_1_,p_i1843_2_
net/minecraft/creativetab/CreativeTabs$12.func_78016_d()Lnet/minecraft/item/Item;=|
net/minecraft/creativetab/CreativeTabs$7.<init>(ILjava/lang/String;)V=|p_i1849_1_,p_i1849_2_
net/minecraft/creativetab/CreativeTabs$7.func_78016_d()Lnet/minecraft/item/Item;=|
net/minecraft/creativetab/CreativeTabs$5.<init>(ILjava/lang/String;)V=|p_i1847_1_,p_i1847_2_
net/minecraft/creativetab/CreativeTabs$5.func_78016_d()Lnet/minecraft/item/Item;=|
net/minecraft/creativetab/CreativeTabs$8.<init>(ILjava/lang/String;)V=|p_i1850_1_,p_i1850_2_
net/minecraft/creativetab/CreativeTabs$8.func_78016_d()Lnet/minecraft/item/Item;=|
net/minecraft/creativetab/CreativeTabs$10.<init>(ILjava/lang/String;)V=|p_i1852_1_,p_i1852_2_
net/minecraft/creativetab/CreativeTabs$10.func_78016_d()Lnet/minecraft/item/Item;=|
net/minecraft/creativetab/CreativeTabs$6.<init>(ILjava/lang/String;)V=|p_i1848_1_,p_i1848_2_
net/minecraft/creativetab/CreativeTabs$6.func_78016_d()Lnet/minecraft/item/Item;=|
net/minecraft/creativetab/CreativeTabs.<init>(ILjava/lang/String;)V=|p_i1853_1_,p_i1853_2_
net/minecraft/creativetab/CreativeTabs.func_111225_m()[Lnet/minecraft/enchantment/EnumEnchantmentType;=|
net/minecraft/creativetab/CreativeTabs.func_111226_a(Lnet/minecraft/enchantment/EnumEnchantmentType;)Z=|p_111226_1_

View file

@ -13,18 +13,18 @@ CL: aac net/minecraft/item/ItemCoal
CL: aad net/minecraft/item/ItemColored
CL: aae net/minecraft/item/ItemMapBase
CL: aaf net/minecraft/creativetab/CreativeTabs
CL: aag net/minecraft/creativetab/CreativeTabs$1
CL: aah net/minecraft/creativetab/CreativeTabs$10
CL: aai net/minecraft/creativetab/CreativeTabs$11
CL: aaj net/minecraft/creativetab/CreativeTabs$12
CL: aak net/minecraft/creativetab/CreativeTabs$2
CL: aal net/minecraft/creativetab/CreativeTabs$3
CL: aam net/minecraft/creativetab/CreativeTabs$4
CL: aan net/minecraft/creativetab/CreativeTabs$5
CL: aao net/minecraft/creativetab/CreativeTabs$6
CL: aap net/minecraft/creativetab/CreativeTabs$7
CL: aaq net/minecraft/creativetab/CreativeTabs$8
CL: aar net/minecraft/creativetab/CreativeTabs$9
CL: aag net/minecraft/creativetab/CreativeTabs$2
CL: aah net/minecraft/creativetab/CreativeTabs$11
CL: aai net/minecraft/creativetab/CreativeTabs$12
CL: aaj net/minecraft/creativetab/CreativeTabs$1
CL: aak net/minecraft/creativetab/CreativeTabs$3
CL: aal net/minecraft/creativetab/CreativeTabs$4
CL: aam net/minecraft/creativetab/CreativeTabs$5
CL: aan net/minecraft/creativetab/CreativeTabs$6
CL: aao net/minecraft/creativetab/CreativeTabs$7
CL: aap net/minecraft/creativetab/CreativeTabs$8
CL: aaq net/minecraft/creativetab/CreativeTabs$9
CL: aar net/minecraft/creativetab/CreativeTabs$10
CL: aas net/minecraft/item/ItemTool
CL: aat net/minecraft/item/ItemDoor
CL: aau net/minecraft/item/ItemDoublePlant
@ -8648,19 +8648,19 @@ MD: aaf/k ()Laaf; net/minecraft/creativetab/CreativeTabs/func_78022_j ()Lnet/min
MD: aaf/l ()I net/minecraft/creativetab/CreativeTabs/func_78020_k ()I #C
MD: aaf/m ()Z net/minecraft/creativetab/CreativeTabs/func_78023_l ()Z #C
MD: aaf/n ()[Laeg; net/minecraft/creativetab/CreativeTabs/func_111225_m ()[Lnet/minecraft/enchantment/EnumEnchantmentType; #C
MD: aag/e ()Labn; net/minecraft/creativetab/CreativeTabs$1/func_78016_d ()Lnet/minecraft/item/Item; #C
MD: aah/e ()Labn; net/minecraft/creativetab/CreativeTabs$10/func_78016_d ()Lnet/minecraft/item/Item; #C
MD: aai/e ()Labn; net/minecraft/creativetab/CreativeTabs$11/func_78016_d ()Lnet/minecraft/item/Item; #C
MD: aaj/e ()Labn; net/minecraft/creativetab/CreativeTabs$12/func_78016_d ()Lnet/minecraft/item/Item; #C
MD: aak/e ()Labn; net/minecraft/creativetab/CreativeTabs$2/func_78016_d ()Lnet/minecraft/item/Item; #C
MD: aak/f ()I net/minecraft/creativetab/CreativeTabs$2/func_151243_f ()I #C
MD: aal/e ()Labn; net/minecraft/creativetab/CreativeTabs$3/func_78016_d ()Lnet/minecraft/item/Item; #C
MD: aam/e ()Labn; net/minecraft/creativetab/CreativeTabs$4/func_78016_d ()Lnet/minecraft/item/Item; #C
MD: aan/e ()Labn; net/minecraft/creativetab/CreativeTabs$5/func_78016_d ()Lnet/minecraft/item/Item; #C
MD: aao/e ()Labn; net/minecraft/creativetab/CreativeTabs$6/func_78016_d ()Lnet/minecraft/item/Item; #C
MD: aap/e ()Labn; net/minecraft/creativetab/CreativeTabs$7/func_78016_d ()Lnet/minecraft/item/Item; #C
MD: aaq/e ()Labn; net/minecraft/creativetab/CreativeTabs$8/func_78016_d ()Lnet/minecraft/item/Item; #C
MD: aar/e ()Labn; net/minecraft/creativetab/CreativeTabs$9/func_78016_d ()Lnet/minecraft/item/Item; #C
MD: aag/e ()Labn; net/minecraft/creativetab/CreativeTabs$2/func_78016_d ()Lnet/minecraft/item/Item; #C
MD: aah/e ()Labn; net/minecraft/creativetab/CreativeTabs$11/func_78016_d ()Lnet/minecraft/item/Item; #C
MD: aai/e ()Labn; net/minecraft/creativetab/CreativeTabs$12/func_78016_d ()Lnet/minecraft/item/Item; #C
MD: aaj/e ()Labn; net/minecraft/creativetab/CreativeTabs$1/func_78016_d ()Lnet/minecraft/item/Item; #C
MD: aak/e ()Labn; net/minecraft/creativetab/CreativeTabs$3/func_78016_d ()Lnet/minecraft/item/Item; #C
MD: aak/f ()I net/minecraft/creativetab/CreativeTabs$4/func_151243_f ()I #C
MD: aal/e ()Labn; net/minecraft/creativetab/CreativeTabs$4/func_78016_d ()Lnet/minecraft/item/Item; #C
MD: aam/e ()Labn; net/minecraft/creativetab/CreativeTabs$5/func_78016_d ()Lnet/minecraft/item/Item; #C
MD: aan/e ()Labn; net/minecraft/creativetab/CreativeTabs$6/func_78016_d ()Lnet/minecraft/item/Item; #C
MD: aao/e ()Labn; net/minecraft/creativetab/CreativeTabs$7/func_78016_d ()Lnet/minecraft/item/Item; #C
MD: aap/e ()Labn; net/minecraft/creativetab/CreativeTabs$8/func_78016_d ()Lnet/minecraft/item/Item; #C
MD: aaq/e ()Labn; net/minecraft/creativetab/CreativeTabs$9/func_78016_d ()Lnet/minecraft/item/Item; #C
MD: aar/e ()Labn; net/minecraft/creativetab/CreativeTabs$10/func_78016_d ()Lnet/minecraft/item/Item; #C
MD: aas/a (Labp;Labp;)Z net/minecraft/item/ItemTool/func_82789_a (Lnet/minecraft/item/ItemStack;Lnet/minecraft/item/ItemStack;)Z
MD: aas/a (Labp;Lafn;Lahu;IIILrh;)Z net/minecraft/item/ItemTool/func_150894_a (Lnet/minecraft/item/ItemStack;Lnet/minecraft/world/World;Lnet/minecraft/block/Block;IIILnet/minecraft/entity/EntityLivingBase;)Z
MD: aas/a (Labp;Lahu;)F net/minecraft/item/ItemTool/func_150893_a (Lnet/minecraft/item/ItemStack;Lnet/minecraft/block/Block;)F

View file

@ -25,6 +25,11 @@ public class FMLFolderResourcePack extends FolderResourcePack {
this.container = container;
}
@Override
protected boolean func_110593_b(String p_110593_1_)
{
return super.func_110593_b(p_110593_1_);
}
@Override
public String func_130077_b()
{

View file

@ -25,6 +25,7 @@ import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.storage.SaveHandler;
import net.minecraft.world.storage.WorldInfo;
import com.google.common.collect.Maps;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
@ -93,8 +94,16 @@ public class FMLContainer extends DummyModContainer implements WorldAccessContai
list.func_74742_a(mod);
}
fmlData.func_74782_a("ModList", list);
NBTTagCompound nbt = GameData.buildItemDataList();
fmlData.func_74782_a("ModItemData", itemList);
NBTTagList dataList = new NBTTagList();
Map<String,Integer> itemList = GameData.buildItemDataList();
for (Entry<String, Integer> item : itemList.entrySet())
{
NBTTagCompound tag = new NBTTagCompound();
tag.func_74778_a("K",item.getKey());
tag.func_74768_a("V",item.getValue());
dataList.func_74742_a(tag);
}
fmlData.func_74782_a("ItemData", dataList);
return fmlData;
}
@ -127,9 +136,16 @@ public class FMLContainer extends DummyModContainer implements WorldAccessContai
// Set<ItemData> worldSaveItems = GameData.buildWorldItemData(modList);
// GameData.validateWorldSave(worldSaveItems);
}
else
else if (tag.func_74764_b("ItemData"))
{
GameData.validateWorldSave(null);
NBTTagList list = tag.func_150295_c("ItemData", (byte)10);
Map<String,Integer> dataList = Maps.newLinkedHashMap();
for (int i = 0; i < list.func_74745_c(); i++)
{
NBTTagCompound dataTag = list.func_150305_b(i);
dataList.put(dataTag.func_74779_i("K"), dataTag.func_74762_e("V"));
}
GameData.injectWorldIDMap(dataList);
}
}

View file

@ -41,7 +41,6 @@ import com.google.common.collect.Multisets;
import com.google.common.collect.Ordering;
import com.google.common.collect.SetMultimap;
import com.google.common.collect.Sets;
import com.google.common.collect.Sets.SetView;
import com.google.common.collect.TreeMultimap;
import cpw.mods.fml.common.LoaderState.ModState;
@ -450,6 +449,7 @@ public class Loader
{
initializeLoader();
mods = Lists.newArrayList();
GameData.fixupRegistries();
namedMods = Maps.newHashMap();
modController = new LoadController(this);
modController.transition(LoaderState.LOADING, false);
@ -493,7 +493,6 @@ public class Loader
modController.transition(LoaderState.PREINITIALIZATION, false);
modController.distributeStateMessage(LoaderState.PREINITIALIZATION, disc.getASMTable(), canonicalConfigDir);
modController.transition(LoaderState.INITIALIZATION, false);
GameData.validateRegistry();
}
private void disableRequestedMods()
@ -670,8 +669,6 @@ public class Loader
// Mod controller should be in the initialization state here
modController.distributeStateMessage(LoaderState.INITIALIZATION);
modController.transition(LoaderState.POSTINITIALIZATION, false);
// Construct the "mod object table" so mods can refer to it in IMC and postinit
GameData.buildModObjectTable();
modController.distributeStateMessage(FMLInterModComms.IMCEvent.class);
modController.distributeStateMessage(LoaderState.POSTINITIALIZATION);
modController.transition(LoaderState.AVAILABLE, false);

View file

@ -14,6 +14,7 @@ package cpw.mods.fml.common.discovery;
import java.io.File;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.logging.Level;
import java.util.regex.Matcher;
@ -85,7 +86,13 @@ public class ModDiscoverer
{
File[] modList = modsDir.listFiles();
// Sort the files into alphabetical order first
Arrays.sort(modList);
Arrays.sort(modList, new Comparator<File>() {
@Override
public int compare(File o1, File o2)
{
return o1.getName().compareToIgnoreCase(o2.getName());
}
});
for (File modFile : modList)
{

View file

@ -4,22 +4,23 @@ import gnu.trove.map.hash.TIntIntHashMap;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.google.common.collect.MapDifference;
import com.google.common.collect.Maps;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.ModContainer;
import net.minecraft.util.ObjectIntIdentityMap;
import net.minecraft.util.RegistryNamespaced;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.google.common.collect.Maps;
import com.google.common.primitives.Ints;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.ModContainer;
public class FMLControlledNamespacedRegistry<I> extends RegistryNamespaced {
public class FMLObjectIntIdentityMap extends ObjectIntIdentityMap {
static class FMLObjectIntIdentityMap extends ObjectIntIdentityMap {
private TIntIntHashMap oldMap;
private TIntIntHashMap newMap;
private ArrayList<Integer> oldIndex;
@ -69,6 +70,11 @@ public class FMLControlledNamespacedRegistry<I> extends RegistryNamespaced {
field_148749_a = oldMap;
field_148748_b = oldIndex;
}
List<Integer> usedIds()
{
return Ints.asList(field_148749_a.keys());
}
}
private final Class<I> superType;
@ -76,13 +82,16 @@ public class FMLControlledNamespacedRegistry<I> extends RegistryNamespaced {
private I optionalDefaultObject;
private BiMap<String,Integer> namedIds = HashBiMap.create();
private Map<String,Integer> transactionalNamedIds;
private BitSet availabilityMap;
private int maxId;
private int minId;
private char discriminator;
public FMLControlledNamespacedRegistry(String optionalDefault, int maxIdValue, int minIdValue, Class<I> type)
public FMLControlledNamespacedRegistry(String optionalDefault, int maxIdValue, int minIdValue, Class<I> type, char discriminator)
{
this.superType = type;
this.discriminator = discriminator;
this.optionalDefaultName = optionalDefault;
this.availabilityMap = new BitSet(maxIdValue);
this.maxId = maxIdValue;
@ -96,7 +105,7 @@ public class FMLControlledNamespacedRegistry<I> extends RegistryNamespaced {
add(id, name, superType.cast(thing));
}
public void add(int id, String name, I thing)
public int add(int id, String name, I thing)
{
if (name.equals(optionalDefaultName))
{
@ -104,7 +113,7 @@ public class FMLControlledNamespacedRegistry<I> extends RegistryNamespaced {
}
int idToUse = id;
if (availabilityMap.get(id))
if (id == 0 || availabilityMap.get(id))
{
idToUse = availabilityMap.nextClearBit(minId);
}
@ -112,12 +121,17 @@ public class FMLControlledNamespacedRegistry<I> extends RegistryNamespaced {
{
throw new RuntimeException(String.format("Invalid id %s - not accepted",id));
}
namedIds.put(name,idToUse);
ModContainer mc = Loader.instance().activeModContainer();
if (mc != null)
{
String prefix = mc.getModId();
name = prefix + ":"+ name;
}
namedIds.put(func_148755_c(name),idToUse);
super.func_148756_a(idToUse, name, thing);
useSlot(idToUse);
return idToUse;
}
@Override
@ -135,29 +149,36 @@ public class FMLControlledNamespacedRegistry<I> extends RegistryNamespaced {
}
void injectIdMapping(BiMap<String,Integer> values)
private FMLObjectIntIdentityMap idMap()
{
MapDifference<String, Integer> difference = Maps.difference(values, namedIds);
for (Entry<String, Integer> missing : difference.entriesOnlyOnLeft().entrySet())
{
String name = missing.getKey();
Integer id = missing.getValue();
String[] parts = name.split(":");
ModContainer modContainer = GameData.findModOwner(parts[0]);
}
@SuppressWarnings("unchecked")
BiMap<String,Object> nameMap = (BiMap<String,Object>) field_82596_a;
FMLObjectIntIdentityMap idMap = (FMLObjectIntIdentityMap) field_148759_a;
idMap.beginSwap();
for (Entry<String, Integer> entry : values.entrySet())
{
String name = entry.getKey();
Integer id = entry.getValue();
Object item = nameMap.get(name);
idMap.putNew(id, item);
return (FMLObjectIntIdentityMap) field_148759_a;
}
idMap.completeSwap();
@SuppressWarnings("unchecked")
private BiMap<String,I> nameMap()
{
return (BiMap<String,I>) field_82596_a;
}
void beginIdSwap()
{
idMap().beginSwap();
transactionalNamedIds = Maps.newHashMap();
}
void reassignMapping(String name, int newId)
{
Object item = nameMap().get(name);
idMap().putNew(newId, item);
transactionalNamedIds.put(name,newId);
}
void completeIdSwap()
{
idMap().completeSwap();
namedIds.clear();
namedIds.putAll(transactionalNamedIds);
transactionalNamedIds = null;
}
public I get(int id)
@ -174,11 +195,33 @@ public class FMLControlledNamespacedRegistry<I> extends RegistryNamespaced {
{
return func_148757_b(thing);
}
public void serializeInto(Map<String, Integer> idMapping)
{
for (Entry<String, Integer> id: namedIds.entrySet())
{
idMapping.put(id.getKey(), id.getValue());
idMapping.put(discriminator+id.getKey(), id.getValue());
}
}
public void useSlot(int id)
{
if (id >= maxId) return;
availabilityMap.set(id);
}
List<Integer> usedIds()
{
return ((FMLObjectIntIdentityMap)field_148759_a).usedIds();
}
public int getId(String itemName)
{
return namedIds.get(itemName);
}
public boolean contains(String itemName)
{
return namedIds.containsKey(itemName);
}
}

View file

@ -13,147 +13,39 @@
package cpw.mods.fml.common.registry;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Map;
import java.util.Properties;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.logging.Level;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import com.google.common.base.Charsets;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Joiner.MapJoiner;
import com.google.common.base.Throwables;
import com.google.common.collect.HashBasedTable;
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableTable;
import com.google.common.collect.ImmutableTable.Builder;
import com.google.common.collect.MapDifference;
import com.google.common.collect.MapDifference.ValueDifference;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.common.collect.Table;
import com.google.common.collect.Table.Cell;
import com.google.common.collect.Tables;
import com.google.common.io.Files;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.LoaderState;
import cpw.mods.fml.common.ModContainer;
import cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier;
public class GameData {
private static Table<String, String, ItemStack> customItemStacks = HashBasedTable.create();
private static boolean validated;
public static final FMLControlledNamespacedRegistry<Block> blockRegistry = new FMLControlledNamespacedRegistry<Block>("air", 4095, 0, Block.class);
public static final FMLControlledNamespacedRegistry<Item> itemRegistry = new FMLControlledNamespacedRegistry<Item>(null, 32000, 4096, Item.class);
public static void newItemAdded(Item item)
{
ModContainer mc = Loader.instance().activeModContainer();
if (mc == null)
{
mc = Loader.instance().getMinecraftModContainer();
if (Loader.instance().hasReachedState(LoaderState.INITIALIZATION) || validated)
{
FMLLog.severe("It appears something has tried to allocate an Item or Block outside of the preinitialization phase for mods. This will NOT work in 1.7 and beyond!");
}
}
String itemType = item.getClass().getName();
ItemData itemData = new ItemData(item, mc);
if (idMap.containsKey(item.field_77779_bT))
{
ItemData id = idMap.get(item.field_77779_bT);
FMLLog.log("fml.ItemTracker", Level.INFO, "The mod %s is overwriting existing item at %d (%s from %s) with %s", mc.getModId(), id.getItemId(), id.getItemType(), id.getModId(), itemType);
}
idMap.put(item.field_77779_bT, itemData);
if (!"Minecraft".equals(mc.getModId()))
{
FMLLog.log("fml.ItemTracker",Level.FINE, "Adding item %s(%d) owned by %s", item.getClass().getName(), item.field_77779_bT, mc.getModId());
}
}
public static void validateWorldSave(Set<ItemData> worldSaveItems)
{
isSaveValid = true;
shouldContinue = true;
// allow ourselves to continue if there's no saved data
if (worldSaveItems == null)
{
serverValidationLatch.countDown();
try
{
clientValidationLatch.await();
}
catch (InterruptedException e)
{
}
return;
}
Function<? super ItemData, Integer> idMapFunction = new Function<ItemData, Integer>() {
public Integer apply(ItemData input) {
return input.getItemId();
};
};
Map<Integer,ItemData> worldMap = Maps.uniqueIndex(worldSaveItems,idMapFunction);
difference = Maps.difference(worldMap, idMap);
FMLLog.log("fml.ItemTracker", Level.FINE, "The difference set is %s", difference);
if (!difference.entriesDiffering().isEmpty() || !difference.entriesOnlyOnLeft().isEmpty())
{
FMLLog.log("fml.ItemTracker", Level.SEVERE, "FML has detected item discrepancies");
FMLLog.log("fml.ItemTracker", Level.SEVERE, "Missing items : %s", difference.entriesOnlyOnLeft());
FMLLog.log("fml.ItemTracker", Level.SEVERE, "Mismatched items : %s", difference.entriesDiffering());
boolean foundNonIgnored = false;
for (ItemData diff : difference.entriesOnlyOnLeft().values())
{
if (!isModIgnoredForIdValidation(diff.getModId()))
{
foundNonIgnored = true;
}
}
for (ValueDifference<ItemData> diff : difference.entriesDiffering().values())
{
if (! ( isModIgnoredForIdValidation(diff.leftValue().getModId()) || isModIgnoredForIdValidation(diff.rightValue().getModId()) ) )
{
foundNonIgnored = true;
}
}
if (!foundNonIgnored)
{
FMLLog.log("fml.ItemTracker", Level.SEVERE, "FML is ignoring these ID discrepancies because of configuration. YOUR GAME WILL NOW PROBABLY CRASH. HOPEFULLY YOU WON'T HAVE CORRUPTED YOUR WORLD. BLAME %s", ignoredMods.keySet());
}
isSaveValid = !foundNonIgnored;
serverValidationLatch.countDown();
}
else
{
isSaveValid = true;
serverValidationLatch.countDown();
}
try
{
clientValidationLatch.await();
if (!shouldContinue)
{
throw new RuntimeException("This server instance is going to stop abnormally because of a fatal ID mismatch");
}
}
catch (InterruptedException e)
{
}
}
public static final FMLControlledNamespacedRegistry<Block> blockRegistry = new FMLControlledNamespacedRegistry<Block>("air", 4095, 0, Block.class,'\u0001');
public static final FMLControlledNamespacedRegistry<Item> itemRegistry = new FMLControlledNamespacedRegistry<Item>(null, 32000, 4096, Item.class,'\u0002');
public static Map<String,Integer> buildItemDataList()
{
@ -266,52 +158,49 @@ public class GameData {
return ui;
}
public static void validateRegistry()
{
/* for (int i = 0; i < Item.field_77698_e.length; i++)
{
if (Item.field_77698_e[i] != null)
{
ItemData itemData = idMap.get(i);
if (itemData == null)
{
FMLLog.severe("Found completely unknown item of class %s with ID %d, this will NOT work for a 1.7 upgrade", Item.field_77698_e[i].getClass().getName(), i);
}
else if (!itemData.isOveridden() && !"Minecraft".equals(itemData.getModId()))
{
FMLLog.severe("Found anonymous item of class %s with ID %d owned by mod %s, this item will NOT survive a 1.7 upgrade!", Item.field_77698_e[i].getClass().getName(), i, itemData.getModId());
}
}
}
*/ validated = true;
}
private static Map<UniqueIdentifier, ModContainer> customOwners = Maps.newHashMap();
static Block registerBlockAndItem(Item item, Block block, String name, String modId)
static void registerBlockAndItem(ItemBlock item, Block block, String name, String modId)
{
ModContainer mc = Loader.instance().activeModContainer();
if (modId != null)
{
customOwners.put(new UniqueIdentifier(modId, name), mc);
}
int blockId = blockRegistry.add(0, name, block);
int itemId = itemRegistry.add(blockId, name, item);
if (itemId != blockId)
{
throw new RuntimeException();
}
}
static Item registerItem(Item item, String name, String modId)
static void registerItem(Item item, String name, String modId)
{
ModContainer mc = Loader.instance().activeModContainer();
if (modId != null)
{
customOwners.put(new UniqueIdentifier(modId, name), mc);
}
itemRegistry.add(0, name, item);
int itemId = itemRegistry.getId(item);
blockRegistry.clearItem(itemId);
return item;
if (item instanceof ItemBlock)
{
throw new RuntimeException("Cannot register an itemblock separately from it's block");
}
static Block registerBlock(Block block, String name, String modId)
int itemId = itemRegistry.add(0, name, item);
blockRegistry.useSlot(itemId);
}
static void registerBlock(Block block, String name, String modId)
{
ModContainer mc = Loader.instance().activeModContainer();
if (modId != null)
{
customOwners.put(new UniqueIdentifier(modId, name), mc);
}
blockRegistry.func_148756_a(0, name, block);
return block;
int blockId = blockRegistry.add(0, name, block);
itemRegistry.useSlot(blockId);
}
public static ModContainer findModOwner(String string)
{
UniqueIdentifier ui = new UniqueIdentifier(string);
@ -321,4 +210,58 @@ public class GameData {
}
return Loader.instance().getIndexedModList().get(ui.modId);
}
public static void fixupRegistries()
{
for (Integer id : blockRegistry.usedIds())
{
itemRegistry.useSlot(id);
}
for (Integer id : itemRegistry.usedIds())
{
blockRegistry.useSlot(id);
}
}
public static void injectWorldIDMap(Map<String, Integer> dataList)
{
blockRegistry.beginIdSwap();
itemRegistry.beginIdSwap();
for (Entry<String, Integer> entry : dataList.entrySet())
{
String itemName = entry.getKey();
char discriminator = itemName.charAt(0);
itemName = itemName.substring(1);
Integer newId = entry.getValue();
int currId;
boolean isBlock = discriminator == '\u0001';
if (isBlock)
{
currId = blockRegistry.getId(itemName);
}
else
{
currId = itemRegistry.getId(itemName);
}
if (currId != newId)
{
FMLLog.info("Found %s id mismatch %s : %d %d", isBlock ? "block" : "item", itemName, currId, newId);
}
if (isBlock)
{
blockRegistry.reassignMapping(itemName, newId);
}
else
{
itemRegistry.reassignMapping(itemName, newId);
}
}
blockRegistry.completeIdSwap();
itemRegistry.completeIdSwap();
}
}

View file

@ -31,26 +31,20 @@ import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraft.world.WorldType;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraft.world.chunk.IChunkProvider;
import com.google.common.base.Objects;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.ICraftingHandler;
import cpw.mods.fml.common.IFuelHandler;
import cpw.mods.fml.common.IPickupNotifier;
import cpw.mods.fml.common.IPlayerTracker;
import cpw.mods.fml.common.IWorldGenerator;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.LoaderException;
import cpw.mods.fml.common.LoaderState;
import cpw.mods.fml.common.ModContainer;
import cpw.mods.fml.common.ObfuscationReflectionHelper;
public class GameRegistry
@ -115,7 +109,8 @@ public class GameRegistry
*/
public static Item registerItem(Item item, String name, String modId)
{
return GameData.registerItem(item, name, modId);
GameData.registerItem(item, name, modId);
return item;
}
/**
@ -130,7 +125,7 @@ public class GameRegistry
/**
* Register a block with the world, with the specified item class and block name
* @param block The block to register
* @param itemclass The item type to register with it
* @param itemclass The item type to register with it : null registers a block without associated item.
* @param name The mod-unique name to register it with
*/
public static Block registerBlock(Block block, Class<? extends ItemBlock> itemclass, String name)
@ -140,7 +135,7 @@ public class GameRegistry
/**
* Register a block with the world, with the specified item class, block name and owning modId
* @param block The block to register
* @param itemclass The iterm type to register with it
* @param itemclass The item type to register with it : null registers a block without associated item.
* @param name The mod-unique name to register it with
* @param modId The modId that will own the block name. null defaults to the active modId
*/
@ -153,11 +148,20 @@ public class GameRegistry
try
{
assert block != null : "registerBlock: block cannot be null";
assert itemclass != null : "registerBlock: itemclass cannot be null";
ItemBlock i = null;
if (itemclass != null)
{
Constructor<? extends ItemBlock> itemCtor = itemclass.getConstructor(Block.class);
Item i = itemCtor.newInstance(block);
i = itemCtor.newInstance(block);
}
if (i != null)
{
GameData.registerBlockAndItem(i, block, name, modId);
}
else
{
GameData.registerBlock(block, name, modId);
GameRegistry.registerItem(i, name, modId);
}
return block;
}
catch (Exception e)
@ -224,16 +228,6 @@ public class GameRegistry
}
}
public static void addBiome(BiomeGenBase biome)
{
WorldType.field_77137_b.addNewBiome(biome);
}
public static void removeBiome(BiomeGenBase biome)
{
WorldType.field_77137_b.removeBiome(biome);
}
public static void registerFuelHandler(IFuelHandler handler)
{
fuelHandlers.add(handler);
@ -282,65 +276,6 @@ public class GameRegistry
}
}
public static void registerPlayerTracker(IPlayerTracker tracker)
{
playerTrackers.add(tracker);
}
public static void onPlayerLogin(EntityPlayer player)
{
for (IPlayerTracker tracker : playerTrackers)
try
{
tracker.onPlayerLogin(player);
}
catch (Exception e)
{
FMLLog.log(Level.SEVERE, e, "A critical error occured handling the onPlayerLogin event with player tracker %s", tracker.getClass().getName());
}
}
public static void onPlayerLogout(EntityPlayer player)
{
for (IPlayerTracker tracker : playerTrackers)
try
{
tracker.onPlayerLogout(player);
}
catch (Exception e)
{
FMLLog.log(Level.SEVERE, e, "A critical error occured handling the onPlayerLogout event with player tracker %s", tracker.getClass().getName());
}
}
public static void onPlayerChangedDimension(EntityPlayer player)
{
for (IPlayerTracker tracker : playerTrackers)
try
{
tracker.onPlayerChangedDimension(player);
}
catch (Exception e)
{
FMLLog.log(Level.SEVERE, e, "A critical error occured handling the onPlayerChangedDimension event with player tracker %s", tracker.getClass()
.getName());
}
}
public static void onPlayerRespawn(EntityPlayer player)
{
for (IPlayerTracker tracker : playerTrackers)
try
{
tracker.onPlayerRespawn(player);
}
catch (Exception e)
{
FMLLog.log(Level.SEVERE, e, "A critical error occured handling the onPlayerRespawn event with player tracker %s", tracker.getClass().getName());
}
}
/**
* Look up a mod block in the global "named item list"
* @param modId The modid owning the block

View file

@ -65,8 +65,8 @@ public net.minecraft.entity.player.EntityPlayerMP.field_71139_cq
## StructureStart
#public aiv.a #FD:StructureStart/field_75075_a
## EntityVillager - minmax lists
public net.minecraft.entity.passive.EntityVillager.func_146091_a(Lnet.minecraft.village.MerchantRecipeList;Lnet.minecraft.item.Item;Ljava/util/Random;F)V # buy
public net.minecraft.entity.passive.EntityVillager.func_146089_b(Lnet.minecraft.village.MerchantRecipeList;Lnet.minecraft.item.Item;Ljava/util/Random;F)V # sell
public net.minecraft.entity.passive.EntityVillager.func_146091_a(Lnet/minecraft/village/MerchantRecipeList;Lnet/minecraft/item/Item;Ljava/util/Random;F)V # buy
public net.minecraft.entity.passive.EntityVillager.func_146089_b(Lnet/minecraft/village/MerchantRecipeList;Lnet/minecraft/item/Item;Ljava/util/Random;F)V # sell
public net.minecraft.entity.passive.EntityVillager.field_70958_bB
public net.minecraft.entity.passive.EntityVillager.field_70960_bC
## GuiButtonMerchant
@ -78,3 +78,4 @@ public net.minecraft.client.Minecraft.field_71446_o # textureManager
protected net.minecraft.util.ObjectIntIdentityMap.field_148749_a # internal map
protected net.minecraft.util.ObjectIntIdentityMap.field_148748_b # internal index list
protected-f net.minecraft.util.RegistryNamespaced.field_148759_a # identitymap
protected net.minecraft.util.RegistryNamespaced.func_148755_c(Ljava/lang/String;)Ljava/lang/String; # prefix if necessary