Modding:Advanced Blocks: Difference between revisions

From Vintage Story Wiki
No edit summary
Line 94: Line 94:
</syntaxhighlight>
</syntaxhighlight>


Although this code works already, some sound effects would be rather nice. This will played every time an entity bounces:
Although this code works already, some sound effects would be rather nice. We can implement it by adding a sound link field to our block, which can use to play the <code>game:tick</code> sound.


<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
entity.PlayEntitySound("tick", EnumAppSide.Server);
public AssetLocation tickSound = new AssetLocation("game", "tick");
</syntaxhighlight>
 
This <code>tickSound</code> will played every time an entity bounces:
 
<syntaxhighlight lang="c#">
world.PlaySoundAt(tickSound, entity.Pos.X, entity.Pos.Y, entity.Pos.Z);
</syntaxhighlight>
</syntaxhighlight>


Line 112: Line 118:
     public class TrampolineMod : ModBase
     public class TrampolineMod : ModBase
     {
     {
         public override void Start(ICoreAPI api)
         public override void Start(ICoreAPI api)
         {
         {
Line 121: Line 128:
     public class TrampolineBlock : Block
     public class TrampolineBlock : Block
     {
     {
         public override void onEntityCollide(IWorldAccessor world, Entity entity, BlockPos pos, BlockFacing facing, bool isImpact)
        public AssetLocation tickSound = new AssetLocation("game", "tick");
 
         public override void OnEntityCollide(IWorldAccessor world, Entity entity, BlockPos pos, BlockFacing facing, bool isImpact)
         {
         {
             if (isImpact && facing.Axis == EnumAxis.Y)
             if (isImpact && facing.Axis == EnumAxis.Y)
             {
             {
                 entity.PlayEntitySound("tick", EnumAppSide.Server);
                 world.PlaySoundAt(tickSound, entity.Pos.X, entity.Pos.Y, entity.Pos.Z);
                 entity.Pos.Motion.Y *= -0.8;
                 entity.Pos.Motion.Y *= -0.8;
             }
             }
Confirmedusers, editor, Administrators
886

edits