tModLoader Problems with StatModifier in Tmodloader 1.4?

Pufflepuff89

Terrarian
For a mod I am working on, I am trying to make a helmet for the shroomite armor that boosts dart damage, however I am having some troubles doing this. After looking at the player class, I found that terraria uses a "StatModifier" object for arrow damage. How would one go about creating a custom stat modifier? I tried creating it in a ModPlayer instance, but when I do this, the damage seems to increase infinitely. I do not have this problem when using the vanilla arrow damage property.

Code:
Shroomite Bandana:
C#:
using Terraria;
using Terraria.ModLoader;
using Terraria.ID;
using Terraria.GameContent.Creative;

namespace AdvancedAmmunition.Items.Accessories.Armor
{
    // The AutoloadEquip attribute automatically attaches an equip texture to this item.
    // Providing the EquipType.Head value here will result in TML expecting a X_Head.png file to be placed next to the item's main texture.
    [AutoloadEquip(EquipType.Head)]
    public class ShroomiteBandana : ModItem
    {
        public override void SetStaticDefaults() {
              Tooltip.SetDefault("15% increased dart damage\n5% increased ranged critical strike chance");

            CreativeItemSacrificesCatalog.Instance.SacrificeCountNeededByItemId[Type] = 3;

            // If your head equipment should draw hair while drawn, use one of the following:
            // ArmorIDs.Head.Sets.DrawHead[Item.headSlot] = false; // Don't draw the head at all. Used by Space Creature Mask
            // ArmorIDs.Head.Sets.DrawHatHair[Item.headSlot] = true; // Draw hair as if a hat was covering the top. Used by Wizards Hat
            ArmorIDs.Head.Sets.DrawFullHair[Item.headSlot] = true; // Draw all hair as normal. Used by Mime Mask, Sunglasses
            ArmorIDs.Head.Sets.DrawBackHair[Item.headSlot] = true;
            // ArmorIDs.Head.Sets.DrawsBackHairWithoutHeadgear[Item.headSlot] = true;
        }

        public override void SetDefaults() {
            Item.CloneDefaults(ItemID.ShroomiteHelmet);
        }

        public override void UpdateEquip(Player player) {
            
            //player.GetModPlayer<VanillaChanges.NewPlayerStats>().Player.arrowDamage += .15f;
            player.GetModPlayer<VanillaChanges.NewPlayerStats>().dartDamage += .15f;
            player.GetCritChance(DamageClass.Ranged) += 5f;
        }

        public override bool IsArmorSet(Item head, Item body, Item legs) {
            return body.type == ItemID.ShroomiteBreastplate && legs.type == ItemID.ShroomiteLeggings;
        }

        // UpdateArmorSet allows you to give set bonuses to the armor.
        public override void UpdateArmorSet(Player player) {
            player.shroomiteStealth = true;
        }

        // Please see Content/ExampleRecipes.cs for a detailed explanation of recipe creation.
        /*public override void AddRecipes() {
            CreateRecipe()
                .AddIngredient<ExampleItem>()
                .AddTile<Tiles.Furniture.ExampleWorkbench>()
                .Register();
        }*/
    }
}

NewPlayerStats:
C#:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.DataStructures;
using Terraria.ID;
using Terraria.ModLoader;

namespace AdvancedAmmunition.VanillaChanges
{
    // This class showcases things you can do with fishing
    public class NewPlayerStats : ModPlayer
    {
        public StatModifier dartDamage = StatModifier.Default;
    }

    
}

DartModifier:
Code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.DataStructures;
using Terraria.ID;
using Terraria.ModLoader;

namespace AdvancedAmmunition.VanillaChanges
{
    // This class showcases things you can do with fishing
    public class DartModifier : ModPlayer
    {
        public override void ModifyWeaponDamage(Item item, ref StatModifier damage) {
            if (item.useAmmo == AmmoID.Dart) {
                damage = damage.CombineWith(Main.player[Main.myPlayer].GetModPlayer<VanillaChanges.NewPlayerStats>().dartDamage);
            }
        }
    }

    
}
 
You need to add
public override void ResetEffects() {
dartDamage = StatModifier.Default;
}
to your NewPlayerStats class
 
Back
Top Bottom