Confirmedusers
643
edits
mNo edit summary |
mNo edit summary |
||
Line 48: | Line 48: | ||
Create your new class. Right click the new folder, hover over ''Add'', and select ''Class''. Ensure you have the standard ''Class'' selected in the template list, enter your class name, and click create. | Create your new class. Right click the new folder, hover over ''Add'', and select ''Class''. Ensure you have the standard ''Class'' selected in the template list, enter your class name, and click create. | ||
The class you created needs to extend the 'Item' | |||
The class | |||
=== Registering the Item Class === | |||
The class for the thorns blade is created, however before it can be used it needs to be registered through the game API. In your mod system, which you used in the previous tutorial, you need to register an item class for both the client and server. | |||
In the ''Start'' function, | In the ''Start'' function, make a call to the RegisterItemClass function in the API. Add the following code on a new line inside of the ''Start'' function's block:<syntaxhighlight lang="csharp"> | ||
api. | api.RegisterItemClass(); | ||
</syntaxhighlight> | </syntaxhighlight>Similarly to the previous tutorial, this will result in an error. You'll need to add some parameters to the function. Don't forget, you can hover over the function with your mouse and the required parameters will be shown. In this case, we once again need a class name, and a type. | ||
Your class name argument should be fully lowercase, and should generally be your mod ID, joined with the name of the class you just made. The itemType will be the class you just made. Replace the function with the following:<syntaxhighlight lang="csharp"> | |||
api.RegisterItemClass(Mod.Info.ModID + ".thornsblade", typeof(ItemThornsBlade)); | |||
</syntaxhighlight>This will register the ItemThornsBlade class with the name "vstutorial.thornsblade". | |||
api. | |||
</syntaxhighlight>This will register the | |||
{| class="wikitable mw-collapsible mw-collapsed" | {| class="wikitable mw-collapsible mw-collapsed" | ||
|Why include the mod id here? | |Why include the mod id here? | ||
Line 68: | Line 66: | ||
|} | |} | ||
=== Adding | === Adding Item Class to Asset === | ||
Before your | Before your item will work, you need to add the class to the asset file. Open the file in ''assets/vstutorial/itemtypes/thornsblade.json''. | ||
You need to add the following property to the file:<syntaxhighlight lang="json"> | You need to add the following property to the file:<syntaxhighlight lang="json"> | ||
"class": "vstutorial. | "class": "vstutorial.thornsblade", | ||
</syntaxhighlight>Generally, this element is placed as the second property in your json file, immediately below the code property. | </syntaxhighlight>Generally, this element is placed as the second property in your json file, immediately below the code property. | ||
Note that the value of this property is identical to the value we used in the '' | Note that the value of this property is identical to the value we used in the ''RegisterItemClass'' function. This is how the game links the JSON asset files to your code's registered classes. | ||
== Testing the Block Class == | == Testing the Block Class == |