crow real
Terrarian
Here's the code:
I'm not getting any errors btw, just that idk how to make it both a rare enemy and a jungle temple enemy.
C#:
using funnymodthing123.NPCs;
using funnymodthing123.Content.Items;
using Microsoft.Xna.Framework;
using System.IO;
using Terraria;
using Terraria.GameContent.Bestiary;
using Terraria.ID;
using Terraria.GameContent.ItemDropRules;
using Terraria.ModLoader;
namespace funnymodthing123.Content.NPCs
{
// These three class showcase usage of the WormHead, WormBody and WormTail classes from Worm.cs
internal class DiggerSnakeHead : WormHead
{
public override int BodyType => ModContent.NPCType<DiggerSnakeBody>();
public override int TailType => ModContent.NPCType<DiggerSnakeTail>();
public override void SetStaticDefaults()
{
var drawModifier = new NPCID.Sets.NPCBestiaryDrawModifiers()
{ // Influences how the NPC looks in the Bestiary
CustomTexturePath = "funnymodthing123/Content/NPCs/DiggerSnake_Bestiary", // If the NPC is multiple parts like a worm, a custom texture for the Bestiary is encouraged.
Position = new Vector2(40f, 24f),
PortraitPositionXOverride = 0f,
PortraitPositionYOverride = 12f
};
NPCID.Sets.NPCBestiaryDrawOffset.Add(NPC.type, drawModifier);
}
public override void SetDefaults()
{
// Head is 10 defense, body 20, tail 30.
NPC.CloneDefaults(NPCID.DiggerHead);
NPC.defense = 20;
NPC.damage = 35;
NPC.lifeMax = 25000;
NPC.life = 25000;
NPC.aiStyle = -1;
NPC.boss = false;
}
public override void ModifyNPCLoot(NPCLoot npcLoot)
{
// Do NOT misuse the ModifyNPCLoot and OnKill hooks: the former is only used for registering drops, the latter for everything else
// The order in which you add loot will appear as such in the Bestiary. To mirror vanilla boss order:
// 1. Trophy
// 2. Classic Mode ("not expert")
// 3. Expert Mode (usually just the treasure bag)
// 4. Master Mode (relic first, pet last, everything else inbetween)
npcLoot.Add(ItemDropRule.Common(ModContent.ItemType<Items.SnakeSkin>(), 2));
npcLoot.Add(ItemDropRule.Common(ModContent.ItemType<Items.Snakebite>(), 10));
}
public override void SetBestiary(BestiaryDatabase database, BestiaryEntry bestiaryEntry)
{
// We can use AddRange instead of calling Add multiple times in order to add multiple items at once
bestiaryEntry.Info.AddRange(new IBestiaryInfoElement[] {
// Sets the spawning conditions of this NPC that is listed in the bestiary.
BestiaryDatabaseNPCsPopulator.CommonTags.SpawnConditions.Biomes.UndergroundJungle,
BestiaryDatabaseNPCsPopulator.CommonTags.SpawnConditions.Biomes.Caverns,
// Sets the description of this NPC that is listed in the bestiary.
new FlavorTextBestiaryInfoElement("Hey, snakes don't dig! Atleast, not this much.")
});
}
public override void Init()
{
// Set the segment variance
// If you want the segment length to be constant, set these two properties to the same value
MinSegmentLength = 20;
MaxSegmentLength = 20;
CommonWormInit(this);
}
// This method is invoked from ExampleWormHead, ExampleWormBody and ExampleWormTail
internal static void CommonWormInit(Worm worm)
{
// These two properties handle the movement of the worm
worm.MoveSpeed = 6.7f;
worm.Acceleration = 0.096f;
}
private int attackCounter;
public override void SendExtraAI(BinaryWriter writer)
{
writer.Write(attackCounter);
}
public override void ReceiveExtraAI(BinaryReader reader)
{
attackCounter = reader.ReadInt32();
}
public override void AI()
{
if (Main.netMode != NetmodeID.MultiplayerClient)
{
if (attackCounter > 0)
{
attackCounter--; // tick down the attack counter.
}
Player target = Main.player[NPC.target];
// If the attack counter is 0, this NPC is less than 12.5 tiles away from its target, and has a path to the target unobstructed by blocks, summon a projectile.
if (attackCounter <= 0 && Vector2.Distance(NPC.Center, target.Center) < 200 && Collision.CanHit(NPC.Center, 1, 1, target.Center, 1, 1))
{
Vector2 direction = (target.Center - NPC.Center).SafeNormalize(Vector2.UnitX);
direction = direction.RotatedByRandom(MathHelper.ToRadians(10));
int projectile = Projectile.NewProjectile(NPC.GetSource_FromThis(), NPC.Center, direction * 10, ProjectileID.JungleSpike, 5, 0, Main.myPlayer);
Main.projectile[projectile].timeLeft = 300;
attackCounter = 500;
NPC.netUpdate = true;
}
}
}
}
internal class DiggerSnakeBody : WormBody
{
public override void SetStaticDefaults()
{
NPCID.Sets.NPCBestiaryDrawModifiers value = new NPCID.Sets.NPCBestiaryDrawModifiers()
{
Hide = true // Hides this NPC from the Bestiary, useful for multi-part NPCs whom you only want one entry.
};
NPCID.Sets.NPCBestiaryDrawOffset.Add(NPC.type, value);
}
public override void SetDefaults()
{
NPC.CloneDefaults(NPCID.DiggerBody);
NPC.damage = 35;
NPC.lifeMax = 25000;
NPC.life = 25000;
NPC.aiStyle = -1;
}
public override void Init()
{
DiggerSnakeHead.CommonWormInit(this);
}
}
internal class DiggerSnakeTail : WormTail
{
public override void SetStaticDefaults()
{
NPCID.Sets.NPCBestiaryDrawModifiers value = new NPCID.Sets.NPCBestiaryDrawModifiers()
{
Hide = true // Hides this NPC from the Bestiary, useful for multi-part NPCs whom you only want one entry.
};
NPCID.Sets.NPCBestiaryDrawOffset.Add(NPC.type, value);
}
public override void SetDefaults()
{
NPC.CloneDefaults(NPCID.DiggerTail);
NPC.damage = 70;
NPC.lifeMax = 25000;
NPC.life = 25000;
NPC.aiStyle = -1;
}
public override void Init()
{
DiggerSnakeHead.CommonWormInit(this);
}
}
}