Setting a flail's chain? (Working flail, random chain id? (Chain3))

thekaner

Terrarian
I've made a working flail, but I've no idea how to set the chain ID. The strangest part to me is that the chain that is shown at default is not from the weapon I've decided to CloneDefaults from (I just did that to ensure the AI works properly, and to speed up some development process), although I have heard in past updates that chains go in the projectile code anyway.

The chain it defaults too is the blue Chain3 texture and I'm not sure why, I thought maybe it would be the default Chain texture, nothing, or hopefully the file I named 'MFlailCopper_Chain' in the same folder.

Please help! here is the code I'm using (Not sure how to place a 'code' looking thing like some people, so here it is just raw in text).

Item Code:


internal class MFlailCopper : ModItem
{

public override void SetStaticDefaults()
{
DisplayName.SetDefault("Copper Flail");
//Tooltip.SetDefault("Go crazy!");
CreativeItemSacrificesCatalog.Instance.SacrificeCountNeededByItemId[Type] = 1;
}

public override void SetDefaults()
{
Item.CloneDefaults(ItemID.Mace);
//Item.width = 32;
//Item.height = 32;

Item.useStyle = ItemUseStyleID.Shoot;
Item.damage = 11;
Item.knockBack = 5;
Item.useAnimation = Item.useTime = 120;
Item.scale = 1.1f;
Item.noUseGraphic = true;
Item.shootSpeed = 5f;
Item.UseSound = SoundID.Item1;
Item.rare = ItemRarityID.White;
Item.channel = true;
Item.noMelee = true;
Item.shoot = ModContent.ProjectileType<MFlailCopperProjectile>();

}

public override void AddRecipes()
{
Recipe copperCowl = CreateRecipe();
copperCowl.AddIngredient(ItemID.CopperBar, 7);
copperCowl.AddIngredient(ItemID.Chain, 8);
copperCowl.AddRecipeGroup("Wood", 8);
copperCowl.AddTile(TileID.HeavyWorkBench);
copperCowl.Register();
}
}


Projectile Code


internal class MFlailCopperProjectile : ModProjectile
{
public override void SetDefaults()
{
Projectile.width = 30;
Projectile.height = 30;

Projectile.friendly = true;
Projectile.penetrate = -1;
Projectile.tileCollide = true;
Projectile.DamageType = DamageClass.Melee;
Projectile.ownerHitCheck = true;
Projectile.ownerHitCheckDistance = 100f;
Projectile.extraUpdates = 1;
Projectile.timeLeft = 3000;

Projectile.aiStyle = ProjAIStyleID.Flail;
}

}
 

thekaner

Terrarian
Thank you! This worked, though, not exactly what I wanted but it still lets me choose which flail I want to copy the chain from. I wanted to use my own chain texture, but it seems to say thats a bit complicated. I had to add the PreDrawExtras (for the chain) and PreDraw (to replace the sunfury projectile with my custom one that is part of my original code which is still in the same code) overrides. Heres my projectile code now:

internal class MFlailCopperProjectile : ModProjectile
{

public override void SetStaticDefaults()
{
}
public override void SetDefaults()
{
Projectile.width = 20;
Projectile.height = 20;

Projectile.friendly = true;
Projectile.scale = 0.8f;
Projectile.penetrate = -1;
Projectile.tileCollide = true;
Projectile.DamageType = DamageClass.Melee;
Projectile.ownerHitCheck = true;

Projectile.netImportant = true;
Projectile.aiStyle = 15;

DrawOffsetX = -6;
DrawOriginOffsetY = -6;
}

public override bool PreDrawExtras()
{
Projectile.type = ProjectileID.Mace;
return base.PreDrawExtras();
}


public override bool PreDraw(ref Color lightColor)
{
Projectile.type = ModContent.ProjectileType<MFlailCopperProjectile>();

// This code handles the after images.
if (Projectile.ai[0] == 1f)
{
Texture2D projectileTexture = TextureAssets.Projectile[Projectile.type].Value;
Vector2 drawPosition = Projectile.position + new Vector2(Projectile.width, Projectile.height) / 2f + Vector2.UnitY * Projectile.gfxOffY - Main.screenPosition;
Vector2 drawOrigin = new Vector2(projectileTexture.Width, projectileTexture.Height) / 2f;
Color drawColor = Projectile.GetAlpha(lightColor);
drawColor.A = 127;
drawColor *= 0.5f;
int launchTimer = (int)Projectile.ai[1];
if (launchTimer > 5)
{
launchTimer = 5;
}

SpriteEffects spriteEffects = Projectile.spriteDirection == 1 ? SpriteEffects.None : SpriteEffects.FlipHorizontally;

for (float transparancy = 1f; transparancy >= 0f; transparancy -= 0.125f)
{
float opacity = 1f - transparancy;
Vector2 drawAdjustment = Projectile.velocity * -launchTimer * transparancy;
Main.EntitySpriteDraw(projectileTexture, drawPosition + drawAdjustment, null, drawColor * opacity, Projectile.rotation, drawOrigin, Projectile.scale * 1.15f * MathHelper.Lerp(0.5f, 1f, opacity), spriteEffects, 0);
}
}

return base.PreDraw(ref lightColor);
}

//Projectile.type = ModContent.ProjectileType<MFlailCopperProjectile>();


}
<3
 

