Beispiel #1
0
        private void onClientTick(float dt)
        {
            if (!riftsEnabled)
            {
                return;
            }

            Vec3d plrPos = capi.World.Player.Entity.Pos.XYZ;

            nearestRifts = rifts.OrderBy(rift => rift.Position.SquareDistanceTo(plrPos)).ToArray();

            for (int i = 0; i < Math.Min(4, nearestRifts.Length); i++)
            {
                Rift         rift  = nearestRifts[i];
                ILoadedSound sound = riftSounds[i];
                if (!sound.IsPlaying)
                {
                    sound.Start();
                    sound.PlaybackPosition = sound.SoundLengthSeconds * (float)capi.World.Rand.NextDouble();
                }

                sound.SetVolume(GameMath.Clamp(rift.GetNowSize(capi) / 3f, 0.1f, 1f));
                sound.SetPosition((float)rift.Position.X, (float)rift.Position.Y, (float)rift.Position.Z);
            }

            for (int i = nearestRifts.Length; i < 4; i++)
            {
                if (riftSounds[i].IsPlaying)
                {
                    riftSounds[i].Stop();
                }
            }
        }
        private void OnClientTick(float dt)
        {
            if (capi.World.ElapsedMilliseconds - lastTeleCollideMsOwnPlayer > 100)
            {
                teleVolume = Math.Max(0, teleVolume - 2 * dt);
            }
            else
            {
                teleVolume = Math.Min(0.5f, teleVolume + dt / 3);
            }

            teleportingSound.SetVolume(teleVolume);

            if (teleportingSound.IsPlaying)
            {
                if (teleVolume <= 0)
                {
                    teleportingSound.Stop();
                }
            }
            else
            {
                if (teleVolume > 0)
                {
                    teleportingSound.Start();
                }
            }



            if (capi.World.ElapsedMilliseconds - lastTranslocateCollideMsOwnPlayer > 200)
            {
                translocVolume = Math.Max(0, translocVolume - 2 * dt);
                translocPitch  = Math.Max(translocPitch - dt, 0.5f);
            }
            else
            {
                translocVolume = Math.Min(0.5f, translocVolume + dt / 3);
                translocPitch  = Math.Min(translocPitch + dt / 3, 2.5f);
                capi.World.ShakeCamera(0.0575f);
            }

            translocatingSound.SetVolume(translocVolume);
            translocatingSound.SetPitch(translocPitch);

            if (translocatingSound.IsPlaying)
            {
                if (translocVolume <= 0)
                {
                    translocatingSound.Stop();
                }
            }
            else
            {
                if (translocVolume > 0)
                {
                    translocatingSound.Start();
                }
            }
        }
 /// <summary>
 /// Updates the volume of the current track provided Sound is not null. (effectively calls Sound.SetVolume)
 /// </summary>
 public void UpdateVolume()
 {
     if (Sound != null)
     {
         Sound.SetVolume();
     }
 }
        private void OnClientTick(float dt)
        {
            if (capi.World.ElapsedMilliseconds - lastCollideMsOwnPlayer > 100)
            {
                volume = Math.Max(0, volume - 2 * dt);
            }
            else
            {
                volume = Math.Min(1, volume + dt / 3);
            }

            teleportingSound.SetVolume(volume);

            if (teleportingSound.IsPlaying)
            {
                if (volume <= 0)
                {
                    teleportingSound.Stop();
                }
            }
            else
            {
                if (volume > 0)
                {
                    teleportingSound.Start();
                }
            }
        }
 public void SetCookingSoundVolume(float volume)
 {
     if (volume > 0)
     {
         if (cookingSound == null)
         {
             cookingSound = capi.World.LoadSound(new SoundParams()
             {
                 Location        = new AssetLocation("sounds/effect/cooking.ogg"),
                 ShouldLoop      = true,
                 Position        = pos.ToVec3f().Add(0.5f, 0.25f, 0.5f),
                 DisposeOnFinish = false,
                 Volume          = volume
             });
             cookingSound.Start();
         }
         else
         {
             cookingSound.SetVolume(volume);
         }
     }
     else
     {
         if (cookingSound != null)
         {
             cookingSound.Stop();
             cookingSound.Dispose();
             cookingSound = null;
         }
     }
 }
