public override bool OnHeldInteractStep(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandling handling) { EntityBehaviorMilkable bh; if (entitySel != null && (bh = entitySel.Entity.GetBehavior <EntityBehaviorMilkable>()) != null) { IPlayer player = (byEntity as EntityPlayer).Player; if (player == null) { return(false); } if (!bh.CanContinueMilking(player, secondsUsed)) { return(false); } handling = EnumHandling.PreventDefault; if (api.Side == EnumAppSide.Client) { ModelTransform tf = new ModelTransform(); tf.EnsureDefaultValues(); tf.Translation.Set(-1f * (float)Easings.EaseOutBack(Math.Min(secondsUsed * 1.5f, 1)), (float)Easings.EaseOutBack(Math.Min(1, secondsUsed * 1.5f)) * 0.3f, -1 * (float)Easings.EaseOutBack(Math.Min(secondsUsed * 1.5f, 1))); if (secondsUsed > 1f) { tf.Translation.X += (float)GameMath.MurmurHash3Mod((int)(secondsUsed * 3), 0, 0, 10) / 600f; tf.Translation.Y += (float)GameMath.MurmurHash3Mod(0, (int)(secondsUsed * 3), 0, 10) / 600f; } byEntity.Controls.UsingHeldItemTransformBefore = tf; } if (api.Side == EnumAppSide.Server) { return(true); } return(secondsUsed < 3); } return(false); }
public override bool OnHeldAttackStep(float secondsPassed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSelection, EntitySelection entitySel) { if (blockSelection == null) { return(false); } if (!CanMultiBreak(api.World.BlockAccessor.GetBlock(blockSelection.Position)) && byEntity.Attributes.GetBool("didBreakBlocks") == false) { return(false); } if (byEntity.World.Side == EnumAppSide.Client) { ModelTransform tf = new ModelTransform(); tf.EnsureDefaultValues(); float t = secondsPassed / 1.35f; float f = (float)Easings.EaseOutBack(Math.Min(t * 2f, 1)); float f2 = (float)Math.Sin(GameMath.Clamp(Math.PI * 1.4f * (t - 0.5f), 0, 3)); tf.Translation.X += Math.Min(0.2f, t * 3); tf.Translation.Y -= Math.Min(0.75f, t * 3); tf.Translation.Z -= Math.Min(1, t * 3); tf.ScaleXYZ += Math.Min(1, t * 3); tf.Origin.X -= Math.Min(0.75f, t * 3); tf.Rotation.X = -Math.Min(30, t * 30) + f * 30 + (float)f2 * 120f; tf.Rotation.Z = -f * 110; if (secondsPassed > 1.75f) { float b = 2 * (secondsPassed - 1.75f); tf.Rotation.Z += b * 140; tf.Rotation.X /= (1 + b * 10); tf.Translation.X -= b * 0.4f; tf.Translation.Y += b * 2 / 0.75f; tf.Translation.Z += b * 2; //tf.Origin.X += b * 2 / 0.75f; //tf.ScaleXYZ -= b * 2; } byEntity.Controls.UsingHeldItemTransformBefore = tf; } if (secondsPassed > 0.75f && byEntity.Attributes.GetBool("didPlaySound") == false) { api.World.PlaySoundAt(new AssetLocation("sounds/tool/scythe1"), byEntity, (byEntity as EntityPlayer)?.Player, true, 16); byEntity.Attributes.SetBool("didPlaySound", true); } if (secondsPassed > 1.45f && byEntity.Attributes.GetBool("didBreakBlocks") == false) { if (byEntity.World.Side == EnumAppSide.Server) { IPlayer byPlayer = (byEntity as EntityPlayer)?.Player; if (!byEntity.World.Claims.TryAccess(byPlayer, blockSelection.Position, EnumBlockAccessFlags.BuildOrBreak)) { return(false); } OnBlockBrokenWith(byEntity.World, byEntity, slot, blockSelection); } byEntity.Attributes.SetBool("didBreakBlocks", true); } // Crappy fix to make harvesting not buggy T_T if (api.Side == EnumAppSide.Server) { return(true); } return(secondsPassed < 2f); }