thekaner

Terrarian
Thank you! This worked, though, not exactly what I wanted but it still lets me choose which flail I want to copy the chain from. I wanted to use my own chain texture, but it seems to say thats a bit complicated. I had to add the PreDrawExtras (for the chain) and PreDraw (to replace the sunfury projectile with my custom one that is part of my original code which is still in the same code) overrides. Heres my projectile code now:

internal class MFlailCopperProjectile : ModProjectile
{

public override void SetStaticDefaults()
{
}
public override void SetDefaults()
{
Projectile.width = 20;
Projectile.height = 20;

Projectile.friendly = true;
Projectile.scale = 0.8f;
Projectile.penetrate = -1;
Projectile.tileCollide = true;
Projectile.DamageType = DamageClass.Melee;
Projectile.ownerHitCheck = true;

Projectile.netImportant = true;
Projectile.aiStyle = 15;

DrawOffsetX = -6;
DrawOriginOffsetY = -6;
}

public override bool PreDrawExtras()
{
Projectile.type = ProjectileID.Mace;
return base.PreDrawExtras();
}


public override bool PreDraw(ref Color lightColor)
{
Projectile.type = ModContent.ProjectileType<MFlailCopperProjectile>();

// This code handles the after images.
if (Projectile.ai[0] == 1f)
{
Texture2D projectileTexture = TextureAssets.Projectile[Projectile.type].Value;
Vector2 drawPosition = Projectile.position + new Vector2(Projectile.width, Projectile.height) / 2f + Vector2.UnitY * Projectile.gfxOffY - Main.screenPosition;
Vector2 drawOrigin = new Vector2(projectileTexture.Width, projectileTexture.Height) / 2f;
Color drawColor = Projectile.GetAlpha(lightColor);
drawColor.A = 127;
drawColor *= 0.5f;
int launchTimer = (int)Projectile.ai[1];
if (launchTimer > 5)
{
launchTimer = 5;
}

SpriteEffects spriteEffects = Projectile.spriteDirection == 1 ? SpriteEffects.None : SpriteEffects.FlipHorizontally;

for (float transparancy = 1f; transparancy >= 0f; transparancy -= 0.125f)
{
float opacity = 1f - transparancy;
Vector2 drawAdjustment = Projectile.velocity * -launchTimer * transparancy;
Main.EntitySpriteDraw(projectileTexture, drawPosition + drawAdjustment, null, drawColor * opacity, Projectile.rotation, drawOrigin, Projectile.scale * 1.15f * MathHelper.Lerp(0.5f, 1f, opacity), spriteEffects, 0);
}
}

return base.PreDraw(ref lightColor);
}

//Projectile.type = ModContent.ProjectileType<MFlailCopperProjectile>();


}
<3
Found the code I was really looking for in the ExampleMod (Instead it is called Example Advanced Falil rather than Example Flail)
Was able to set my own chain! Had to change a bit, remove the 'const string' parts and write in the strings myself to replace where they are later in the code and some other things, but it works! I have my copper chain on my copper flail.

 
Top Bottom