Is there a way to make an item craftable? For example, sulfur ore cooks into sulfur. Can you make a non-cookable item and make it cookable? Would you add the ItemModCookable component to the item? Not looking for an existing plugin, just looking for some direction on how to do this myself.
Making an item cookable?Solved
I guess it is possible, by as u said adding ItemModCookable or changing something else.
In response to misticos ():I guess it is possible, by as u said adding ItemModCookable or changing something else.
I've been trying to use ItemModCookable, but it's not working out too well.
I thought this would work. Sulfur ore uses the ItemModCookable component. I want it to act just like sulfur ore. just 2 different items.
var item = ItemManager.FindItemDefinition("cloth");
var cookable = item.gameObject.AddComponent<ItemModCookable>();
cookable.amountOfBecome = 1;
cookable.becomeOnCooked = ItemManager.FindItemDefinition("leather");
cookable.cookTime = 5f;
cookable.highTemp = 1200;
cookable.lowTemp = 800;
cookable.ModInit();I thought this would work. Sulfur ore uses the ItemModCookable component. I want it to act just like sulfur ore. just 2 different items.
In response to Tanner ():I've been trying to use ItemModCookable, but it's not working out too well.
var item = I...
From what I can see here, you are not creating an actual item here, just modifying an item definition, have you tried to spawn item and then apply component to it?
Upd. Also, consider option not to change an item itself, but use oven ticks (dont remember the hook name), and just replace the item in oven's inventory, when its "ready"
Upd. Also, consider option not to change an item itself, but use oven ticks (dont remember the hook name), and just replace the item in oven's inventory, when its "ready"
Try adding this item mod also to definition.itemMods array. Should work
In response to misticos ():Try adding this item mod also to definition.itemMods array. Should work
Okay.
This works. It's cooking the cloth, but when I put in 1 cloth, it turns into 9 leather. When I put in 10 cloth, it takes 9 cloth and turns it into 9 leather... Interesting. That's literally all the code I have inside OnServerInitialized.
Merged post
Scratch that.. It's no longer working for some reason. Figured the extra leather was because I had multiple ItemModCookable components. Removed the extra components and added a new component and now it's not working.
var item = ItemManager.CreateByName("cloth");
var itemDefinition = ItemManager.FindItemDefinition("cloth");
var cookable = itemDefinition.gameObject.AddComponent<ItemModCookable>();
cookable.amountOfBecome = 1;
cookable.becomeOnCooked = ItemManager.FindItemDefinition("leather");
cookable.cookTime = 5f;
cookable.highTemp = 1200;
cookable.lowTemp = 800;This works. It's cooking the cloth, but when I put in 1 cloth, it turns into 9 leather. When I put in 10 cloth, it takes 9 cloth and turns it into 9 leather... Interesting. That's literally all the code I have inside OnServerInitialized.
Merged post
Scratch that.. It's no longer working for some reason. Figured the extra leather was because I had multiple ItemModCookable components. Removed the extra components and added a new component and now it's not working.
there is GetOrAddComponent, you could use and modify that :P (facepunch method afaik). make sure u didnt remove code that adds it to itemMods array in item definition :)
This is what ModInit does.
public virtual void ModInit()
{
this.siblingMods = this.GetComponents<ItemMod>();
}So this means I would want to put ItemModCookable inside the ItemMod component?
var item = ItemManager.CreateByName("cloth");
var itemDefinition = ItemManager.FindItemDefinition("cloth");
var itemMod = itemDefinition.gameObject.GetOrAddComponent<ItemMod>();
var cookable = itemMod.gameObject.GetOrAddComponent<ItemModCookable>();Then I'd do itemMod.ModInit() right? That still doesn't work. That should add the item to the itemmod array. Looking through the decompiler right now.
No just use ItemModCookable that inherits ItemMod. GetOrAdd it and dont forget to add it to itemDefinition.itemMods array (using linq or whatever u want)
Locked automatically