Skip to content

Items

Creating Items

To create an item, you first need to make a class overriding CustomInventoryItem.
Example:

using COTL_API.CustomInventory;
using COTL_API.Helpers;
using UnityEngine;
using System.IO;
internal class ExampleItem : CustomInventoryItem
{
public override string InternalName => "Example_Item";
public override string LocalizedName() { return "Example Item"; }
public override string LocalizedDescription() { return "This is an example item"; }
//used for inventory icons
public override Sprite InventoryIcon => TextureHelper.CreateSpriteFromPath(Path.Combine(Plugin.PluginPath, "Assets", "example_item.png"));
//used for spawning object in the world
public override Sprite Sprite => TextureHelper.CreateSpriteFromPath(Path.Combine(Plugin.PluginPath, "Assets", "example_item.png"));
}

CustomInventoryItem supports the following overrides:

TypeNameDefault
stringInternalName[REQUIRED]
SpriteInventoryIconTextureHelper.CreateSpriteFromPath(PluginPaths.ResolveAssetPath(“placeholder.png”))
SpriteSpriteTextureHelper.CreateSpriteFromPath(PluginPaths.ResolveAssetPath(“placeholder.png”))
InventoryItem.ITEM_CATEGORIESItemCategoryInventoryItem.ITEM_CATEGORIES.NONE
InventoryItem.ITEM_TYPESeedTypeInventoryItem.ITEM_TYPE.NONE;
CustomInventoryItemTypeInventoryItemTypeCustomInventoryItemType.ITEM
stringLocalizedName()LocalizationManager.GetTranslation($“Inventory/{ModPrefix}.{InternalName}“)
stringLocalizedLore()LocalizationManager.GetTranslation($“Inventory/{ModPrefix}.{InternalName}/Lore”)
stringLocalizedDescription()LocalizationManager.GetTranslation($“Inventory/{ModPrefix}.{InternalName}/Description”)
intFuelWeight1
intFoodSatitation75
boolIsFishfalse
boolIsFoodfalse
boolIsBigFishfalse
boolIsCurrencyfalse
boolIsSeedfalse
boolIsPlantablefalse
boolIsBurnableFuelfalse
boolCanBeGivenToFollowerfalse
stringGiftTitle(Follower follower)$“{Name()} ({Inventory.GetItemQuantity(ItemType)})“
FollowerCommandsGiftCommandFollowerCommands.None
voidOnGiftTo(Follower follower, System.Action onFinish)onFinish()
CustomItemManager.ItemRarityRarityCustomItemManager.ItemRarity.COMMON
Vector3LocalScalenew(0.5f, 0.5f, 0.5f)
boolAddItemToOfferingShrinefalse;
InventoryItem.ITEM_TYPEItemPickUpToImitateInventoryItem.ITEM_TYPE.LOG
boolAddItemToDungeonChestsfalse
intDungeonChestSpawnChance100
intDungeonChestMinAmount1
intDungeonChestMaxAmount1
boolCanBeRefinedfalse
InventoryItem.ITEM_TYPERefineryInputInventoryItem.ITEM_TYPE.LOG
intRefineryInputQty15
floatCustomRefineryDuration0

Helpers

TypeNamePurpose
boolCustomItemManager.DropLoot(CustomInventoryItem customInventoryItem)Used to determine if a custom item should drop or not based on the items chance configuration.

Adding Items

To add an item to the game, simply use CustomItemManager.Add().
Example:

using COTL_API.CustomInventory;
public static InventoryItem.ITEM_TYPE ExampleItem { get; private set; }
private void Awake()
{
ExampleItem = CustomItemManager.Add(new ExampleItem());
}

Assigning the result of CustomItemManager.Add() allows you to reference that item elsewhere in your code using Plugin.ExampleItem. Example usage below.

Spawning Items

To spawn an item into the world, add the neccessary overrides (see table above) and simply use InventoryItem.Spawn(Plugin.ExampleItem, 5, Position);. The properties the item will take on (such as bounce, speed etc) are determined by ItemPickUpToImitate. The sprite that is used for spawning is the same as the inventory icon.

  • Items can be added to dungeon chests.
  • You can control the chance to spawn, and the minimum/maximum amount to spawn.
  • There is a helper method to aid in determining chance, simply call CustomItemManager.DropLoot(Plugin.ExampleItem); which returns a boolean true/false.
  • Keep in mind the chance is affected by the players current LuckModifier.
  • Items can be added to offering shrines. The shrines have two pools, COMMON and RARE. The default for custom items is COMMON.

Refinery

Custom items can be added to the refinery as a refinable resource. Simply follow the steps below:

  • Override the refinery fields.
  • CanBeRefined needs to be set to true. The default is false.
  • RefineryInput is the item/materials required.
  • RefineryInputQty is how many of the above items are required.

The default time used by the refinery is 128f, with that then being modified based on the followers attributes.

  • CustomRefineryDuration is optional. Leaving it at 0 or not overriding is off, anything greater than 0 becomes the time to refine.

Final Steps

For the icon to load, you need to put it in the appropriate location. For the example, this would be /Assets/example_item.png relative to the root folder containing the .dll
Directory structure:

📂plugins
┣📂Assets
┃ ┗🖼️example_item.png
┗📜mod_name.dll