Modding:Block and Item Interactions: Difference between revisions

From Vintage Story Wiki
Marked this version for translation
m (Checked version and updated.)
(Marked this version for translation)
(One intermediate revision by the same user not shown)
Line 1: Line 1:
<languages/>
__FORCETOC__
__FORCETOC__
<translate>
<!--T:1-->
{{GameVersion|1.19.3}}
{{GameVersion|1.19.3}}
</translate>


<translate>
<!--T:2-->
This tutorial will introduce you into the basics of custom interactions. We will create a magic wand which will spawn particles when holding right click.
This tutorial will introduce you into the basics of custom interactions. We will create a magic wand which will spawn particles when holding right click.
</translate>


= Preparations =
<translate>
= Preparations = <!--T:3-->
</translate>


<translate>
<!--T:4-->
I highly recommend to read about [[Advanced Items|The Item Class]] first. Additionally you can download the assets [https://wiki.vintagestory.at/images/4/4d/MagicWand_-_No_CS_File.zip here].
I highly recommend to read about [[Advanced Items|The Item Class]] first. Additionally you can download the assets [https://wiki.vintagestory.at/images/4/4d/MagicWand_-_No_CS_File.zip here].
</translate>


<translate>
<!--T:5-->
All of this should be familiar to you, creating and registering the item class ...
All of this should be familiar to you, creating and registering the item class ...
</translate>


<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
Line 28: Line 43:
</syntaxhighlight>
</syntaxhighlight>


== Adding particles ==
<translate>
== Adding particles == <!--T:6-->
</translate>


<translate>
<!--T:7-->
Now we need to implement the interact function. First of all we need to specify that the player can "use" this tool, therefore we need to set handling to <code>handled</code> ...
Now we need to implement the interact function. First of all we need to specify that the player can "use" this tool, therefore we need to set handling to <code>handled</code> ...
</translate>


<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
Line 39: Line 59:
</syntaxhighlight>
</syntaxhighlight>


<translate>
<!--T:8-->
The method <code>OnHeldInteractStep</code> allows us to spawn particles per tick while the player is using the item, but it would be better to implement an animation first. Particles should spawn after the animation is done ...
The method <code>OnHeldInteractStep</code> allows us to spawn particles per tick while the player is using the item, but it would be better to implement an animation first. Particles should spawn after the animation is done ...
</translate>


<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
Line 57: Line 80:
</syntaxhighlight>
</syntaxhighlight>


<translate>
<!--T:9-->
Holding rightclick ...
Holding rightclick ...


<!--T:10-->
[[File:Magic Stick Interact.gif|300px]]
[[File:Magic Stick Interact.gif|300px]]


<!--T:11-->
So let's start to mess around with particles, therefore we need a static particle type ...
So let's start to mess around with particles, therefore we need a static particle type ...
</translate>


<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
Line 79: Line 107:
</syntaxhighlight>
</syntaxhighlight>


<translate>
<!--T:12-->
Particles should spawn once the animation is completed. This will be the case after <code>0.6</code> seconds ...
Particles should spawn once the animation is completed. This will be the case after <code>0.6</code> seconds ...
</translate>


<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
Line 88: Line 119:
</syntaxhighlight>
</syntaxhighlight>


<translate>
<!--T:13-->
I suggest to read the tutorial about [[Simple Particles]] first. This code will spawn particles in front of the player with a randomized color and a sinus evolving size ...
I suggest to read the tutorial about [[Simple Particles]] first. This code will spawn particles in front of the player with a randomized color and a sinus evolving size ...
</translate>


<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
Line 107: Line 141:
</syntaxhighlight>
</syntaxhighlight>


<translate>
<!--T:14-->
If we put everything together the <code>OnHeldInteractStep</code> method will look like this ...
If we put everything together the <code>OnHeldInteractStep</code> method will look like this ...
</translate>


<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
Line 143: Line 180:
</syntaxhighlight>
</syntaxhighlight>


== Testing ==
<translate>
== Testing == <!--T:15-->
</translate>


<translate>
<!--T:16-->
Now we can run our first test, doesn't it look beautiful?
Now we can run our first test, doesn't it look beautiful?
</translate>


<youtube>bTPXL97Gfns</youtube>
<youtube>bTPXL97Gfns</youtube>


= Mod Download =
<translate>
= Mod Download = <!--T:17-->
</translate>


<translate>
<!--T:18-->
Feel free to try it out yourself:
Feel free to try it out yourself:
</translate>


<translate>
<!--T:19-->
Here is my version:  
Here is my version:  
* for VS v1.9: [https://wiki.vintagestory.at/images/7/72/Magicwand_vs1.9_v1.0.0.zip Magicwand_vs1.9_v1.0.0.zip]
* for VS v1.9: [https://wiki.vintagestory.at/images/7/72/Magicwand_vs1.9_v1.0.0.zip Magicwand_vs1.9_v1.0.0.zip]
* for VS v1.8: [https://wiki.vintagestory.at/images/3/38/MagicWand.zip MagicWand.zip]
* for VS v1.8: [https://wiki.vintagestory.at/images/3/38/MagicWand.zip MagicWand.zip]
</translate>






{{Navbox/modding|Vintage Story}}
{{Navbox/modding|Vintage Story}}
Confirmedusers
409

edits