private void updateSoundsAndEffects(double hereStability, double ownStability) { if (!isSelf || tempStabSoundDrain == null) { return; } // Effects float fadeSpeed = 3f; // Sounds if (hereStability < 0.95f && ownStability < 0.65f) { if (!tempStabSoundDrain.IsPlaying) { tempStabSoundDrain.Start(); } tempStabSoundDrain.FadeTo(Math.Min(1, 3 * (1 - hereStability)), 0.95f * fadeSpeed, (s) => { }); } else { tempStabSoundDrain.FadeTo(0, 0.95f * fadeSpeed, (s) => { tempStabSoundDrain.Stop(); }); } SurfaceMusicTrack.ShouldPlayMusic = ownStability > 0.45f; CaveMusicTrack.ShouldPlayCaveMusic = ownStability > 0.2f; if (ownStability < 0.4f) { if (!tempStabSoundLow.IsPlaying) { tempStabSoundLow.Start(); } float volume = (0.4f - (float)ownStability) * 1 / 0.4f; tempStabSoundLow.FadeTo(Math.Min(1, volume), 0.95f * fadeSpeed, (s) => { }); } else { tempStabSoundLow.FadeTo(0, 0.95f * fadeSpeed, (s) => { tempStabSoundLow.Stop(); }); } if (ownStability < 0.25f) { if (!tempStabSoundVeryLow.IsPlaying) { tempStabSoundVeryLow.Start(); } float volume = (0.25f - (float)ownStability) * 1 / 0.25f; tempStabSoundVeryLow.FadeTo(Math.Min(1, volume) / 5f, 0.95f * fadeSpeed, (s) => { }); } else { tempStabSoundVeryLow.FadeTo(0, 0.95f * fadeSpeed, (s) => { tempStabSoundVeryLow.Stop(); }); } }
public override void Initialize(ICoreAPI api) { base.Initialize(api); RegisterGameTickListener(OnTick, 25); RegisterGameTickListener(OnSlowTick, 1000); fireBlock = api.World.GetBlock(new AssetLocation("fire")); if (fireBlock == null) { fireBlock = new Block(); } neibBlock = api.World.BlockAccessor.GetBlock(Pos.AddCopy(fromFacing.Opposite)); wsys = api.ModLoader.GetModSystem <WeatherSystemBase>(); if (ambientSound == null && api.Side == EnumAppSide.Client) { ambientSound = ((IClientWorldAccessor)api.World).LoadSound(new SoundParams() { Location = new AssetLocation("sounds/environment/fire.ogg"), ShouldLoop = true, Position = Pos.ToVec3f().Add(0.5f, 0.25f, 0.5f), DisposeOnFinish = false, Volume = 1f }); if (ambientSound != null) { ambientSound.PlaybackPosition = ambientSound.SoundLengthSeconds * (float)Api.World.Rand.NextDouble(); ambientSound.Start(); } } }
private void initSoundsAndTicking() { fuelBlock = Api.World.BlockAccessor.GetBlock(FuelPos); l1 = Blockentity.RegisterGameTickListener(OnTick, 25); if (Api.Side == EnumAppSide.Server) { l2 = Blockentity.RegisterGameTickListener(OnSlowServerTick, 1000); } wsys = Api.ModLoader.GetModSystem <WeatherSystemBase>(); if (ambientSound == null && Api.Side == EnumAppSide.Client) { ambientSound = ((IClientWorldAccessor)Api.World).LoadSound(new SoundParams() { Location = new AssetLocation("sounds/environment/fire.ogg"), ShouldLoop = true, Position = FirePos.ToVec3f().Add(0.5f, 0.25f, 0.5f), DisposeOnFinish = false, Volume = 1f }); if (ambientSound != null) { ambientSound.PlaybackPosition = ambientSound.SoundLengthSeconds * (float)Api.World.Rand.NextDouble(); ambientSound.Start(); } } particleFacing = BlockFacing.FromNormal(new Vec3i(FirePos.X - FuelPos.X, FirePos.Y - FuelPos.Y, FirePos.Z - FuelPos.Z)); }
public virtual void ToggleAmbientSounds(bool on) { if (Api.Side != EnumAppSide.Client) { return; } if (on) { if (ambientSound == null || !ambientSound.IsPlaying) { ambientSound = ((IClientWorldAccessor)Api.World).LoadSound(new SoundParams() { Location = new AssetLocation("sounds/environment/fireplace.ogg"), ShouldLoop = true, Position = Pos.ToVec3f().Add(0.5f, 0.1f, 0.5f), DisposeOnFinish = false, Volume = 0.66f }); ambientSound.Start(); } } else { ambientSound.Stop(); ambientSound.Dispose(); ambientSound = null; } }
public override void Initialize(ICoreAPI api) { base.Initialize(api); RegisterGameTickListener(OnTick, 25); RegisterGameTickListener(OnSlowTick, 1000); fireBlock = api.World.GetBlock(new AssetLocation("fire")); if (fireBlock == null) { fireBlock = new Block(); } neibBlock = api.World.BlockAccessor.GetBlock(pos.AddCopy(fromFacing.GetOpposite())); if (ambientSound == null && api.Side == EnumAppSide.Client) { RegisterDelayedCallback((dt) => { // When the world loads with a lot of fire they'll all start at the same millisecond, so lets delay a bit ambientSound = ((IClientWorldAccessor)api.World).LoadSound(new SoundParams() { Location = new AssetLocation("sounds/environment/fire.ogg"), ShouldLoop = true, Position = pos.ToVec3f().Add(0.5f, 0.25f, 0.5f), DisposeOnFinish = false, Volume = 1f }); ambientSound?.Start(); }, api.World.Rand.Next(200)); } }
public void UpdateBreakSounds() { if (Api.Side != EnumAppSide.Client) { return; } if (resistance > 0 && bebrake.Engaged && network != null && network.Speed > 0.1) { if (brakeSound == null || !brakeSound.IsPlaying) { brakeSound = ((IClientWorldAccessor)Api.World).LoadSound(new SoundParams() { Location = new AssetLocation("sounds/effect/woodgrind.ogg"), ShouldLoop = true, Position = Position.ToVec3f().Add(0.5f, 0.25f, 0.5f), DisposeOnFinish = false, Volume = 1 }); brakeSound.Start(); } brakeSound.SetPitch(GameMath.Clamp(network.Speed * 1.5f + 0.2f, 0.5f, 1)); } else { brakeSound?.FadeOut(1, (s) => { brakeSound.Stop(); }); } }
private void onTrackLoaded(ILoadedSound sound) { if (track == null) { sound?.Dispose(); return; } if (sound == null) { return; } track.Sound = sound; // Needed so that the music engine does not dispose the sound Api.Event.EnqueueMainThreadTask(() => track.loading = true, "settrackloading"); long longMsPassed = Api.World.ElapsedMilliseconds - startLoadingMs; handlerId = RegisterDelayedCallback((dt) => { if (sound.IsDisposed) { Api.World.Logger.Notification("Echo chamber track is diposed? o.O"); } if (!wasStopped) { sound.Start(); } track.loading = false; }, (int)Math.Max(0, 500 - longMsPassed)); }
public override void OnReceivedServerPacket(int packetid, byte[] data) { if (packetid == 1025) { AssetLocation loc = SerializerUtil.Deserialize <AssetLocation>(data); if (alarmSound == null) { alarmSound = capi.World.LoadSound(new SoundParams() { Location = loc, Position = Pos.XYZ.ToVec3f(), Range = 48, ShouldLoop = true, SoundType = EnumSoundType.Sound, Volume = 0, DisposeOnFinish = false }); } if (!alarmSound.IsPlaying) { alarmSound.Start(); alarmSound.FadeIn(0.25f, null); } } if (packetid == 1026) { alarmSound?.FadeOutAndStop(0.25f); } base.OnReceivedServerPacket(packetid, data); }
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(); } } }
public void ToggleAmbientSounds(bool on) { if (Api.Side != EnumAppSide.Client) { return; } if (on) { if (ambientSound == null || !ambientSound.IsPlaying) { ambientSound = ((IClientWorldAccessor)Api.World).LoadSound(new SoundParams() { Location = new AssetLocation("sounds/environment/fireplace.ogg"), ShouldLoop = true, Position = be.Pos.ToVec3f().Add(0.5f, 0.25f, 0.5f), DisposeOnFinish = false, Volume = SoundLevel }); if (ambientSound != null) { ambientSound.Start(); ambientSound.PlaybackPosition = ambientSound.SoundLengthSeconds * (float)Api.World.Rand.NextDouble(); } } } else { ambientSound?.Stop(); ambientSound?.Dispose(); ambientSound = null; } }
public void PlaySound(float startPitch, float endPitch, float volume) { startPitch *= pitchModifier; endPitch *= pitchModifier; volume *= volumneModifier; SoundParams param = new SoundParams() { Location = soundName, DisposeOnFinish = true, Pitch = startPitch, Volume = volume, Position = entity.Pos.XYZ.ToVec3f().Add(0, (float)entity.EyeHeight, 0), ShouldLoop = false, Range = 8, }; ILoadedSound sound = capi.World.LoadSound(param); if (startPitch != endPitch) { slidingPitchSounds.Add(new SlidingPitchSound() { startPitch = startPitch, endPitch = endPitch, sound = sound, startMs = capi.World.ElapsedMilliseconds }); } sound.Start(); }
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(); } } }
void updateBurningState() { if (!burning) { return; } if (Api.World.Side == EnumAppSide.Client) { if (ambientSound == null || !ambientSound.IsPlaying) { ambientSound = ((IClientWorldAccessor)Api.World).LoadSound(new SoundParams() { Location = new AssetLocation("sounds/effect/embers.ogg"), ShouldLoop = true, Position = Pos.ToVec3f().Add(0.5f, 0.25f, 0.5f), DisposeOnFinish = false, Volume = 1 }); if (ambientSound != null) { ambientSound.PlaybackPosition = ambientSound.SoundLengthSeconds * (float)Api.World.Rand.NextDouble(); ambientSound.Start(); } } listenerId = RegisterGameTickListener(onBurningTickClient, 100); } else { listenerId = RegisterGameTickListener(onBurningTickServer, 10000); } }
public override void Initialize(ICoreAPI api) { base.Initialize(api); bloomeryInv.LateInitialize("bloomery-1", api); RegisterGameTickListener(OnGameTick, 100); if (ambientSound == null && api.Side == EnumAppSide.Client) { ambientSound = ((IClientWorldAccessor)api.World).LoadSound(new SoundParams() { Location = new AssetLocation("sounds/environment/fire.ogg"), ShouldLoop = true, Position = Pos.ToVec3f().Add(0.5f, 0.25f, 0.5f), DisposeOnFinish = false, Volume = 0.3f, Range = 8 }); if (burning) { ambientSound.Start(); } } if (api.Side == EnumAppSide.Client) { ICoreClientAPI capi = (ICoreClientAPI)api; capi.Event.RegisterRenderer(renderer = new BloomeryContentsRenderer(Pos, capi), EnumRenderStage.Opaque, "bloomery"); UpdateRenderer(); } ownFacing = BlockFacing.FromCode(api.World.BlockAccessor.GetBlock(Pos).LastCodePart()); }
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; } } }
void updateGrindingState(bool beforeGrinding) { bool nowGrinding = IsGrinding; if (nowGrinding != beforeGrinding) { if (renderer != null) { renderer.ShouldRotate = nowGrinding; } api.World.BlockAccessor.MarkBlockDirty(pos, OnRetesselated); if (nowGrinding) { ambientSound?.Start(); } else { ambientSound?.Stop(); } if (api.Side == EnumAppSide.Server) { MarkDirty(); } } }
void updateGrindingState() { if (Api?.World == null) { return; } bool nowGrinding = quantityPlayersGrinding > 0 || (automated && mpc.TrueSpeed > 0f); if (nowGrinding != beforeGrinding) { if (renderer != null) { renderer.ShouldRotateManual = quantityPlayersGrinding > 0; } Api.World.BlockAccessor.MarkBlockDirty(Pos, OnRetesselated); if (nowGrinding) { ambientSound?.Start(); } else { ambientSound?.Stop(); } if (Api.Side == EnumAppSide.Server) { MarkDirty(); } } beforeGrinding = nowGrinding; }
public bool TryIgnite() { if (!CanIgnite() || burning) { return(false); } if (!Api.World.BlockAccessor.GetBlock(Pos.UpCopy()).Code.Path.Contains("bloomerychimney")) { return(false); } burning = true; burningUntilTotalDays = Api.World.Calendar.TotalDays + 10 / 24.0; burningStartTotalDays = Api.World.Calendar.TotalDays; MarkDirty(); ambientSound?.Start(); return(true); }
public override void Initialize(EntityProperties properties, ICoreAPI api, long InChunkIndex3d) { if (removedBlockentity != null) { this.blockEntityAttributes = new TreeAttribute(); removedBlockentity.ToTreeAttributes(blockEntityAttributes); blockEntityClass = api.World.ClassRegistry.GetBlockEntityClass(removedBlockentity.GetType()); } SimulationRange = (int)(0.75f * GlobalConstants.DefaultTrackingRange); base.Initialize(properties, api, InChunkIndex3d); // Need to capture this now before we remove the block and start to fall drops = Block.GetDrops(api.World, initialPos, null); lightHsv = Block.GetLightHsv(World.BlockAccessor, initialPos); SidedPos.Motion.Y = -0.02; blockAsStack = new ItemStack(Block); if (api.Side == EnumAppSide.Client && fallSound != null && fallingNow.Count < 100) { fallingNow.Add(EntityId); ICoreClientAPI capi = api as ICoreClientAPI; sound = capi.World.LoadSound(new SoundParams() { Location = fallSound.WithPathPrefixOnce("sounds/").WithPathAppendixOnce(".ogg"), Position = new Vec3f((float)Pos.X, (float)Pos.Y, (float)Pos.Z), Range = 32, Pitch = 0.8f + (float)capi.World.Rand.NextDouble() * 0.3f, Volume = 1, SoundType = EnumSoundType.Ambient }); sound.Start(); soundStartDelay = 0.05f + (float)capi.World.Rand.NextDouble() / 3f; } canFallSideways = WatchedAttributes.GetBool("canFallSideways"); dustIntensity = WatchedAttributes.GetFloat("dustIntensity"); if (WatchedAttributes.HasAttribute("fallSound")) { fallSound = new AssetLocation(WatchedAttributes.GetString("fallSound")); } if (api.World.Side == EnumAppSide.Client) { particleSys = api.ModLoader.GetModSystem <FallingBlockParticlesModSystem>(); particleSys.Register(this); physicsBh = GetBehavior <EntityBehaviorPassivePhysics>(); } }
public bool TryIgnite() { if (!CanIgnite()) { return(false); } burning = true; fuelBurnTime = 45 + FuelSlot.StackSize * 5; //approximately 1 hour of game time for a full stack of fuel MarkDirty(); ambientSound?.Start(); return(true); }
private void SpawnParticles(float dt) { Api.World.SpawnParticles(smokeParticles); Api.World.SpawnParticles(fireCubeParticles); if (!smoulderSound.IsPlaying) { int soundRand = rand.Next(0, 100); if (soundRand <= 1) { smoulderSound.Start(); } } }
internal void OnIgnite(IPlayer byPlayer) { if (lit) { return; } if (api.Side == EnumAppSide.Client) { fuseSound.Start(); } lit = true; remainingSeconds = FuseTimeSeconds; MarkDirty(); }
private void onTrackLoaded(ILoadedSound sound) { if (track == null) { sound?.Dispose(); return; } track.Sound = sound; long longMsPassed = api.World.ElapsedMilliseconds - startLoadingMs; handlerId = RegisterDelayedCallback((dt) => { if (!wasStopped) { sound.Start(); } }, (int)Math.Max(0, 500 - longMsPassed)); }
public override void Initialize(EntityProperties properties, ICoreAPI api, long InChunkIndex3d) { base.Initialize(properties, api, InChunkIndex3d); if (buzzSound == null && World.Side == EnumAppSide.Client) { buzzSound = ((IClientWorldAccessor)World).LoadSound(new SoundParams() { Location = new AssetLocation("sounds/creature/beemob.ogg"), ShouldLoop = true, Position = soundpos = Pos.XYZ.ToVec3f().Add(0.5f, 0.25f, 0.5f), DisposeOnFinish = false, Volume = 0.25f }); buzzSound.Start(); } StartAnimation("enraged"); }
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(); } } }
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(); } } } }
public void PlaySound(float startPitch, float endPitch, float volume) { SoundParams param = new SoundParams() { Location = soundName, DisposeOnFinish = true, Pitch = startPitch, Volume = volume, Position = entity.Pos.XYZ.ToVec3f().Add(0, (float)entity.EyeHeight, 0), ShouldLoop = false, Range = 8, }; if (startPitch != endPitch) { //slidingPitchSounds.Add(new KeyValuePair<ILoadedSound, float>()); } ILoadedSound sound = capi.World.LoadSound(param); sound.Start(); }
private void After350ms(float dt) { ICoreClientAPI capi = api as ICoreClientAPI; IClientPlayer plr = capi.World.Player; EntityPlayer plrentity = plr.Entity; if (plrentity.Controls.HandUse == EnumHandInteract.HeldItemInteract) { capi.World.PlaySoundAt(new AssetLocation("sounds/effect/watering"), plrentity, plr); } if (plrentity.Controls.HandUse == EnumHandInteract.HeldItemInteract) { if (pouringLoop != null) { pouringLoop.FadeIn(0.3f, null); return; } pouringLoop = capi.World.LoadSound(new SoundParams() { DisposeOnFinish = false, Location = new AssetLocation("sounds/effect/watering-loop.ogg"), Position = new Vec3f(), RelativePosition = true, ShouldLoop = true, Range = 16, Volume = 0.2f, Pitch = 0.5f }); pouringLoop.Start(); pouringLoop.FadeIn(0.15f, null); return; } }
public bool TryBeginMilking() { lastIsMilkingStateTotalMs = entity.World.ElapsedMilliseconds; bhmul = entity.GetBehavior <EntityBehaviorMultiply>(); // Can not be milked when stressed (= caused by aggressive or fleeing emotion states) float stressLevel = entity.WatchedAttributes.GetFloat("stressLevel"); if (stressLevel > 0.1) { if (entity.World.Api is ICoreClientAPI capi) { capi.TriggerIngameError(this, "notready", Lang.Get("Currently too stressed to be milkable")); } return(false); } // Can only be milked for 21 days after giving birth double daysSinceBirth = Math.Max(0, entity.World.Calendar.TotalDays - bhmul.TotalDaysLastBirth); if (bhmul != null && daysSinceBirth >= lactatingDaysAfterBirth) { return(false); } // Can only be milked once every day if (entity.World.Calendar.TotalHours - lastMilkedTotalHours < entity.World.Calendar.HoursPerDay) { return(false); } int generation = entity.WatchedAttributes.GetInt("generation", 0); aggroChance = Math.Min(1 - generation / 3f, 0.95f); aggroTested = false; clientCanContinueMilking = true; if (entity.World.Side == EnumAppSide.Server) { AiTaskManager tmgr = entity.GetBehavior <EntityBehaviorTaskAI>().TaskManager; tmgr.StopTask(typeof(AiTaskWander)); tmgr.StopTask(typeof(AiTaskSeekEntity)); tmgr.StopTask(typeof(AiTaskSeekFoodAndEat)); tmgr.StopTask(typeof(AiTaskStayCloseToEntity)); } else { if (entity.World is IClientWorldAccessor cworld) { milkSound?.Dispose(); milkSound = cworld.LoadSound(new SoundParams() { DisposeOnFinish = true, Location = new AssetLocation("sounds/creature/sheep/milking.ogg"), Position = entity.Pos.XYZFloat, SoundType = EnumSoundType.Sound }); milkSound.Start(); } } return(true); }