Confirmedusers
553
edits
Mirotworez (talk | contribs) (Undo revision 55421 by Mirotworez (talk)) Tag: Undo |
m (Updated to 1.19.3. Now using new, non-obselete command API.) |
||
Line 1: | Line 1: | ||
<languages/> | <languages/> | ||
{{GameVersion|1. | {{GameVersion|1.19.3}} | ||
<translate> | <translate> | ||
<!--T:1--> | <!--T:1--> | ||
Line 8: | Line 8: | ||
<!--T:3--> | <!--T:3--> | ||
The idea is to add a command which makes it easier for your | The idea is to add a command which makes it easier for your friends to locate you. Therefore we will spawn some particles alongside a playing sound, so others can see and hear where you are at the moment. | ||
== Implementation == <!--T:7--> | |||
As always, we need to create a class extending <code>ModSystem</code>: | |||
== Implementation == | |||
<!--T:7--> | |||
As always we need to create a class extending <code>ModSystem</code>: | |||
<syntaxhighlight lang="c#"> | <syntaxhighlight lang="c#"> | ||
public class CommandMod : ModSystem | public class CommandMod : ModSystem | ||
Line 29: | Line 21: | ||
<!--T:9--> | <!--T:9--> | ||
We will be creating a server-side command, so our mod only needs to load on the server's side: | |||
<syntaxhighlight lang="c#"> | <syntaxhighlight lang="c#"> | ||
public override bool ShouldLoad(EnumAppSide side) | public override bool ShouldLoad(EnumAppSide side) | ||
Line 38: | Line 30: | ||
<!--T:10--> | <!--T:10--> | ||
Now we need to | Now we need to create the command itself: | ||
<syntaxhighlight lang="c#"> | <syntaxhighlight lang="c#"> | ||
public override void StartServerSide(ICoreServerAPI api) | public override void StartServerSide(ICoreServerAPI api) | ||
{ | { | ||
base.StartServerSide(api); | base.StartServerSide(api); | ||
api. | AssetLocation sound = new AssetLocation("here", "sounds/partyhorn"); | ||
api.ChatCommands.Create("here") | |||
.WithDescription("spawns particles around the player") | |||
.RequiresPrivilege(Privilege.chat) | |||
.RequiresPlayer(); | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 60: | Line 51: | ||
{ | { | ||
base.StartServerSide(api); | base.StartServerSide(api); | ||
AssetLocation sound = new AssetLocation("here", "sounds/partyhorn"); | AssetLocation sound = new AssetLocation("here", "sounds/partyhorn"); | ||
api. | api.ChatCommands.Create("here") | ||
.WithDescription("spawns particles around the player") | |||
.RequiresPrivilege(Privilege.chat) | |||
.RequiresPlayer() | |||
.HandleWith((args) => | |||
{ | |||
var byEntity = args.Caller.Entity; | |||
Vec3d pos = byEntity.Pos.XYZ.Add(0, byEntity. | byEntity.World.PlaySoundAt(sound, byEntity); | ||
Vec3d pos = byEntity.Pos.XYZ.Add(0, byEntity.LocalEyePos.Y, 0); | |||
Random rand = new Random(); | |||
for (int i = 0; i < 100; i++) | |||
{ | |||
Vec3d realPos = pos.AddCopy(-0.1 + rand.NextDouble() * 0.2, 0, -0.1 + rand.NextDouble() * 0.2); | |||
Vec3f velocity = new Vec3f(-0.2F + (float)rand.NextDouble() * 0.4F, 0.4F + (float)rand.NextDouble() * 2F, -0.2F + (float)rand.NextDouble() * 0.4F); | |||
byEntity.World.SpawnParticles(1, ColorUtil.ToRgba(255, rand.Next(0, 255), rand.Next(0, 255), rand.Next(0, 255)), | |||
realPos, realPos, | |||
velocity, velocity, (float)rand.NextDouble() * 1 + 1, 0.01F, | |||
1, EnumParticleModel.Cube); | |||
} | |||
return TextCommandResult.Success(); | |||
}); | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 93: | Line 86: | ||
<!--T:18--> | <!--T:18--> | ||
<youtube>XjHMtl6rSF4</youtube> | <youtube>XjHMtl6rSF4</youtube> | ||
</translate> | </translate> | ||
{{Navbox/modding|Vintage Story}} | {{Navbox/modding|Vintage Story}} |