Beispiel #6
0
        private void Every100ms(float dt)
        {
            float grindSpeed = GrindSpeed;

            if (Api.Side == EnumAppSide.Client)
            {
                if (InputStack != null)
                {
                    float dustMinQ      = 1 * grindSpeed;
                    float dustAddQ      = 5 * grindSpeed;
                    float flourPartMinQ = 1 * grindSpeed;
                    float flourPartAddQ = 20 * grindSpeed;

                    FlourDustParticles.Color       = FlourParticles.Color = InputStack.Collectible.GetRandomColor(Api as ICoreClientAPI, InputStack);
                    FlourDustParticles.Color      &= 0xffffff;
                    FlourDustParticles.Color      |= (200 << 24);
                    FlourDustParticles.MinQuantity = dustMinQ;
                    FlourDustParticles.AddQuantity = dustAddQ;
                    FlourDustParticles.MinPos.Set(Pos.X - 1 / 32f, Pos.Y + 11 / 16f, Pos.Z - 1 / 32f);
                    FlourDustParticles.MinVelocity.Set(-0.1f, 0, -0.1f);
                    FlourDustParticles.AddVelocity.Set(0.2f, 0.2f, 0.2f);

                    FlourParticles.MinPos.Set(Pos.X - 1 / 32f, Pos.Y + 11 / 16f, Pos.Z - 1 / 32f);
                    FlourParticles.AddQuantity = flourPartAddQ;
                    FlourParticles.MinQuantity = flourPartMinQ;

                    Api.World.SpawnParticles(FlourParticles);
                    Api.World.SpawnParticles(FlourDustParticles);
                }

                if (ambientSound != null && automated)
                {
                    ambientSound.SetPitch((0.5f + mpc.TrueSpeed) * 0.9f);
                    ambientSound.SetVolume(Math.Min(1f, mpc.TrueSpeed * 3f));
                }

                return;
            }


            // Only tick on the server and merely sync to client

            // Use up fuel
            if (CanGrind() && grindSpeed > 0)
            {
                inputGrindTime += dt * grindSpeed;

                if (inputGrindTime >= maxGrindingTime())
                {
                    grindInput();
                    inputGrindTime = 0;
                }

                MarkDirty();
            }
        }
        protected virtual void HandleSoundClient(float dt)
        {
            var  capi             = Api as ICoreClientAPI;
            bool ownTranslocate   = !(capi.World.ElapsedMilliseconds - lastOwnPlayerCollideMs > 200);
            bool otherTranslocate = !(capi.World.ElapsedMilliseconds - lastEntityCollideMs > 200);

            if (ownTranslocate || otherTranslocate)
            {
                translocVolume = Math.Min(0.5f, translocVolume + dt / 3);
                translocPitch  = Math.Min(translocPitch + dt / 3, 2.5f);
                if (ownTranslocate)
                {
                    capi.World.AddCameraShake(0.0575f);
                }
            }
            else
            {
                translocVolume = Math.Max(0, translocVolume - 2 * dt);
                translocPitch  = Math.Max(translocPitch - dt, 0.5f);
            }


            if (translocatingSound.IsPlaying)
            {
                translocatingSound.SetVolume(translocVolume);
                translocatingSound.SetPitch(translocPitch);
                if (translocVolume <= 0)
                {
                    translocatingSound.Stop();
                }
            }
            else
            {
                if (translocVolume > 0)
                {
                    translocatingSound.Start();
                }
            }
        }
