Exemplo n.º 1
0
 void Events_ContactCreated(EntityCollidable sender, Collidable other, CollidablePairHandler pair, ContactData contact)
 {
     if (TheRegion.GlobalTickTimeLocal - lastSoundTime < soundmaxrate)
     {
         return;
     }
     lastSoundTime = TheRegion.GlobalTickTimeLocal;
     if (other is FullChunkObject)
     {
         ((ConvexFCOPairHandler)pair).ContactInfo(/*contact.Id*/ 0, out ContactInformation info);
         float vellen = (float)(Math.Abs(info.RelativeVelocity.X) + Math.Abs(info.RelativeVelocity.Y) + Math.Abs(info.RelativeVelocity.Z));
         float mod    = vellen / 5;
         if (mod > 2)
         {
             mod = 2;
         }
         Location      block = new Location(contact.Position - contact.Normal * 0.01f);
         BlockInternal bi    = TheRegion.GetBlockInternal(block);
         MaterialSound sound = ((Material)bi.BlockMaterial).Sound();
         if (sound != MaterialSound.NONE)
         {
             new DefaultSoundPacketIn()
             {
                 TheClient = TheClient
             }.PlayDefaultBlockSound(block, sound, mod, 0.5f * mod);
         }
         MaterialSound sound2 = Mat.Sound();
         if (sound2 != MaterialSound.NONE)
         {
             new DefaultSoundPacketIn()
             {
                 TheClient = TheClient
             }.PlayDefaultBlockSound(block, sound2, mod, 0.5f * mod);
         }
     }
     else if (other is EntityCollidable)
     {
         BEPUphysics.Entities.Entity e        = ((EntityCollidable)other).Entity;
         BEPUutilities.Vector3       velocity = BEPUutilities.Vector3.Zero;
         if (e != null)
         {
             velocity = e.LinearVelocity;
         }
         BEPUutilities.Vector3 relvel = Body.LinearVelocity - velocity;
         float vellen = (float)(Math.Abs(relvel.X) + Math.Abs(relvel.Y) + Math.Abs(relvel.Z));
         float mod    = vellen / 5;
         if (mod > 2)
         {
             mod = 2;
         }
         MaterialSound sound = Mat.Sound();
         if (sound != MaterialSound.NONE)
         {
             new DefaultSoundPacketIn()
             {
                 TheClient = TheClient
             }.PlayDefaultBlockSound(new Location(contact.Position), sound, mod, 0.5f * mod);
         }
     }
 }