_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 :
I hope anyone can help!
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!