Modding:Simple Particles: Difference between revisions

From Vintage Story Wiki
(Marked this version for translation)
m (Updated to 1.19.3.)
Line 1: Line 1:
{{GameVersion|1.15}}
{{GameVersion|1.19.3}}
<languages/><translate>
<languages/><translate>
<!--T:1-->
<!--T:1-->
Line 11: Line 11:
<!--T:4-->
<!--T:4-->
<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
        public static SimpleParticleProperties myParticles = new SimpleParticleProperties(1, 1, ColorUtil.ColorFromArgb(50, 220, 220, 220), new Vec3d(), new Vec3d(), new Vec3f(), new Vec3f());
    public static SimpleParticleProperties myParticles = new SimpleParticleProperties(1, 1, ColorUtil.ColorFromRgba(220, 220, 220, 255), new Vec3d(), new Vec3d(), new Vec3f(), new Vec3f());
 
</syntaxhighlight>
</syntaxhighlight>


Line 17: Line 18:
Now we have the property, the only thing left to do is to set the position and spawn the particles into the world. I'm gonna use the <code>OnHeldInteractStart</code> and *Step method inside a custom made Item class (you can read more about this in the [[Collectible|Collectibles Tutorial]]):
Now we have the property, the only thing left to do is to set the position and spawn the particles into the world. I'm gonna use the <code>OnHeldInteractStart</code> and *Step method inside a custom made Item class (you can read more about this in the [[Collectible|Collectibles Tutorial]]):
<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
         public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handHandling)
         public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handling)
         {
         {
             handHandling = EnumHandHandling.Handled;
             handling = EnumHandHandling.Handled;
         }
         }


