示例#1
0
        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 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;
            }
        }