/// <summary> /// Custom item from a prefab with a <see cref="global::Recipe"/> made from a <see cref="ItemConfig"/>.<br /> /// Can fix references for <see cref="Entities.Mock{T}"/>s. /// </summary> /// <param name="itemPrefab">The prefab for this custom item.</param> /// <param name="fixReference">If true references for <see cref="Entities.Mock{T}"/> objects get resolved at runtime by Jötunn.</param> /// <param name="itemConfig">The recipe config for this custom item.</param> public CustomItem(GameObject itemPrefab, bool fixReference, ItemConfig itemConfig) { ItemPrefab = itemPrefab; ItemDrop = itemPrefab.GetComponent <ItemDrop>(); FixReference = fixReference; itemConfig.Item = ItemPrefab.name; Recipe = new CustomRecipe(itemConfig.GetRecipe(), true, true); }
/// <summary> /// Custom item created as an "empty" primitive with a <see cref="global::Recipe"/> made from a <see cref="ItemConfig"/>.<br /> /// At least the name and the Icon of the <see cref="global::ItemDrop"/> must be edited after creation. /// </summary> /// <param name="name">Name of the new prefab. Must be unique.</param> /// <param name="addZNetView">If true a ZNetView component will be added to the prefab for network sync.</param> /// <param name="itemConfig">The recipe config for this custom item.</param> public CustomItem(string name, bool addZNetView, ItemConfig itemConfig) { ItemPrefab = PrefabManager.Instance.CreateEmptyPrefab(name, addZNetView); if (ItemPrefab) { ItemDrop = ItemPrefab.AddComponent <ItemDrop>(); itemConfig.Item = name; Recipe = new CustomRecipe(itemConfig.GetRecipe(), true, true); } }
/// <summary> /// Custom item created as a copy of a vanilla Valheim prefab with a <see cref="global::Recipe"/> made from a <see cref="ItemConfig"/>. /// </summary> /// <param name="name">The new name of the prefab after cloning.</param> /// <param name="basePrefabName">The name of the base prefab the custom item is cloned from.</param> /// <param name="itemConfig">The recipe config for this custom item.</param> public CustomItem(string name, string basePrefabName, ItemConfig itemConfig) { ItemPrefab = PrefabManager.Instance.CreateClonedPrefab(name, basePrefabName); if (ItemPrefab) { ItemDrop = ItemPrefab.GetComponent <ItemDrop>(); itemConfig.Item = name; Recipe = new CustomRecipe(itemConfig.GetRecipe(), true, true); } }
/// <summary> /// Custom item from a prefab with a <see cref="global::Recipe"/> made from a <see cref="ItemConfig"/>.<br /> /// Can fix references for <see cref="Entities.Mock{T}"/>s. /// </summary> /// <param name="itemPrefab">The prefab for this custom item.</param> /// <param name="fixReference">If true references for <see cref="Entities.Mock{T}"/> objects get resolved at runtime by Jötunn.</param> /// <param name="itemConfig">The item config for this custom item.</param> public CustomItem(GameObject itemPrefab, bool fixReference, ItemConfig itemConfig) { ItemPrefab = itemPrefab; ItemDrop = itemPrefab.GetComponent <ItemDrop>(); FixReference = fixReference; itemConfig.Apply(ItemPrefab); FixConfig = true; var recipe = itemConfig.GetRecipe(); if (recipe != null) { Recipe = new CustomRecipe(recipe, true, true); } }
/// <summary> /// Custom item created as an "empty" primitive with a <see cref="global::Recipe"/> made from a <see cref="ItemConfig"/>. /// </summary> /// <param name="name">Name of the new prefab. Must be unique.</param> /// <param name="addZNetView">If true a ZNetView component will be added to the prefab for network sync.</param> /// <param name="itemConfig">The item config for this custom item.</param> public CustomItem(string name, bool addZNetView, ItemConfig itemConfig) { ItemPrefab = PrefabManager.Instance.CreateEmptyPrefab(name, addZNetView); ItemDrop = ItemPrefab.AddComponent <ItemDrop>(); ItemDrop.m_itemData.m_shared = new ItemDrop.ItemData.SharedData(); itemConfig.Apply(ItemPrefab); FixConfig = true; var recipe = itemConfig.GetRecipe(); if (recipe != null) { Recipe = new CustomRecipe(recipe, true, true); } }
/// <summary> /// Custom item created as a copy of a vanilla Valheim prefab with a <see cref="global::Recipe"/> made from a <see cref="ItemConfig"/>. /// </summary> /// <param name="name">The new name of the prefab after cloning.</param> /// <param name="basePrefabName">The name of the base prefab the custom item is cloned from.</param> /// <param name="itemConfig">The item config for this custom item.</param> public CustomItem(string name, string basePrefabName, ItemConfig itemConfig) { var itemPrefab = PrefabManager.Instance.CreateClonedPrefab(name, basePrefabName); if (itemPrefab) { ItemPrefab = itemPrefab; ItemDrop = itemPrefab.GetComponent <ItemDrop>(); itemConfig.Apply(itemPrefab); FixConfig = true; var recipe = itemConfig.GetRecipe(); if (recipe != null) { Recipe = new CustomRecipe(recipe, true, true); } } }