Line 25: Line 26:
public override bool OnHeldInteractStep(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
public override bool OnHeldInteractStep(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
         {
         {
             myParticles.minPos = byEntity.Pos.XYZ.Add(0, byEntity.EyeHeight(), 0).Ahead(1f, byEntity.Pos.Pitch, byEntity.Pos.Yaw);
             myParticles.minPos = byEntity.Pos.XYZ.Add(0, byEntity.LocalEyePos, 0).Ahead(1f, byEntity.Pos.Pitch, byEntity.Pos.Yaw);
             byEntity.World.SpawnParticles(myParticles);
             byEntity.World.SpawnParticles(myParticles);


Line 47: Line 48:


<!--T:13-->
<!--T:13-->
Basically there are two properties. One of them is the <code>minPos</code> property, which will determine the exact position where particles will spawn. <code>addPos</code> is relative to this position, once a particle will spawn it will be randomized and added to the particle's position. If <code>addPos</code> is not defined all particles will spawn at the exact some position.
Basically there are two properties. One of them is the <code>MinPos</code> property, which will determine the exact position where particles will spawn. <code>AddPos</code> is relative to this position, once a particle will spawn it will be randomized and added to the particle's position. If <code>AddPos</code> is not defined all particles will spawn at the exact some position.


<!--T:14-->
<!--T:14-->
Line 56: Line 57:


<!--T:16-->
<!--T:16-->
If we now set <code>addPos</code> ...
If we now set <code>AddPos</code> ...


<!--T:17-->
<!--T:17-->
<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
     myParticles.addPos = new Vec3d(0.5, 0.5, 0.5);
     myParticles.AddPos = new Vec3d(0.5, 0.5, 0.5);
</syntaxhighlight>
</syntaxhighlight>


Line 72: Line 73:


<!--T:21-->
<!--T:21-->
It follows the same way as position. You can configure a minimum velocity (<code>minPos</code>) and an additional velocity (<code>addPos</code>).
It follows the same way as position. You can configure a minimum velocity (<code>MinVelocity</code>) and an additional velocity (AddVelocity).


<!--T:22-->
<!--T:22-->
<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
     myParticles.minVelocity = new Vec3f(0, 3, 0);
     myParticles.MinVelocity = new Vec3f(0, 3, 0);
</syntaxhighlight>
</syntaxhighlight>


Line 95: Line 96:
<!--T:28-->
<!--T:28-->
<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
     myParticles.lifeLength = 0.2F;
     myParticles.LifeLength = 0.2F;
</syntaxhighlight>
</syntaxhighlight>


Line 107: Line 108:
<!--T:31-->
<!--T:31-->
<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
     myParticles.lifeLength = 1F;
     myParticles.LifeLength = 1F;
</syntaxhighlight>
</syntaxhighlight>


Line 120: Line 121:
<!--T:35-->
<!--T:35-->
<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
     myParticles.minQuantity = 3;
     myParticles.MinQuantity = 3;
</syntaxhighlight>
</syntaxhighlight>


Line 134: Line 135:
<!--T:39-->
<!--T:39-->
<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
     myParticles.minQuantity = 0;
     myParticles.MinQuantity = 0;
     myParticles.addQuantity = 100;
     myParticles.AddQuantity = 100;
</syntaxhighlight>
</syntaxhighlight>


Line 151: Line 152:
<!--T:44-->
<!--T:44-->
<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
     myParticles.color = ColorUtil.ToRGBABytes(ColorUtil.ColorFromArgb(255, 255, 0, 0));
     myParticles.Color = ColorUtil.ColorFromRgba(255, 0, 0, 255);
</syntaxhighlight>
</syntaxhighlight>


Line 163: Line 164:
<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
     Random rand = new Random();
     Random rand = new Random();
     myParticles.color = ColorUtil.ToRGBABytes(ColorUtil.ColorFromArgb(255, rand.Next(0, 255), rand.Next(0, 255), rand.Next(0, 255)));
     myParticles.Color = ColorUtil.ColorFromRgba(rand.Next(0, 255), rand.Next(0, 255), rand.Next(0, 255), 255);
</syntaxhighlight>
</syntaxhighlight>


Line 169: Line 170:
This will spawn particles with a random color ...
This will spawn particles with a random color ...


<!--T:49-->
[[File:Particles (random colors).gif|300px]]
[[File:Particles (random colors).gif|300px]]
=== Glow === <!--T:50-->
<!--T:51-->
This property allows you to define whether the particles will be visible in the dark or not ...
<!--T:52-->
<syntaxhighlight lang="c#">
    myParticles.glowLevel = 20;
</syntaxhighlight>
<!--T:53-->
[[File:Particles (glowing).gif|300px]]
<!--T:54-->
<syntaxhighlight lang="c#">
    myParticles.glowLevel = 255;
</syntaxhighlight>
<!--T:55-->
[[File:Particles (glowing brightest).gif|300px]]


=== Gravity === <!--T:56-->
=== Gravity === <!--T:56-->
Line 200: Line 179:
<!--T:58-->
<!--T:58-->
<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
     myParticles.gravityEffect = 0.1F;
     myParticles.GravityEffect = 0.1F;
</syntaxhighlight>
</syntaxhighlight>


Line 216: Line 195:
<!--T:63-->
<!--T:63-->
<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
     myParticles.minSize = 0.1F;
     myParticles.MinSize = 0.1F;
     myParticles.maxSize = 1.0F;
     myParticles.MaxSize = 1.0F;
</syntaxhighlight>
</syntaxhighlight>


Line 228: Line 207:
<!--T:66-->
<!--T:66-->
<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
     myParticles.minSize = 0.1F;
     myParticles.MinSize = 0.1F;
     myParticles.maxSize = 1.0F;
     myParticles.MaxSize = 1.0F;
     myParticles.SizeEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEAR, 2);
     myParticles.SizeEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEAR, 2);
</syntaxhighlight>
</syntaxhighlight>
Line 246: Line 225:
<!--T:71-->
<!--T:71-->
<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
     myParticles.model = EnumParticleModel.Quad;
     myParticles.ParticleModel = EnumParticleModel.Quad;
</syntaxhighlight>
</syntaxhighlight>


Line 259: Line 238:
<!--T:75-->
<!--T:75-->
<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
     myParticles.color = ColorUtil.ToRGBABytes(ColorUtil.ColorFromArgb(130, rand.Next(0, 255), rand.Next(0, 255), rand.Next(0, 255)));
     myParticles.Color = ColorUtil.ColorFromRgba(rand.Next(0, 255), rand.Next(0, 255), rand.Next(0, 255), 130);
</syntaxhighlight>
</syntaxhighlight>


Line 283: Line 262:
<!--T:82-->
<!--T:82-->
<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
     myParticles.minVelocity = new Vec3f((float) (rand.NextDouble() - 0.5), 1f, (float) (rand.NextDouble() - 0.5));
     myParticles.MinVelocity = new Vec3f((float) (rand.NextDouble() - 0.5), 1f, (float) (rand.NextDouble() - 0.5));
     myParticles.SelfPropelled = true;
     myParticles.SelfPropelled = true;
</syntaxhighlight>
</syntaxhighlight>
Line 293: Line 272:


<!--T:85-->
<!--T:85-->
This property is useful for particles in water, which should disappear once they reach the surface (die in liquid). Of course this can also be used the other way round (die in air).
This property is useful for particles in water, which should disappear once they reach the surface (die in liquid). Of course this can also be used the other way round (die in air).<syntaxhighlight lang="c#">
    myParticles.ShouldDieInAir = true;
    myParticles.ShouldDieInLiquid = true;
    myParticles.ShouldSwimOnLiquid = true;
</syntaxhighlight>


</translate>
</translate>


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