Itemstacks in the GameRegistry (manual registration by mods)
This commit is contained in:
parent
1d0e8e9935
commit
db46ea94bc
2 changed files with 53 additions and 0 deletions
|
@ -25,11 +25,13 @@ import java.util.logging.Level;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockSand;
|
import net.minecraft.block.BlockSand;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.nbt.NBTTagList;
|
import net.minecraft.nbt.NBTTagList;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Throwables;
|
import com.google.common.base.Throwables;
|
||||||
|
import com.google.common.collect.HashBasedTable;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.ImmutableTable;
|
import com.google.common.collect.ImmutableTable;
|
||||||
import com.google.common.collect.ImmutableTable.Builder;
|
import com.google.common.collect.ImmutableTable.Builder;
|
||||||
|
@ -54,6 +56,7 @@ public class GameData {
|
||||||
private static boolean shouldContinue = true;
|
private static boolean shouldContinue = true;
|
||||||
private static boolean isSaveValid = true;
|
private static boolean isSaveValid = true;
|
||||||
private static ImmutableTable<String, String, Integer> modObjectTable;
|
private static ImmutableTable<String, String, Integer> modObjectTable;
|
||||||
|
private static Table<String, String, ItemStack> customItemStacks = HashBasedTable.create();
|
||||||
private static Map<String,String> ignoredMods;
|
private static Map<String,String> ignoredMods;
|
||||||
|
|
||||||
private static boolean isModIgnoredForIdValidation(String modId)
|
private static boolean isModIgnoredForIdValidation(String modId)
|
||||||
|
@ -299,4 +302,31 @@ public class GameData {
|
||||||
}
|
}
|
||||||
return Block.field_71973_m[blockId];
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -394,4 +394,27 @@ public class GameRegistry
|
||||||
{
|
{
|
||||||
return GameData.findItem(modId, name);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue