Modding:Block and Item Interactions: Difference between revisions

From Vintage Story Wiki
no edit summary
No edit summary
No edit summary
(4 intermediate revisions by 2 users not shown)
Line 3: Line 3:
== Preparations ==
== Preparations ==


I highly recommend to read about [[Advanced Items|The Item Class]] first. Additionally you can download the assets [http://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].


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 ...
Line 30: Line 30:


<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
         public override bool OnBeginInteract(IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
         public override bool OnHeldInteractStart(IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
         {
         {
             return true;
             return true;
Line 36: Line 36:
</syntaxhighlight>
</syntaxhighlight>


The method <code>OnInteracting</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 ...


<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
         public override bool OnInteracting(float secondsUsed, IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
         public override bool OnHeldInteractStep(float secondsUsed, IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
         {
         {
             if (byEntity.World is IClientWorldAccessor)
             if (byEntity.World is IClientWorldAccessor)
Line 109: Line 109:
</syntaxhighlight>
</syntaxhighlight>


If we put everything together the <code>OnInteracting</code> method will look like this ...
If we put everything together the <code>OnHeldInteractStep</code> method will look like this ...


<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
         public override bool OnInteracting(float secondsUsed, IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
         public override bool OnHeldInteractStep(float secondsUsed, IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
         {
         {
             if (byEntity.World is IClientWorldAccessor)
             if (byEntity.World is IClientWorldAccessor)
Line 161: Line 161:
Feel free to try it out yourself:
Feel free to try it out yourself:


[http://wiki.vintagestory.at/images/3/38/MagicWand.zip MagicWand.zip]
[https://wiki.vintagestory.at/images/3/38/MagicWand.zip MagicWand.zip]
 
 
{{Navbox/modding|Vintage Story}}
Confirmedusers, editor, Administrators
886

edits