Crafting Recipe Modding Guide
This guide shows you how to add custom crafting recipes into Medieval Engineers. We'll be making an example mod in which you can craft a Log using 4 Timbers.
Tools Used
- Notepad++ (or any plain text editor)
Prerequisites
- No prior programming knowledge is required, as we will only be dealing with XML. That being said, a superficial understanding of how it works can help you prevent syntax mistakes. You can find more info about it here.
Mod Structure
Our example mod contains two folders and one file. First, let's create the folders.
- Navigate to %appdata%/Roaming/MedievalEngineers/Mods
- Create a new folder. Name it whatever you like. I'll be calling it ExampleMod. This is our mod's root folder.
- Navigate to our mod's root folder.
- Create a new folder. Name it Data, with a capital letter D.
Now that we have our mod structure, let's start adding the definitions.
Definitions
XML stores information, but can't do anything useful with it on its own. A definition is a way to tell the game what we want it to do with this information when it loads our mod. For example, to create a crafting recipe we use a CraftingRecipeDefinition. This definition contains what we want the recipe to produce, what's are the costs of it and so on.
- Open a new document in Notepad++ and paste the following code.
- Save the file in our mod's Data folder as ExampleMod_Crafting.sbc. The extension is mandatory, but the name is not. Prepending the name of the mod on the file name can also help avoid confusion with vanilla files.
<?xml version="1.0"?>
<Definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Definition xsi:type="MyObjectBuilder_CraftingRecipeDefinition">
<Id Type="MyObjectBuilder_CraftingRecipeDefinition" Subtype="ExampleMod_LogForTimbers"/>
<DisplayName>Log for Timbers</DisplayName>
<Description>Craft a Log using 4 Timbers</Description>
<Icon>Textures\GUI\Icons\Cubes\Log250cm.dds</Icon>
<Category>SmallBlocks</Category>
<Prerequisites>
<Item Amount="4" Tag="Timber" />
</Prerequisites>
<Results>
<Item Amount="1" Type="InventoryItem" Subtype="Log250cm" />
</Results>
<CraftingTime Seconds="5"/>
</Definition>
</Definitions>
- Start the game and load our mod. Take a look at what we did and come back to the explanation later. (Note: Local mods can only be loaded in offline mode)
Explanation
- The file header. Don't mess with it.
<?xml version="1.0"?>
- Open (<>) and close (</>) our definitions. A file can have multiple CraftingRecipeDefinitions in it, but all of them must be inside these tags.
<Definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
</Definitions>
- Tells the game that we want to create a crafting recipe, hence type CraftingRecipeDefinition.
<Definition xsi:type="MyObjectBuilder_CraftingRecipeDefinition">
</Definition>
- The most important thing here is the Subtype. This is the name by which this definition will be referenced in other files. For example, in a ResearchDefinition, which creates a research that can be unlocked in the Research Table.
- The Subtype must be unique among all mods being used by a player, or the last definition to load will overwrite the others. Prepending the name of the mod in the Subtype is a way to make sure it is unique.
- You may overwrite a vanilla definition on purpose. For example, to increase the amount of Timbers produced by a Log.
<Id Type="MyObjectBuilder_CraftingRecipeDefinition" Subtype="ExampleMod_LogForTimbers"/>
- This is the name that will appear when you hover the mouse over the recipe in the crafting screen.
<DisplayName>Log for Timbers</DisplayName>
- This is the description that will appear when you hover the mouse over the recipe in the crafting screen.
<Description>Craft a Log using 4 Timbers</Description>
- This is the icon that will appear in the crafting screen for this recipe. The path is relative to you mod's root folder. If the file does not exist there, it will fallback to the Content folder in the game's files. This means you can use files from the game without copying them to your mod's folder.
- You can specify multiple icons by using this tag multiple times with different values. In this case, the resulting icon will be the overlap of the individual files, the last icon defined being on the front.
<Icon>Textures\GUI\Icons\Cubes\Log250cm.dds</Icon>
- This is the category this recipe will appear in the crafting screen.
- It also indirectly defines where this recipe can be crafted. SmallBlocks means it can be crafted in the player's crafting screen and in the Crafting Table.
- There are other categories, like Milling for the Mill Stone and Smelting for the Furnace
<Category>SmallBlocks</Category>
- This is the cost of the recipe. You can specify multiple items by using the Items tag multiple times. Amount is the amount of that type of item that will be consumed.
<Prerequisites>
<Item Amount="4" Tag="Timber" />
</Prerequisites>
- There are two ways of referencing an item. By its Type and Subtype or by its Tag. For example, we could do the same thing using the following, but it would mean that we can only craft a Log using common Timbers and not round or diagonal ones. The Tag version allows all kinds of timbers to be used without needing to define individual recipes for each one.
<Prerequisites>
<Item Amount="4" Type="CubeBlock" Subtype="Timber10"/>
</Prerequisites>
- This is the product of the recipe.
<Results>
<Item Amount="1" Type="InventoryItem" Subtype="Log250cm" />
</Results>
- This is the amount of time it takes for the crafting to complete.
<CraftingTime Seconds="5"/>
Conclusion & Challenge
This wraps up this guide about crafting recipes. I hope it was useful to you. As an optional challenge to see if you got everything right, try to:
- Make a recipe that gets a Pumpkin and a Torch and turns them into a Jack-o'-Lantern.
- Make this new recipe overwrite the vanilla Jack-o'-Lantern recipe.