Crafting Recipe Modding Guide: Difference between revisions
CptTwinkie (talk | contribs) mNo edit summary |
CptTwinkie (talk | contribs) mNo edit summary |
||
Line 27: | Line 27: | ||
# 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. | # 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. | ||
< | <syntaxhighlight lang="xml" collapse="false" line> | ||
<?xml version="1.0"?> | <?xml version="1.0"?> | ||
<Definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> | <Definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> | ||
Line 45: | Line 45: | ||
</Definition> | </Definition> | ||
</Definitions> | </Definitions> | ||
</ | </syntaxhighlight> | ||
Line 55: | Line 55: | ||
== Explanation == | == Explanation == | ||
* The XML prolog. Don't mess with it. | * The XML prolog. Don't mess with it. | ||
< | <syntaxhighlight lang="xml" collapse="false"> | ||
<?xml version="1.0"?> | <?xml version="1.0"?> | ||
</ | </syntaxhighlight> | ||
<br> | <br> | ||
* Opens (<>) and closes (</>) our definitions. A file can have multiple ''CraftingRecipeDefinitions'' in it, but all of them must be inside these tags. | * Opens (<>) and closes (</>) our definitions. A file can have multiple ''CraftingRecipeDefinitions'' in it, but all of them must be inside these tags. | ||
< | <syntaxhighlight lang="xml" collapse="false"> | ||
<Definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> | <Definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> | ||
</Definitions> | </Definitions> | ||
</ | </syntaxhighlight> | ||
<br> | <br> | ||
* Tells the game that we want to create a crafting recipe, hence type ''CraftingRecipeDefinition''. | * Tells the game that we want to create a crafting recipe, hence type ''CraftingRecipeDefinition''. | ||
< | <syntaxhighlight lang="xml" collapse="false"> | ||
<Definition xsi:type="MyObjectBuilder_CraftingRecipeDefinition"> | <Definition xsi:type="MyObjectBuilder_CraftingRecipeDefinition"> | ||
</Definition> | </Definition> | ||
</ | </syntaxhighlight> | ||
<br> | <br> | ||
* 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 {{Small_Image_Link|DrawingBoard.png|Research Table}}. | * 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 {{Small_Image_Link|DrawingBoard.png|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. | * 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. | * You may overwrite a vanilla definition on purpose. For example, to increase the amount of Timbers produced by a Log. | ||
< | <syntaxhighlight lang="xml" collapse="false"> | ||
<Id Type="MyObjectBuilder_CraftingRecipeDefinition" Subtype="ExampleMod_LogForTimbers"/> | <Id Type="MyObjectBuilder_CraftingRecipeDefinition" Subtype="ExampleMod_LogForTimbers"/> | ||
</ | </syntaxhighlight> | ||
<br> | <br> | ||
* This is the name that will appear when you hover the mouse over the recipe in the crafting screen. | * This is the name that will appear when you hover the mouse over the recipe in the crafting screen. | ||
< | <syntaxhighlight lang="xml" collapse="false"> | ||
<DisplayName>Log for Timbers</DisplayName> | <DisplayName>Log for Timbers</DisplayName> | ||
</ | </syntaxhighlight> | ||
<br> | <br> | ||
* This is the description that will appear when you hover the mouse over the recipe in the crafting screen. | * This is the description that will appear when you hover the mouse over the recipe in the crafting screen. | ||
< | <syntaxhighlight lang="xml" collapse="false"> | ||
<Description>Craft a Log using 4 Timbers</Description> | <Description>Craft a Log using 4 Timbers</Description> | ||
</ | </syntaxhighlight> | ||
<br> | <br> | ||
* 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. | * 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. | * 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. | ||
< | <syntaxhighlight lang="xml" collapse="false"> | ||
<Icon>Textures\GUI\Icons\Cubes\Log250cm.dds</Icon> | <Icon>Textures\GUI\Icons\Cubes\Log250cm.dds</Icon> | ||
</ | </syntaxhighlight> | ||
<br> | <br> | ||
* This is the category this recipe will appear in the crafting screen. | * 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 {{Small_Image_Link|WoodTable.png|Crafting Table}}. | * 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 {{Small_Image_Link|WoodTable.png|Crafting Table}}. | ||
* There are other categories, like ''Milling'' for the {{Small_Image_Link|MillStone_Small.png|Mill Stone}} and ''Smelting'' for the {{Small_Image_Link|ClayFurnace.png|Furnace}} | * There are other categories, like ''Milling'' for the {{Small_Image_Link|MillStone_Small.png|Mill Stone}} and ''Smelting'' for the {{Small_Image_Link|ClayFurnace.png|Furnace}} | ||
< | <syntaxhighlight lang="xml" collapse="false"> | ||
<Category>SmallBlocks</Category> | <Category>SmallBlocks</Category> | ||
</ | </syntaxhighlight> | ||
{{TextBox|Tip: Use Notepad++ '''Search in Files''' function to search vanilla definitions on the game's Data folder. You can access it by pressing '''Ctrl + Shift + F'''.}} | {{TextBox|Tip: Use Notepad++ '''Search in Files''' function to search vanilla definitions on the game's Data folder. You can access it by pressing '''Ctrl + Shift + F'''.}} | ||
<br> | <br> | ||
* This is the cost of the recipe. You can specify multiple items by using the ''Item'' tag multiple times. ''Amount'' is the amount of that type of item that will be consumed. | * This is the cost of the recipe. You can specify multiple items by using the ''Item'' tag multiple times. ''Amount'' is the amount of that type of item that will be consumed. | ||
< | <syntaxhighlight lang="xml" collapse="false"> | ||
<Prerequisites> | <Prerequisites> | ||
<Item Amount="4" Tag="Timber" /> | <Item Amount="4" Tag="Timber" /> | ||
</Prerequisites> | </Prerequisites> | ||
</ | </syntaxhighlight> | ||
* 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. | * 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. | ||
< | <syntaxhighlight lang="xml" collapse="false"> | ||
<Prerequisites> | <Prerequisites> | ||
<Item Amount="4" Type="CubeBlock" Subtype="Timber10"/> | <Item Amount="4" Type="CubeBlock" Subtype="Timber10"/> | ||
</Prerequisites> | </Prerequisites> | ||
</ | </syntaxhighlight> | ||
<br> | <br> | ||
* This is the product of the recipe. | * This is the product of the recipe. | ||
< | <syntaxhighlight lang="xml" collapse="false"> | ||
<Results> | <Results> | ||
<Item Amount="1" Type="InventoryItem" Subtype="Log250cm" /> | <Item Amount="1" Type="InventoryItem" Subtype="Log250cm" /> | ||
</Results> | </Results> | ||
</ | </syntaxhighlight> | ||
<br> | <br> | ||
* This is the amount of time it takes for the crafting to complete. | * This is the amount of time it takes for the crafting to complete. | ||
< | <syntaxhighlight lang="xml" collapse="false"> | ||
<CraftingTime Seconds="5"/> | <CraftingTime Seconds="5"/> | ||
</ | </syntaxhighlight> | ||
== Conclusion & Challenge == | == Conclusion & Challenge == |
Latest revision as of 20:12, 18 July 2022
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.
Version: | 0.5 |
Tools Used
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.
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 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 XML prolog. Don't mess with it.
<?xml version="1.0"?>
- Opens (<>) and closes (</>) 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 Item 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.