Exemple #1
0
 public override bool OnHeldInteractStep(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
 {
     if (byEntity.Controls.Sneak)
     {
         return(base.OnHeldInteractStep(secondsUsed, slot, byEntity, blockSel, entitySel));
     }
     if (byEntity.World.Side.IsServer() && sustain && !GetSustainment(byEntity))
     {
         SetSustainment(byEntity, true);
         float normalizedPitch = 1.0f - GameMathExt.Normalize(byEntity.Pos.Pitch, 1.578125f, 4.6875f);
         SetNote(byEntity, (EnumPitch)(int)Math.Round((noteValues.Length - 1) * normalizedPitch));
         PlayNote(byEntity, GetNote(byEntity));
         api.Event.RegisterCallback(dt => SetSustainment(byEntity, false), delay);
     }
     return(true);
 }
Exemple #2
0
        public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling)
        {
            if (byEntity.Controls.Sneak)
            {
                base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, firstEvent, ref handHandling);
                return;
            }
            handHandling = EnumHandHandling.PreventDefault;

            if (byEntity.World.Side.IsServer() && firstEvent)
            {
                SetSustainment(byEntity, false);
                float normalizedPitch = 1.0f - GameMathExt.Normalize(byEntity.Pos.Pitch, 1.578125f, 4.6875f);
                SetNote(byEntity, (EnumPitch)(int)Math.Round((noteValues.Length - 1) * normalizedPitch));
                PlayNote(byEntity, GetNote(byEntity));
            }
        }
        public override bool OnHeldInteractStep(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
        {
            if (byEntity.Controls.Sneak)
            {
                return(base.OnHeldInteractStep(secondsUsed, slot, byEntity, blockSel, entitySel));
            }
            if (tick && byEntity.World.Side.IsServer())
            {
                int delay = instrument == "flute" ? 24 : 500;
                tick = false;
                Vec3d pos             = byEntity.LocalPos.XYZ;
                float normalizedPitch = 1.0f - GameMathExt.Normalize(byEntity.Pos.Pitch, 1.578125f, 4.6875f);
                int   note            = (int)Math.Round((octave.Length - 1) * normalizedPitch);

                Play(byEntity, octave, note, pos);
                byEntity.World.RegisterCallback(dt => tick = true, delay);
            }
            return(true);
        }