public override void OnInteract(EntityAgent byEntity, ItemSlot slot, Vec3d hitPosition, EnumInteractMode mode) { EnumHandling handled = EnumHandling.PassThrough; foreach (EntityBehavior behavior in SidedProperties.Behaviors) { behavior.OnInteract(byEntity, slot, hitPosition, mode, ref handled); if (handled == EnumHandling.PreventSubsequent) { break; } } if (handled == EnumHandling.PreventDefault || handled == EnumHandling.PreventSubsequent) { return; } if (mode == EnumInteractMode.Attack) { float damage = slot.Itemstack == null ? 0.5f : slot.Itemstack.Collectible.GetAttackPower(slot.Itemstack); int damagetier = slot.Itemstack == null ? 0 : slot.Itemstack.Collectible.ToolTier; damage *= byEntity.Stats.GetBlended("meleeWeaponsDamage"); if (Attributes.GetBool("isMechanical", false)) { damage *= byEntity.Stats.GetBlended("mechanicalsDamage"); } IPlayer byPlayer = null; if (byEntity is EntityPlayer && !IsActivityRunning("invulnerable")) { byPlayer = (byEntity as EntityPlayer).Player; World.PlaySoundAt(new AssetLocation("sounds/player/slap"), ServerPos.X, ServerPos.Y, ServerPos.Z, byPlayer); slot?.Itemstack?.Collectible.OnAttackingWith(byEntity.World, byEntity, this, slot); } if (Api.Side == EnumAppSide.Client && damage > 1 && !IsActivityRunning("invulnerable") && Properties.Attributes?["spawnDamageParticles"].AsBool() == true) { Vec3d pos = SidedPos.XYZ + hitPosition; Vec3d minPos = pos.AddCopy(-0.15, -0.15, -0.15); Vec3d maxPos = pos.AddCopy(0.15, 0.15, 0.15); int textureSubId = this.Properties.Client.FirstTexture.Baked.TextureSubId; Vec3f tmp = new Vec3f(); for (int i = 0; i < 10; i++) { int color = (Api as ICoreClientAPI).EntityTextureAtlas.GetRandomColor(textureSubId); tmp.Set( 1f - 2 * (float)World.Rand.NextDouble(), 2 * (float)World.Rand.NextDouble(), 1f - 2 * (float)World.Rand.NextDouble() ); World.SpawnParticles( 1, color, minPos, maxPos, tmp, tmp, 1.5f, 1f, 0.25f + (float)World.Rand.NextDouble() * 0.25f, EnumParticleModel.Cube, byPlayer ); } } DamageSource dmgSource = new DamageSource() { Source = (byEntity as EntityPlayer).Player == null ? EnumDamageSource.Entity : EnumDamageSource.Player, SourceEntity = byEntity, Type = EnumDamageType.BluntAttack, HitPosition = hitPosition, DamageTier = damagetier }; if (ReceiveDamage(dmgSource, damage)) { byEntity.DidAttack(dmgSource, this); } } }
/// <summary> /// Called when a custom attack action is finished /// </summary> /// <param name="secondsPassed"></param> /// <param name="slot"></param> /// <param name="byEntity"></param> /// <param name="blockSelection"></param> /// <param name="entitySel"></param> /// <param name="handling"></param> public virtual void OnHeldAttackStop(float secondsPassed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSelection, EntitySelection entitySel, ref EnumHandHandling handling) { handling = EnumHandHandling.NotHandled; }
/// <summary> /// Called continously when a custom attack action is playing. Return false to stop the action. /// </summary> /// <param name="secondsPassed"></param> /// <param name="slot"></param> /// <param name="byEntity"></param> /// <param name="blockSelection"></param> /// <param name="entitySel"></param> /// <param name="handling"></param> /// <returns></returns> public virtual bool OnHeldAttackStep(float secondsPassed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSelection, EntitySelection entitySel, ref EnumHandHandling handling) { handling = EnumHandHandling.NotHandled; return(false); }
/// <summary> /// When the player has begun using this item for attacking (left mouse click). Return true to play a custom action. /// </summary> /// <param name="slot"></param> /// <param name="byEntity"></param> /// <param name="blockSel"></param> /// <param name="entitySel"></param> /// <param name="handHandling"></param> /// <param name="handling"></param> /// <returns></returns> public virtual void OnHeldAttackStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handHandling, ref EnumHandHandling handling) { handHandling = EnumHandHandling.NotHandled; }
/// <summary> /// Called when the player successfully completed the using action, not called when successfully cancelled /// </summary> /// <param name="secondsUsed"></param> /// <param name="slot"></param> /// <param name="byEntity"></param> /// <param name="blockSel"></param> /// <param name="entitySel"></param> /// <param name="handling"></param> public virtual void OnHeldInteractStop(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandling handling) { handling = EnumHandling.PassThrough; return; }
/// <summary> /// Called when the player right clicks while holding this block/item in his hands /// </summary> /// <param name="slot"></param> /// <param name="byEntity"></param> /// <param name="blockSel"></param> /// <param name="entitySel"></param> /// <param name="handHandling"></param> /// <param name="handling"></param> /// <returns></returns> public virtual void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling, ref EnumHandling handling) { handling = EnumHandling.PassThrough; }