Beispiel #1
0
        public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling)
        {
            if (blockSel == null)
            {
                return;
            }

            Block block = api.World.BlockAccessor.GetBlock(blockSel.Position);

            if (block is BlockStaticTranslocator)
            {
                return;
            }

            if (byEntity.World is IClientWorldAccessor)
            {
                IClientWorldAccessor world = byEntity.World as IClientWorldAccessor;
                ILoadedSound         sound;
                byEntity.World.Api.ObjectCache["temporalGearSound"] = sound = world.LoadSound(new SoundParams()
                {
                    Location        = new AssetLocation("sounds/effect/gears.ogg"),
                    ShouldLoop      = true,
                    Position        = blockSel.Position.ToVec3f().Add(0.5f, 0.25f, 0.5f),
                    DisposeOnFinish = false,
                    Volume          = 1f,
                    Pitch           = 0.7f
                });

                sound?.Start();

                byEntity.World.RegisterCallback((dt) =>
                {
                    // Make sure the sound is stopped
                    if (byEntity.Controls.HandUse == EnumHandInteract.None)
                    {
                        sound?.Stop();
                        sound?.Dispose();
                    }
                }, 3600);

                byEntity.World.RegisterCallback((dt) =>
                {
                    // Make sure the sound is stopped
                    if (byEntity.Controls.HandUse == EnumHandInteract.None)
                    {
                        sound?.Stop();
                        sound?.Dispose();
                    }
                }, 20);
            }

            handHandling = EnumHandHandling.PreventDefault;
        }