Skip to content
This repository was archived by the owner on May 26, 2018. It is now read-only.

Commit 2d368c4

Browse files
committed
Itemstacks in the GameRegistry (manual registration by mods)
1 parent d9db272 commit 2d368c4

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

common/cpw/mods/fml/common/registry/GameData.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@
2525
import net.minecraft.block.Block;
2626
import net.minecraft.block.BlockSand;
2727
import net.minecraft.item.Item;
28+
import net.minecraft.item.ItemStack;
2829
import net.minecraft.nbt.NBTTagCompound;
2930
import net.minecraft.nbt.NBTTagList;
3031

3132
import com.google.common.base.Function;
3233
import com.google.common.base.Throwables;
34+
import com.google.common.collect.HashBasedTable;
3335
import com.google.common.collect.ImmutableMap;
3436
import com.google.common.collect.ImmutableTable;
3537
import com.google.common.collect.ImmutableTable.Builder;
@@ -54,6 +56,7 @@ public class GameData {
5456
private static boolean shouldContinue = true;
5557
private static boolean isSaveValid = true;
5658
private static ImmutableTable<String, String, Integer> modObjectTable;
59+
private static Table<String, String, ItemStack> customItemStacks = HashBasedTable.create();
5760
private static Map<String,String> ignoredMods;
5861

5962
private static boolean isModIgnoredForIdValidation(String modId)
@@ -299,4 +302,31 @@ static Block findBlock(String modId, String name)
299302
}
300303
return Block.field_71973_m[blockId];
301304
}
305+
306+
static ItemStack findItemStack(String modId, String name)
307+
{
308+
ItemStack is = customItemStacks.get(modId, name);
309+
if (is == null)
310+
{
311+
Item i = findItem(modId, name);
312+
if (i != null)
313+
{
314+
is = new ItemStack(i, 0 ,0);
315+
}
316+
}
317+
if (is == null)
318+
{
319+
Block b = findBlock(modId, name);
320+
if (b != null)
321+
{
322+
is = new ItemStack(b, 0, 0);
323+
}
324+
}
325+
return is;
326+
}
327+
328+
static void registerCustomItemStack(String name, ItemStack itemStack)
329+
{
330+
customItemStacks.put(Loader.instance().activeModContainer().getModId(), name, itemStack);
331+
}
302332
}

common/cpw/mods/fml/common/registry/GameRegistry.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,4 +394,27 @@ public static net.minecraft.item.Item findItem(String modId, String name)
394394
{
395395
return GameData.findItem(modId, name);
396396
}
397+
398+
/**
399+
* Manually register a custom item stack with FML for later tracking. It is automatically scoped with the active modid
400+
*
401+
* @param name The name to register it under
402+
* @param itemStack The itemstack to register
403+
*/
404+
public static void registerCustomItemStack(String name, ItemStack itemStack)
405+
{
406+
GameData.registerCustomItemStack(name, itemStack);
407+
}
408+
/**
409+
* Lookup an itemstack based on mod and name. It will create "default" itemstacks from blocks and items if no
410+
* explicit itemstack is found.
411+
*
412+
* @param modId The modid of the stack owner
413+
* @param name The name of the stack
414+
* @return The custom itemstack or null if no such itemstack was found
415+
*/
416+
public static ItemStack findItemStack(String modId, String name)
417+
{
418+
return GameData.findItemStack(modId, name);
419+
}
397420
}

0 commit comments

Comments
 (0)