Beispiel #8
0
        protected virtual void HandleSoundClient(float dt)
        {
            var capi = Api as ICoreClientAPI;

            long msEllapsed = capi.World.ElapsedMilliseconds - lastEntityCollideMs;

            if (msEllapsed > 100)
            {
                teleSoundVolume = Math.Max(0, teleSoundVolume - 2 * dt);
                teleSoundPitch  = Math.Max(0.7f, teleSoundPitch - 2 * dt);
            }
            else
            {
                teleSoundVolume = Math.Min(0.5f, teleSoundVolume + dt / 3);
                teleSoundPitch  = Math.Min(6, teleSoundPitch + dt);
            }

            if (teleportingSound != null)
            {
                teleportingSound.SetVolume(teleSoundVolume);
                teleportingSound.SetPitch(teleSoundPitch);

                if (teleportingSound.IsPlaying)
                {
                    if (teleSoundVolume <= 0)
                    {
                        teleportingSound.Stop();
                    }
                }
                else
                {
                    if (teleSoundVolume > 0)
                    {
                        teleportingSound.Start();
                    }
                }
            }
        }
Beispiel #9
0
        private void updateSounds(float dt)
        {
            float targetRainVolumeLeafy    = 0;
            float targetRainVolumeLeafless = 0;
            float targetHailVolume         = 0;
            float targetTrembleVolume      = 0;

            float targetRainPitch = 1;
            float targetHailPitch = 1;

            WeatherDataSnapshot weatherData = weatherSys.BlendedWeatherData;

            if (searchComplete)
            {
                EntityPlayer eplr = capi.World.Player.Entity;
                plrPos.Set((int)eplr.Pos.X, (int)eplr.Pos.Y, (int)eplr.Pos.Z);
                searchComplete = false;

                TyronThreadPool.QueueTask(() =>
                {
                    float val           = (float)Math.Pow(Math.Max(0, (capi.World.BlockAccessor.GetDistanceToRainFall(plrPos, 12, 4) - 2) / 10f), 2);
                    roomVolumePitchLoss = GameMath.Clamp(val, 0, 1);
                    searchComplete      = true;
                });
            }

            EnumPrecipitationType precType = weatherData.BlendedPrecType;

            if (precType == EnumPrecipitationType.Auto)
            {
                precType = weatherSys.clientClimateCond?.Temperature < weatherData.snowThresholdTemp ? EnumPrecipitationType.Snow : EnumPrecipitationType.Rain;
            }

            float nearbyLeaviness = GameMath.Clamp(GlobalConstants.CurrentNearbyRelLeavesCountClient * 60, 0, 1);

            ClimateCondition conds = weatherSys.clientClimateCond;

            if (conds.Rainfall > 0)
            {
                if (precType == EnumPrecipitationType.Rain || weatherSys.clientClimateCond.Temperature < weatherData.snowThresholdTemp)
                {
                    targetRainVolumeLeafy = nearbyLeaviness * GameMath.Clamp(conds.Rainfall * 2f - Math.Max(0, 2f * (weatherData.snowThresholdTemp - weatherSys.clientClimateCond.Temperature)), 0, 1);
                    targetRainVolumeLeafy = GameMath.Max(0, targetRainVolumeLeafy - roomVolumePitchLoss);

                    targetRainVolumeLeafless = Math.Max(0.3f, 1 - nearbyLeaviness) * GameMath.Clamp(conds.Rainfall * 2f - Math.Max(0, 2f * (weatherData.snowThresholdTemp - weatherSys.clientClimateCond.Temperature)), 0, 1);
                    targetRainVolumeLeafless = GameMath.Max(0, targetRainVolumeLeafless - roomVolumePitchLoss);

                    targetRainPitch = Math.Max(0.7f, 1.25f - conds.Rainfall * 0.7f);
                    targetRainPitch = Math.Max(0, targetRainPitch - roomVolumePitchLoss / 4f);

                    targetTrembleVolume = GameMath.Clamp(conds.Rainfall * 1.6f - 0.8f - roomVolumePitchLoss * 0.25f, 0, 1);

                    if (!rainSoundsOn && (targetRainVolumeLeafy > 0.01 || targetRainVolumeLeafless > 0.01))
                    {
                        for (int i = 0; i < rainSoundsLeafless.Length; i++)
                        {
                            rainSoundsLeafless[i]?.Start();
                        }
                        for (int i = 0; i < rainSoundsLeafy.Length; i++)
                        {
                            rainSoundsLeafy[i]?.Start();
                        }

                        lowTrembleSound?.Start();
                        rainSoundsOn = true;

                        curRainPitch = targetRainPitch;
                    }

                    if (capi.World.Player.Entity.IsEyesSubmerged())
                    {
                        curRainPitch              = targetRainPitch / 2;
                        targetRainVolumeLeafy    *= 0.75f;
                        targetRainVolumeLeafless *= 0.75f;
                    }
                }

                if (precType == EnumPrecipitationType.Hail)
                {
                    targetHailVolume = GameMath.Clamp(conds.Rainfall * 2f - roomVolumePitchLoss, 0, 1);
                    targetHailVolume = GameMath.Max(0, targetHailVolume - roomVolumePitchLoss);

                    targetHailPitch = Math.Max(0.7f, 1.25f - conds.Rainfall * 0.7f);
                    targetHailPitch = Math.Max(0, targetHailPitch - roomVolumePitchLoss / 4f);

                    if (!hailSoundsOn && targetHailVolume > 0.01)
                    {
                        hailSound?.Start();
                        hailSoundsOn = true;
                        curHailPitch = targetHailPitch;
                    }
                }
            }


            curRainVolumeLeafy    += (targetRainVolumeLeafy - curRainVolumeLeafy) * dt / 2;
            curRainVolumeLeafless += (targetRainVolumeLeafless - curRainVolumeLeafless) * dt / 2;

            curTrembleVolume += (targetTrembleVolume - curTrembleVolume) * dt;
            curHailVolume    += (targetHailVolume - curHailVolume) * dt;

            curHailPitch += (targetHailPitch - curHailPitch) * dt;
            curRainPitch += (targetRainPitch - curRainPitch) * dt;



            if (rainSoundsOn)
            {
                for (int i = 0; i < rainSoundsLeafless.Length; i++)
                {
                    rainSoundsLeafless[i]?.SetVolume(curRainVolumeLeafless);
                    rainSoundsLeafless[i]?.SetPitch(curRainPitch);
                }
                for (int i = 0; i < rainSoundsLeafy.Length; i++)
                {
                    rainSoundsLeafy[i]?.SetVolume(curRainVolumeLeafy);
                    rainSoundsLeafy[i]?.SetPitch(curRainPitch);
                }

                lowTrembleSound?.SetVolume(curTrembleVolume);
            }
            if (hailSoundsOn)
            {
                hailSound?.SetVolume(curHailVolume);
                hailSound?.SetPitch(curHailPitch);
            }


            if (curRainVolumeLeafless < 0.01 && curRainVolumeLeafy < 0.01)
            {
                for (int i = 0; i < rainSoundsLeafless.Length; i++)
                {
                    rainSoundsLeafless[i]?.Stop();
                }
                for (int i = 0; i < rainSoundsLeafy.Length; i++)
                {
                    rainSoundsLeafy[i]?.Stop();
                }
                rainSoundsOn = false;
            }

            if (curHailVolume < 0.01)
            {
                hailSound?.Stop();
                hailSoundsOn = false;
            }



            float wstr = (1 - roomVolumePitchLoss) * weatherData.curWindSpeed.X - 0.3f;

            if (wstr > 0.03f || curWindVolumeLeafy > 0.01f || curWindVolumeLeafless > 0.01f)
            {
                if (!windSoundsOn)
                {
                    windSoundLeafy?.Start();
                    windSoundLeafless?.Start();
                    windSoundsOn = true;
                }

                float targetVolumeLeafy    = nearbyLeaviness * 1.2f * wstr;
                float targetVolumeLeafless = (1 - nearbyLeaviness) * 1.2f * wstr;

                curWindVolumeLeafy    += (targetVolumeLeafy - curWindVolumeLeafy) * dt;
                curWindVolumeLeafless += (targetVolumeLeafless - curWindVolumeLeafless) * dt;

                windSoundLeafy?.SetVolume(curWindVolumeLeafy);
                windSoundLeafless?.SetVolume(curWindVolumeLeafless);
            }
            else
            {
                if (windSoundsOn)
                {
                    windSoundLeafy?.Stop();
                    windSoundLeafless?.Stop();
                    windSoundsOn = false;
                }
            }
        }