GameRegistry.java 文件源码

java
阅读 25 收藏 0 点赞 0 评论 0

项目:TRHS_Club_Mod_2016 作者:
/**
 * Makes an {@link ItemStack} based on the itemName reference, with supplied meta, stackSize and nbt, if possible
 *
 * Will return null if the item doesn't exist (because it's not from a loaded mod for example)
 * Will throw a {@link RuntimeException} if the nbtString is invalid for use in an {@link ItemStack}
 *
 * @param itemName a registry name reference
 * @param meta the meta
 * @param stackSize the stack size
 * @param nbtString an nbt stack as a string, will be processed by {@link JsonToNBT}
 * @return a new itemstack
 */
public static ItemStack makeItemStack(String itemName, int meta, int stackSize, String nbtString)
{
    if (itemName == null) throw new IllegalArgumentException("The itemName cannot be null");
    Item item = GameData.getItemRegistry().func_82594_a(itemName);
    if (item == null) {
        FMLLog.getLogger().log(Level.TRACE, "Unable to find item with name {}", itemName);
        return null;
    }
    ItemStack is = new ItemStack(item,1,meta);
    if (!Strings.isNullOrEmpty(nbtString)) {
        NBTBase nbttag = null;
        try
        {
            nbttag = JsonToNBT.func_150315_a(nbtString);
        } catch (NBTException e)
        {
            FMLLog.getLogger().log(Level.WARN, "Encountered an exception parsing ItemStack NBT string {}", nbtString, e);
            throw Throwables.propagate(e);
        }
        if (!(nbttag instanceof NBTTagCompound)) {
            FMLLog.getLogger().log(Level.WARN, "Unexpected NBT string - multiple values {}", nbtString);
            throw new RuntimeException("Invalid NBT JSON");
        } else {
            is.func_77982_d((NBTTagCompound) nbttag);
        }
    }
    return is;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号