Stack Count By Ingredients - Vanilla-Expanded/VanillaExpandedFramework GitHub Wiki
Graphic_StackCountByIngredient is a graphic class that allows you to change the graphic of an item depending on its list of ingredients. Used and abused by Alpha Crafts a lot.
To make it work, it needs a custom def in tandem, GraphicOffsets:
//The ThingDef this GraphicOffsets is targetting
public ThingDef thingDef;
//A Dictionary of ingredient ThingDefs and their offset
public Dictionary<ThingDef, int> ingredientsAndOffsetList;
The amount of images in the folder for the item must be a multiple of 3, or weird things will happen!
First of all, graphic classes can just be specified by placing them in the graphicClass tag of the Thing:
<graphicClass>VEF.Graphics.Graphic_StackCountByIngredient</graphicClass>
Secondly, you'll need to make a list of ingredients and their offset in an image's folder to tell the graphic class which graphic to choose. For example, this is the custom def for oil in Alpha Crafts:
<?xml version="1.0" encoding="UTF-8"?>
<Defs>
<VEF.Graphics.GraphicOffsets>
<defName>AC_OilOffsets</defName>
<thingDef>AC_Oil</thingDef>
<ingredientsAndOffsetList>
<li>
<key>RawCorn</key>
<value>3</value>
</li>
<li>
<key>SmokeleafLeaves</key>
<value>5</value>
</li>
</ingredientsAndOffsetList>
</VEF.Graphics.GraphicOffsets>
</Defs>
And here is an image of the item's folder:
I marked them so that you can see groups of threes.
If you don't make a VEF.Graphics.GraphicOffsets, the image chosen for the item will always be the first group. As specified in the example above, the value field for RawCorn is 3, so if the ingredients contain corn, the game will choose the third group (remember, count starts at 0!), so these:
If the ingredients contain smokeleaf, the game will choose the fifth group (again, count starts at 0), so these:
Furthermore, new entries can be patched into a VEF.Graphics.GraphicOffsets, that's why there are more oils in that image, as patches for different VE mods will insert Avocado with a value of 7 (the last group of three, greenish), olives and canola, for example.