public override void OnHeldInteractStop(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel) { if (secondsUsed > 0.7f && byEntity.World.Side == EnumAppSide.Server) { JsonObject attr = slot.Itemstack.Collectible.Attributes; float health = attr["health"].AsFloat(); byEntity.ReceiveDamage(new DamageSource() { Source = EnumDamageSource.Internal, Type = health > 0 ? EnumDamageType.Heal : EnumDamageType.Poison }, Math.Abs(health)); slot.TakeOut(1); } }
public override bool OnHeldInteractStep(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel) { if (byEntity.Attributes.GetBool("isInsertGear", false)) { if (!(byEntity.LeftHandItemSlot?.Itemstack?.Collectible is ItemTemporalGear)) { return(false); } if (byEntity.World.Side == EnumAppSide.Client) { ModelTransform tf = new ModelTransform(); tf.EnsureDefaultValues(); tf.Translation.Set(0, -Math.Min(0.2f, secondsUsed * 0.8f), -Math.Min(0.6f, secondsUsed * 3 * 0.8f)); //tf.Rotation.X = Math.Min(60, secondsUsed * 90 * 4f); tf.Origin.Set(0.3f, 0, 0.5f); tf.Rotation.X = Math.Min(135, secondsUsed * 90 * 7.5f * 0.8f); tf.Rotation.Z = -Math.Min(30, secondsUsed * 90 * 1.667f * 0.8f); if (secondsUsed > 1f) { tf.Translation.Y += Math.Min(0.75f, (secondsUsed - 1f) * 20); tf.Translation.X -= Math.Min(0.2f, secondsUsed - 1f); tf.Rotation.Z -= Math.Min(130, (secondsUsed - 1f) * 90 * 20); } if (secondsUsed > 1.1f && !byEntity.Attributes.GetBool("stabPlayed", false)) { byEntity.World.PlaySoundAt(new AssetLocation("sounds/player/stab"), byEntity, (byEntity as EntityPlayer)?.Player, false, 12, 0.3f); byEntity.Attributes.SetBool("stabPlayed", true); } byEntity.Controls.UsingHeldItemTransformBefore = tf; ModelTransform tfleft = new ModelTransform(); tfleft.EnsureDefaultValues(); byEntity.LeftHandItemSlot.Itemstack.Collectible.FpHandTransform.Rotation.Y = 0; tfleft.Translation.Set(Math.Min(0.6f, secondsUsed * 4), Math.Min(0.2f, secondsUsed), 0); if (secondsUsed >= 1.4f) { tfleft.Translation.Z += (secondsUsed - 1.4f) * 1.2f; tfleft.Translation.Y += Math.Min(0.1f, (secondsUsed - 1.4f) * 1.2f); tfleft.Translation.X += (secondsUsed - 1.4f) * 1.2f; } byEntity.Controls.LeftUsingHeldItemTransformBefore = tfleft; return(true); } else { if (secondsUsed > 1.1f && !byEntity.Attributes.GetBool("didHurt", false)) { api.World.Logger.Notification("Server did hurt"); byEntity.ReceiveDamage(new DamageSource() { DamageTier = 0, Source = EnumDamageSource.Internal, Type = EnumDamageType.PiercingAttack }, 2); slot?.Itemstack?.Collectible.DamageItem(byEntity.World, byEntity, slot, 1); byEntity.Attributes.SetBool("didHurt", true); } if (secondsUsed >= 1.95f && !byEntity.Attributes.GetBool("stabPlayed", false)) { api.World.Logger.Notification("Server did stab played"); byEntity.GetBehavior <EntityBehaviorTemporalStabilityAffected>().AddStability(0.30); byEntity.LeftHandItemSlot.TakeOut(1); byEntity.LeftHandItemSlot.MarkDirty(); ((byEntity as EntityPlayer)?.Player as IServerPlayer)?.BroadcastPlayerData(); int h = 110 + api.World.Rand.Next(15); int v = 100 + api.World.Rand.Next(50); particlesStab.MinPos = byEntity.SidedPos.XYZ.Add(byEntity.CollisionBox.X1, 0, byEntity.CollisionBox.Z1); particlesStab.AddPos = new Vec3d(byEntity.CollisionBox.XSize, byEntity.CollisionBox.Y2, byEntity.CollisionBox.ZSize); particlesStab.Color = ColorUtil.ReverseColorBytes(ColorUtil.HsvToRgba(h, 180, v, 150)); api.World.SpawnParticles(particlesStab); byEntity.Attributes.SetBool("stabPlayed", true); } return(secondsUsed < 2f); } } // Crappy fix to make animal harvesting not buggy T_T if (api.Side == EnumAppSide.Server) { return(true); } EntityBehaviorHarvestable bh; if (entitySel != null && (bh = entitySel.Entity.GetBehavior <EntityBehaviorHarvestable>()) != null && bh.Harvestable) { if (byEntity.World.Side == EnumAppSide.Client) { ModelTransform tf = new ModelTransform(); tf.EnsureDefaultValues(); tf.Translation.Set(0, 0, -Math.Min(0.6f, secondsUsed * 2)); tf.Rotation.Y = Math.Min(20, secondsUsed * 90 * 2f); if (secondsUsed > 0.4f) { tf.Translation.X += (float)Math.Cos(secondsUsed * 15) / 10; tf.Translation.Z += (float)Math.Sin(secondsUsed * 5) / 30; } byEntity.Controls.UsingHeldItemTransformBefore = tf; } //byEntity.World.Logger.Debug("{0} knife interact step: Seconds: {1}/{2}", byEntity.World.Side, secondsUsed, bh.HarvestDuration ); return(secondsUsed < bh.GetHarvestDuration(byEntity) + 0.15f); } return(false); }