tModLoader (FIXED) CS0117 : "ModContent" does not contain a definition for "ItemType"

_Golden_

Terrarian
I'm working on my mod and I wanted to add a custom loot to my enemy, but it seems like ItemType doesn't exist for ModContent.
Enemy : DarkConcentration | Item to loot : DarkMatter | Inside mod's name : MoreMagicBeta1
Here's the full code :

C#:
using Terraria;
using Terraria.ID;
using Microsoft.Xna.Framework;
using Terraria.ModLoader;
using Terraria.Graphics.Effects;
using Terraria.Graphics.Shaders;
using MoreMagicBeta1.Content.Projectiles;
using System.Drawing.Imaging;
using System;
using Terraria.GameContent.ItemDropRules;
using MoreMagicBeta1.Content.Items.Materials;

namespace MoreMagicBeta1.Content.NPCs;

public class DarkConcentration : ModNPC
{
    public override void SetStaticDefaults()
    {
        // DisplayName.SetDefault("Dark Concentration");
        Main.npcFrameCount[NPC.type] = 7;

        NPCID.Sets.NPCBestiaryDrawModifiers value = new()
        {
            Velocity = 1f
        };
        NPCID.Sets.NPCBestiaryDrawOffset.Add(Type, value);
    }

    public override void SetDefaults()
    {
        NPC.width = 64;
        NPC.height = 64;

        // frames
        NPC.frame.Width = 64;
        NPC.frame.Height = 64;
        NPC.frameCounter = 0;

        NPC.damage = 150;
        NPC.defense = 20;
        NPC.lifeMax = 1200;
        NPC.knockBackResist = 0.5f;
        NPC.HitSound = SoundID.NPCHit5;
        NPC.DeathSound = SoundID.NPCDeath45;

        NPC.value = 200f;

        NPC.aiStyle = 86;

    }

    public override void AI()
    {
        // Custom animation

        NPC.frameCounter++;

        if (NPC.frameCounter >= 7)
        {
            NPC.frame.Y += 64;
            if (NPC.frame.Y >= Main.npcFrameCount[NPC.type] * NPC.frame.Height)
            {
                NPC.frame.Y = 0;
            }
            NPC.frameCounter = 0;
        }
    }

    public override void ModifyNPCLoot(NPCLoot npcLoot)
    {
        npcLoot.Add(ItemDropRule.Common(ModContent.ItemType<DarkMatter>(), 30, 1, 4));
    }
    public override void OnKill()
    {
        NPC.TargetClosest();
        if (NPC.HasValidTarget && Main.netMode != NetmodeID.MultiplayerClient)
        {

            var source = NPC.GetSource_FromAI();
            Vector2 position = NPC.Center;
            Vector2 targetPosition = Main.player[NPC.target].Center;
            Vector2 direction = targetPosition - position;
            direction.Normalize();
            float speed = 10f;
            int type = ProjectileID.InfernoHostileBlast;
            int projectileDamage = NPC.damage;
            Projectile.NewProjectile(source, position, direction * speed, type, projectileDamage, 0f, Main.myPlayer);
        }
    }
}

I hope anyone can help!
 
The code seems fine, you just need the right using statement for your loot item.

Is the class name DarkMatter and the namespace is MoreMagicBeta1.Content.Items.Materials? That's what you currently have, but if it can't be found, one of those two is the issue.
 
The class name DarkMatter has the correct namespace.
Here's its code in case :

C#:
using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace MoreMagicBeta1.Content.Items.Materials;

public class DarkMatter : ModItem
{

    public override void SetStaticDefaults()
    {
        //DisplayName("Dark Matter");
    }

    public override void ModifyTooltips(System.Collections.Generic.List<TooltipLine> tooltips)
    {
        // Add a tooltip line dynamically
        tooltips.Add(new TooltipLine(Mod, "Dark Matter", "A strange and evil power... It smells like cheese."));
    }

    public override void SetDefaults()
    {
        Item.width = 46;
        Item.height = 46;
        Item.value = Item.buyPrice(0, 0, 0, 0);
        Item.rare = ItemRarityID.Pink;
    }
}
 
Ok, that looks perfectly fine. Hmm. Can you post a screenshot of the full error?
 
Nevermind! I've found a solution
Here's what I had to do :
"ModContent.ItemType" doesn't exist, but to make it exist, I need to put "Terraria.ModLoader."

Here's the fixed hook :
C#:
public override void ModifyNPCLoot(NPCLoot npcLoot)
    {
        npcLoot.Add(ItemDropRule.Common(Terraria.ModLoader.ModContent.ItemType<DarkMatter>(), 30, 1, 4));
    }

Thanks for your involvement anyway!
 
Back
Top Bottom