Solo-Ion
Dungeon Spirit
Terraria has a built in craft group for iron or lead. Just do the following.How can I make an Item to be either crafted with an iron bar or a lead bar, like the craftinggroup method?
I don't want to add two recipes, and since crafting group method was removed, I am confused what to do.
recipe1.AddRecipeGroup("IronBar", 3); //vanilla recipe group - adds 3
A custom craft group looks like the following.
Code:
public override void AddRecipeGroups()
{
//Add the silver ranked group
RecipeGroup group = new RecipeGroup(() => Lang.misc[37] + " Silver", new int[]
{
ItemID.SilverBar,
ItemID.TungstenBar
});
RecipeGroup.RegisterGroup("rankSilver", group); //creates a group called "rankSilver". Use recipe.AddRecipeGroup("rankSilver", 1); to use this group in a recipe
}
Well first, I found the problem that was causing the slow down. You need to swap the two if conditions inside the findNearest function so that your projectile isn't checking collision with all 200 non-existent NPC's in the world. And your projectile wasn't homing because you had removed the position of its target from the equation, so that it never knew where to home to. Also, you forgot to check if your 'nearest' NPC was null, which would cause the projectile to disappear. I've fixed your AI for you.I have a big problem now
the projectile just goes out a little distance and then stops until there is something to home in on.then it homes.
EDIT: Then it just sits there and never homes
Code:using System; using Terraria; using Terraria.ID; using Terraria.ModLoader; using Microsoft.Xna.Framework; namespace Pack.Projectiles { public class TS : ModProjectile { public override void SetDefaults() { projectile.name = "Templite Spell"; projectile.width = 8; projectile.height = 8; projectile.friendly = true; projectile.penetrate = 10; projectile.aiStyle = 0; projectile.magic = true; projectile.tileCollide = true; projectile.timeLeft = 60000; projectile.light = 10f; } public NPC FindNearest(Vector2 pos) { NPC nearest = null; float oldDist = 1001; float newDist = 1000; for (int i = 0; i < Terraria.Main.npc.Length - 1; i++) { if (!Collision.CanHit(pos, 1, 1, Main.npc[i].position, Main.npc[i].width, Main.npc[i].height)) continue; if (!Terraria.Main.npc[i].CanBeChasedBy(projectile)) continue; if (nearest == null) nearest = Terraria.Main.npc[i]; else { oldDist = Vector2.Distance(pos, nearest.position); newDist = Vector2.Distance(pos, Terraria.Main.npc[i].position); if (newDist < oldDist) nearest = Terraria.Main.npc[i]; } } return nearest; } int maxSpeed = 10; public override void AI() { NPC nearest = this.FindNearest(projectile.Center); Vector2 acceleration = Vector2.Zero; projectile.velocity += acceleration * 1.5f; projectile.velocity *= 0.95f; if (projectile.velocity.Length() > maxSpeed) { projectile.velocity.Normalize(); projectile.velocity *= maxSpeed; } projectile.rotation = projectile.velocity.ToRotation(); } } }
where's the mistake in my code?
please help
Code:
public override void AI()
{
NPC nearest = this.FindNearest(projectile.Center);
Vector2 acceleration;
if (nearest != null) //this is really important
{
acceleration = (nearest.position - projectile.position);
} else
{
acceleration = Vector2.Zero; //maintain speed -- or whatever else you want to do here
}
projectile.velocity += acceleration * 1.5f;
projectile.velocity *= 0.99f;
if (projectile.velocity.Length() > maxSpeed)
{
projectile.velocity.Normalize();
projectile.velocity *= maxSpeed;
}
projectile.rotation = projectile.velocity.ToRotation();
}