From 4fc600010ebb9117f2949849dbef8f4712e54d06 Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 9 Dec 2013 21:36:49 -0500 Subject: [PATCH] ID loading from the server save now works. --- fml/conf/joined.exc | 40 ++-- fml/conf/joined.srg | 50 ++-- .../fml/client/FMLFolderResourcePack.java | 5 + .../cpw/mods/fml/common/FMLContainer.java | 24 +- .../main/java/cpw/mods/fml/common/Loader.java | 5 +- .../fml/common/discovery/ModDiscoverer.java | 9 +- .../FMLControlledNamespacedRegistry.java | 117 ++++++--- .../mods/fml/common/registry/GameData.java | 225 +++++++----------- .../fml/common/registry/GameRegistry.java | 103 ++------ fml/src/main/resources/fml_at.cfg | 5 +- 10 files changed, 265 insertions(+), 318 deletions(-) diff --git a/fml/conf/joined.exc b/fml/conf/joined.exc index 9f6f60327..108e5282f 100644 --- a/fml/conf/joined.exc +++ b/fml/conf/joined.exc @@ -5737,31 +5737,31 @@ net/minecraft/client/gui/inventory/CreativeCrafting.(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.(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.(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.(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.(ILjava/lang/String;)V=|p_i1846_1_,p_i1846_2_ +net/minecraft/creativetab/CreativeTabs$3.(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.(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.(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.(ILjava/lang/String;)V=|p_i1843_1_,p_i1843_2_ +net/minecraft/creativetab/CreativeTabs$11.(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.(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.(ILjava/lang/String;)V=|p_i1847_1_,p_i1847_2_ +net/minecraft/creativetab/CreativeTabs$2.(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.(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.(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.(ILjava/lang/String;)V=|p_i1852_1_,p_i1852_2_ +net/minecraft/creativetab/CreativeTabs$9.(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.(ILjava/lang/String;)V=|p_i1848_1_,p_i1848_2_ +net/minecraft/creativetab/CreativeTabs$1.(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.(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.(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.(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.(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.(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.(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.(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_ diff --git a/fml/conf/joined.srg b/fml/conf/joined.srg index 6505783ee..d14353f13 100644 --- a/fml/conf/joined.srg +++ b/fml/conf/joined.srg @@ -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 diff --git a/fml/src/main/java/cpw/mods/fml/client/FMLFolderResourcePack.java b/fml/src/main/java/cpw/mods/fml/client/FMLFolderResourcePack.java index 30281549f..6fed90810 100644 --- a/fml/src/main/java/cpw/mods/fml/client/FMLFolderResourcePack.java +++ b/fml/src/main/java/cpw/mods/fml/client/FMLFolderResourcePack.java @@ -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() { diff --git a/fml/src/main/java/cpw/mods/fml/common/FMLContainer.java b/fml/src/main/java/cpw/mods/fml/common/FMLContainer.java index b5eeb14c2..4a1c407d3 100644 --- a/fml/src/main/java/cpw/mods/fml/common/FMLContainer.java +++ b/fml/src/main/java/cpw/mods/fml/common/FMLContainer.java @@ -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 itemList = GameData.buildItemDataList(); + for (Entry 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 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 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); } } diff --git a/fml/src/main/java/cpw/mods/fml/common/Loader.java b/fml/src/main/java/cpw/mods/fml/common/Loader.java index 8f9e67651..780fc13b4 100644 --- a/fml/src/main/java/cpw/mods/fml/common/Loader.java +++ b/fml/src/main/java/cpw/mods/fml/common/Loader.java @@ -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); diff --git a/fml/src/main/java/cpw/mods/fml/common/discovery/ModDiscoverer.java b/fml/src/main/java/cpw/mods/fml/common/discovery/ModDiscoverer.java index 514567343..da7e87ccc 100644 --- a/fml/src/main/java/cpw/mods/fml/common/discovery/ModDiscoverer.java +++ b/fml/src/main/java/cpw/mods/fml/common/discovery/ModDiscoverer.java @@ -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() { + @Override + public int compare(File o1, File o2) + { + return o1.getName().compareToIgnoreCase(o2.getName()); + } + }); for (File modFile : modList) { diff --git a/fml/src/main/java/cpw/mods/fml/common/registry/FMLControlledNamespacedRegistry.java b/fml/src/main/java/cpw/mods/fml/common/registry/FMLControlledNamespacedRegistry.java index 1a29ecc8e..51f7c045e 100644 --- a/fml/src/main/java/cpw/mods/fml/common/registry/FMLControlledNamespacedRegistry.java +++ b/fml/src/main/java/cpw/mods/fml/common/registry/FMLControlledNamespacedRegistry.java @@ -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 extends RegistryNamespaced { - public class FMLObjectIntIdentityMap extends ObjectIntIdentityMap { + static class FMLObjectIntIdentityMap extends ObjectIntIdentityMap { private TIntIntHashMap oldMap; private TIntIntHashMap newMap; private ArrayList oldIndex; @@ -69,6 +70,11 @@ public class FMLControlledNamespacedRegistry extends RegistryNamespaced { field_148749_a = oldMap; field_148748_b = oldIndex; } + + List usedIds() + { + return Ints.asList(field_148749_a.keys()); + } } private final Class superType; @@ -76,13 +82,16 @@ public class FMLControlledNamespacedRegistry extends RegistryNamespaced { private I optionalDefaultObject; private BiMap namedIds = HashBiMap.create(); + private Map transactionalNamedIds; private BitSet availabilityMap; private int maxId; private int minId; + private char discriminator; - public FMLControlledNamespacedRegistry(String optionalDefault, int maxIdValue, int minIdValue, Class type) + public FMLControlledNamespacedRegistry(String optionalDefault, int maxIdValue, int minIdValue, Class 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 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 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 extends RegistryNamespaced { { throw new RuntimeException(String.format("Invalid id %s - not accepted",id)); } - namedIds.put(name,idToUse); ModContainer mc = Loader.instance().activeModContainer(); - String prefix = mc.getModId(); - name = prefix + ":"+ name; + 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 extends RegistryNamespaced { } - void injectIdMapping(BiMap values) + private FMLObjectIntIdentityMap idMap() { - MapDifference difference = Maps.difference(values, namedIds); - for (Entry 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 nameMap = (BiMap) field_82596_a; - FMLObjectIntIdentityMap idMap = (FMLObjectIntIdentityMap) field_148759_a; - idMap.beginSwap(); - for (Entry 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 nameMap() + { + return (BiMap) 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 extends RegistryNamespaced { { return func_148757_b(thing); } + public void serializeInto(Map idMapping) { for (Entry 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 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); + } } diff --git a/fml/src/main/java/cpw/mods/fml/common/registry/GameData.java b/fml/src/main/java/cpw/mods/fml/common/registry/GameData.java index 4d8200fd5..c378906d0 100644 --- a/fml/src/main/java/cpw/mods/fml/common/registry/GameData.java +++ b/fml/src/main/java/cpw/mods/fml/common/registry/GameData.java @@ -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 customItemStacks = HashBasedTable.create(); - private static boolean validated; - public static final FMLControlledNamespacedRegistry blockRegistry = new FMLControlledNamespacedRegistry("air", 4095, 0, Block.class); - public static final FMLControlledNamespacedRegistry itemRegistry = new FMLControlledNamespacedRegistry(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 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 idMapFunction = new Function() { - public Integer apply(ItemData input) { - return input.getItemId(); - }; - }; - - Map 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 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 blockRegistry = new FMLControlledNamespacedRegistry("air", 4095, 0, Block.class,'\u0001'); + public static final FMLControlledNamespacedRegistry itemRegistry = new FMLControlledNamespacedRegistry(null, 32000, 4096, Item.class,'\u0002'); public static Map buildItemDataList() { @@ -182,7 +74,7 @@ public class GameData { static Block findBlock(String modId, String name) { - return (Block) blockRegistry.func_82594_a(modId+":"+name); + return (Block) blockRegistry.func_82594_a(modId + ":" + name); } static ItemStack findItemStack(String modId, String name) @@ -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 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"); + } + int itemId = itemRegistry.add(0, name, item); + blockRegistry.useSlot(itemId); } - static Block registerBlock(Block block, String name, String modId) + + 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 dataList) + { + blockRegistry.beginIdSwap(); + itemRegistry.beginIdSwap(); + for (Entry 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(); + } } diff --git a/fml/src/main/java/cpw/mods/fml/common/registry/GameRegistry.java b/fml/src/main/java/cpw/mods/fml/common/registry/GameRegistry.java index 78e3cfae3..a3e889072 100644 --- a/fml/src/main/java/cpw/mods/fml/common/registry/GameRegistry.java +++ b/fml/src/main/java/cpw/mods/fml/common/registry/GameRegistry.java @@ -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 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"; - Constructor itemCtor = itemclass.getConstructor(Block.class); - Item i = itemCtor.newInstance(block); - GameData.registerBlock(block, name, modId); - GameRegistry.registerItem(i, name, modId); + ItemBlock i = null; + if (itemclass != null) + { + Constructor itemCtor = itemclass.getConstructor(Block.class); + i = itemCtor.newInstance(block); + } + if (i != null) + { + GameData.registerBlockAndItem(i, block, name, modId); + } + else + { + GameData.registerBlock(block, 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,66 +276,7 @@ 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 * @param name The name of the block itself diff --git a/fml/src/main/resources/fml_at.cfg b/fml/src/main/resources/fml_at.cfg index ebe5189c6..7db34ee87 100644 --- a/fml/src/main/resources/fml_at.cfg +++ b/fml/src/main/resources/fml_at.cfg @@ -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