Crafting Recipe Modding Guide: Difference between revisions

From Medieval Engineers Wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
 
(15 intermediate revisions by 2 users not shown)
Line 1: Line 1:
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 {{Small_Image_Link|Log.png|Log}} using 4 {{Small_Image_Link|Timber.png|Timber}}s.
{{SEO|description=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.}}
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 {{Small_Image_Link|Log.png|Log}} using {{Small_Image_Number_Link|Timber.png|4|Timber}}s.
 
{{Version <!-- Do not change the version until the entire page is up-to-date -->
|release=0|major=5|minor=x}}


== Tools Used ==
== Tools Used ==
* Notepad++
* [https://notepad-plus-plus.org/ Notepad++]


== Prerequisites ==
== 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 [https://www.w3schools.com/Xml/default.asp here].
* No prior programming knowledge is required, as we will only be dealing with [https://en.wikipedia.org/wiki/XML XML]. That being said, a superficial understanding of [https://www.w3schools.com/Xml/default.asp how it works] can help you prevent syntax mistakes.


== Mod Structure ==
== Mod Structure ==
Line 18: Line 22:


== 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.
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.
# 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.
# 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.


<source lang="xml" collapse="false">
<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 41: Line 45:
   </Definition>
   </Definition>
</Definitions>
</Definitions>
</source>
</syntaxhighlight>
 


{{TextBox|Tip: Life is hard on its own. Go to the '''Language''' menu in Notepad++ and select '''XML''' as the file language, this will enable syntax highlighting.}}
{{TextBox|Tip: Life is hard on its own. Go to the '''Language''' menu in Notepad++ and select '''XML''' as the file language, this will enable syntax highlighting.}}


# Start the game and load our mod. Take a look at what we did and come back to the explanation later.
 
# 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 ==
== Explanation ==
* The file header. Don't mess with it.
* The XML prolog. Don't mess with it.
<source lang="xml" collapse="false">
<syntaxhighlight lang="xml" collapse="false">
<?xml version="1.0"?>
<?xml version="1.0"?>
</source>
</syntaxhighlight>
<br>
<br>
* Open (<>) and close (</>) 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.
<source lang="xml" collapse="false">
<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>
</source>
</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''.
<source lang="xml" collapse="false">
<syntaxhighlight lang="xml" collapse="false">
<Definition xsi:type="MyObjectBuilder_CraftingRecipeDefinition">
<Definition xsi:type="MyObjectBuilder_CraftingRecipeDefinition">
</Definition>
</Definition>
</source>
</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.  
<source lang="xml" collapse="false">
<syntaxhighlight lang="xml" collapse="false">
<Id Type="MyObjectBuilder_CraftingRecipeDefinition" Subtype="ExampleMod_LogForTimbers"/>
<Id Type="MyObjectBuilder_CraftingRecipeDefinition" Subtype="ExampleMod_LogForTimbers"/>
</source>
</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.
<source lang="xml" collapse="false">
<syntaxhighlight lang="xml" collapse="false">
<DisplayName>Log for Timbers</DisplayName>
<DisplayName>Log for Timbers</DisplayName>
</source>
</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.
<source lang="xml" collapse="false">
<syntaxhighlight lang="xml" collapse="false">
<Description>Craft a Log using 4 Timbers</Description>
<Description>Craft a Log using 4 Timbers</Description>
</source>
</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.
<source lang="xml" collapse="false">
<syntaxhighlight lang="xml" collapse="false">
<Icon>Textures\GUI\Icons\Cubes\Log250cm.dds</Icon>
<Icon>Textures\GUI\Icons\Cubes\Log250cm.dds</Icon>
</source>
</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}}
<source lang="xml" collapse="false">
<syntaxhighlight lang="xml" collapse="false">
<Category>SmallBlocks</Category>
<Category>SmallBlocks</Category>
</source>
</syntaxhighlight>
{{TextBox|Tip: Use Notepad++ '''Search in Files''' function to search vanilla definitions on the game's Data folde. 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 ''Items'' 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.
<source lang="xml" collapse="false">
<syntaxhighlight lang="xml" collapse="false">
<Prerequisites>
<Prerequisites>
     <Item Amount="4" Tag="Timber" />
     <Item Amount="4" Tag="Timber" />
</Prerequisites>
</Prerequisites>
</source>
</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.
<source lang="xml" collapse="false">
<syntaxhighlight lang="xml" collapse="false">
<Prerequisites>
<Prerequisites>
     <Item Amount="4" Type="CubeBlock" Subtype="Timber10"/>
     <Item Amount="4" Type="CubeBlock" Subtype="Timber10"/>
</Prerequisites>
</Prerequisites>
</source>
</syntaxhighlight>
<br>
<br>
* This is the product of the recipe.
* This is the product of the recipe.
<source lang="xml" collapse="false">
<syntaxhighlight lang="xml" collapse="false">
<Prerequisites>
<Results>
     <Item Amount="1" Type="InventoryItem" Subtype="Log250cm" />
     <Item Amount="1" Type="InventoryItem" Subtype="Log250cm" />
</Prerequisites>
</Results>
</source>
</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.
<source lang="xml" collapse="false">
<syntaxhighlight lang="xml" collapse="false">
<CraftingTime Seconds="5"/>
<CraftingTime Seconds="5"/>
</source>
</syntaxhighlight>


== Conclusion & Challenge ==
== Conclusion & Challenge ==
Line 126: Line 132:
# Make a recipe that gets a Pumpkin and a Torch and turns them into a Jack-o'-Lantern.
# 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.
# Make this new recipe overwrite the vanilla Jack-o'-Lantern recipe.
[[Category:Community_Modding_Guides]]
[[Category:Community_Guides]]

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.

  1. Navigate to %appdata%/Roaming/MedievalEngineers/Mods
  2. Create a new folder. Name it whatever you like. I'll be calling it ExampleMod. This is our mod's root folder.
  3. Navigate to our mod's root folder.
  4. 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.

  1. Open a new document in Notepad++ and paste the following code.
  2. 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>


Tip: Life is hard on its own. Go to the Language menu in Notepad++ and select XML as the file language, this will enable syntax highlighting.


  1. 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>
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.


  • 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:

  1. Make a recipe that gets a Pumpkin and a Torch and turns them into a Jack-o'-Lantern.
  2. Make this new recipe overwrite the vanilla Jack-o'-Lantern recipe.