diff --git a/fml/common/cpw/mods/fml/common/registry/GameData.java b/fml/common/cpw/mods/fml/common/registry/GameData.java index 9393cb143..0eeb164d4 100644 --- a/fml/common/cpw/mods/fml/common/registry/GameData.java +++ b/fml/common/cpw/mods/fml/common/registry/GameData.java @@ -25,11 +25,13 @@ import java.util.logging.Level; import net.minecraft.block.Block; import net.minecraft.block.BlockSand; import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import com.google.common.base.Function; import com.google.common.base.Throwables; +import com.google.common.collect.HashBasedTable; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableTable; import com.google.common.collect.ImmutableTable.Builder; @@ -54,6 +56,7 @@ public class GameData { private static boolean shouldContinue = true; private static boolean isSaveValid = true; private static ImmutableTable modObjectTable; + private static Table customItemStacks = HashBasedTable.create(); private static Map ignoredMods; private static boolean isModIgnoredForIdValidation(String modId) @@ -299,4 +302,31 @@ public class GameData { } return Block.field_71973_m[blockId]; } + + static ItemStack findItemStack(String modId, String name) + { + ItemStack is = customItemStacks.get(modId, name); + if (is == null) + { + Item i = findItem(modId, name); + if (i != null) + { + is = new ItemStack(i, 0 ,0); + } + } + if (is == null) + { + Block b = findBlock(modId, name); + if (b != null) + { + is = new ItemStack(b, 0, 0); + } + } + return is; + } + + static void registerCustomItemStack(String name, ItemStack itemStack) + { + customItemStacks.put(Loader.instance().activeModContainer().getModId(), name, itemStack); + } } diff --git a/fml/common/cpw/mods/fml/common/registry/GameRegistry.java b/fml/common/cpw/mods/fml/common/registry/GameRegistry.java index c504fac29..2333cc703 100644 --- a/fml/common/cpw/mods/fml/common/registry/GameRegistry.java +++ b/fml/common/cpw/mods/fml/common/registry/GameRegistry.java @@ -394,4 +394,27 @@ public class GameRegistry { return GameData.findItem(modId, name); } + + /** + * Manually register a custom item stack with FML for later tracking. It is automatically scoped with the active modid + * + * @param name The name to register it under + * @param itemStack The itemstack to register + */ + public static void registerCustomItemStack(String name, ItemStack itemStack) + { + GameData.registerCustomItemStack(name, itemStack); + } + /** + * Lookup an itemstack based on mod and name. It will create "default" itemstacks from blocks and items if no + * explicit itemstack is found. + * + * @param modId The modid of the stack owner + * @param name The name of the stack + * @return The custom itemstack or null if no such itemstack was found + */ + public static ItemStack findItemStack(String modId, String name) + { + return GameData.findItemStack(modId, name); + } }