Modding:Block and Item Interactions: Difference between revisions

From Vintage Story Wiki
no edit summary
No edit summary
No edit summary
(8 intermediate revisions by 3 users not shown)
Line 1: Line 1:
__FORCETOC__
{{GameVersion|1.13}}
This tutorial should introduce you into the basics of custom interactions. We will create a magic wand which should spawn particles when holding right click.
This tutorial should introduce you into the basics of custom interactions. We will create a magic wand which should spawn particles when holding right click.


== Preparations ==
= Preparations =


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].
Line 63: Line 66:
         public static SimpleParticleProperties particles = new SimpleParticleProperties(
         public static SimpleParticleProperties particles = new SimpleParticleProperties(
                     1, 1,
                     1, 1,
                     ColorUtil.ColorFromArgb(50, 220, 220, 220),
                     ColorUtil.ColorFromRgba(220, 220, 220, 50),
                     new Vec3d(),
                     new Vec3d(),
                     new Vec3d(),
                     new Vec3d(),
Line 89: Line 92:
<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
                     Vec3d pos =
                     Vec3d pos =
                             byEntity.Pos.XYZ.Add(0, byEntity.EyeHeight(), 0)
                             byEntity.Pos.XYZ.Add(0, byEntity.LocalEyePos.Y, 0)
                             .Ahead(1f, byEntity.Pos.Pitch, byEntity.Pos.Yaw)
                             .Ahead(1f, byEntity.Pos.Pitch, byEntity.Pos.Yaw)
                         ;
                         ;


                     Vec3f speedVec = new Vec3d(0, 0, 0).Ahead(5, byEntity.Pos.Pitch, byEntity.Pos.Yaw).ToVec3f();
                     Vec3f speedVec = new Vec3d(0, 0, 0).Ahead(5, byEntity.Pos.Pitch, byEntity.Pos.Yaw).ToVec3f();
                     particles.minVelocity = speedVec;
                     particles.MinVelocity = speedVec;
                     Random rand = new Random();
                     Random rand = new Random();
                     particles.color = ColorUtil.ToRGBABytes(ColorUtil.ColorFromArgb(255, rand.Next(0, 255), rand.Next(0, 255), rand.Next(0, 255)));
                     particles.Color = ColorUtil.ColorFromRgba(rand.Next(0, 255), rand.Next(0, 255), rand.Next(0, 255), 255);
                     particles.minPos = pos.AddCopy(-0.05, -0.05, -0.05);
                     particles.MinPos = pos.AddCopy(-0.05, -0.05, -0.05);
                     particles.addPos.Set(0.1, 0.1, 0.1);
                     particles.AddPos.Set(0.1, 0.1, 0.1);
                     particles.minSize = 0.1F;
                     particles.MinSize = 0.1F;
                     particles.SizeEvolve = EvolvingNatFloat.create(EnumTransformFunction.SINUS, 10);
                     particles.SizeEvolve = EvolvingNatFloat.create(EnumTransformFunction.SINUS, 10);
                     byEntity.World.SpawnParticles(particles);
                     byEntity.World.SpawnParticles(particles);
Line 121: Line 124:
                 {
                 {
                     Vec3d pos =
                     Vec3d pos =
                             byEntity.Pos.XYZ.Add(0, byEntity.EyeHeight, 0)
                             byEntity.Pos.XYZ.Add(0, byEntity.LocalEyePos.Y, 0)
                             .Ahead(1f, byEntity.Pos.Pitch, byEntity.Pos.Yaw)
                             .Ahead(1f, byEntity.Pos.Pitch, byEntity.Pos.Yaw)
                         ;
                         ;


                     Vec3f speedVec = new Vec3d(0, 0, 0).Ahead(5, byEntity.Pos.Pitch, byEntity.Pos.Yaw).ToVec3f();
                     Vec3f speedVec = new Vec3d(0, 0, 0).Ahead(5, byEntity.Pos.Pitch, byEntity.Pos.Yaw).ToVec3f();
                     particles.minVelocity = speedVec;
                     particles.MinVelocity = speedVec;
                     Random rand = new Random();
                     Random rand = new Random();
                     particles.color = ColorUtil.ToRgba(255, rand.Next(0, 255), rand.Next(0, 255), rand.Next(0, 255));
                     particles.Color = ColorUtil.ColorFromRgba(rand.Next(0, 255), rand.Next(0, 255), rand.Next(0, 255), 255);
                     particles.minPos = pos.AddCopy(-0.05, -0.05, -0.05);
                     particles.MinPos = pos.AddCopy(-0.05, -0.05, -0.05);
                     particles.addPos.Set(0.1, 0.1, 0.1);
                     particles.AddPos.Set(0.1, 0.1, 0.1);
                     particles.minSize = 0.1F;
                     particles.MinSize = 0.1F;
                     particles.SizeEvolve = EvolvingNatFloat.create(EnumTransformFunction.SINUS, 10);
                     particles.SizeEvolve = EvolvingNatFloat.create(EnumTransformFunction.SINUS, 10);
                     byEntity.World.SpawnParticles(particles);
                     byEntity.World.SpawnParticles(particles);
Line 146: Line 149:
<youtube>bTPXL97Gfns</youtube>
<youtube>bTPXL97Gfns</youtube>


== Download ==
= Mod Download =


Feel free to try it out yourself:
Feel free to try it out yourself:
Confirmedusers, Bureaucrats, editor, Administrators
1,778

edits