i cannot for the love of god let my sword shoot my custom projectile

sxjxt

Terrarian
im new to modding and i dont rly know what im doing. i just wanna make a sword shoot a custom projectile but no matter what i do i get this error:
1691343076540.png

now i've tried looking it up but nothing helps. it's incredibly annoying and nothing i do fixes it.

here is the sword's code:
using Terraria.ID;
using Terraria.ModLoader;
using sxjxtmod.Projectiles.woodenwindmillprojectile;

namespace ExampleMod.Content.Items.Weapons
{
/// <summary>
/// Star Wrath/Starfury style weapon. Spawn projectiles from sky that aim towards mouse.
/// See Source code for Star Wrath projectile to see how it passes through tiles.
/// For a detailed sword guide see <see cref="ExampleSword" />
/// </summary>
public class ExampleShootingSword : ModItem
{
public override void SetDefaults() {
Item.width = 26;
Item.height = 42;

Item.useStyle = ItemUseStyleID.Swing;
Item.useTime = 20;
Item.useAnimation = 20;
Item.autoReuse = true;

Item.DamageType = DamageClass.Melee;
Item.damage = 6;
Item.knockBack = 7;
Item.crit = 6;

Item.value = Item.buyPrice(copper: 20);
Item.rare = ItemRarityID.White;
Item.UseSound = SoundID.Item1;

Item.shoot = ModContent.ProjectileType<Projectiles.woodenwindmillprojectile>();
Item.shootSpeed = 8f; // Speed of the projectiles the sword will shoot

// If you want melee speed to only affect the swing speed of the weapon and not the shoot speed (not recommended)
// Item.attackSpeedOnlyAffectsWeaponAnimation = true;
}
// This method gets called when firing your weapon/sword.
public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback) {
Vector2 target = Main.screenPosition + new Vector2(Main.mouseX, Main.mouseY);
float ceilingLimit = target.Y;
if (ceilingLimit > player.Center.Y - 200f) {
ceilingLimit = player.Center.Y - 200f;
}
// Loop these functions 3 times.
for (int i = 0; i < 3; i++) {
position = player.Center - new Vector2(Main.rand.NextFloat(401) * player.direction, 600f);
position.Y -= 100 * i;
Vector2 heading = target - position;

if (heading.Y < 0f) {
heading.Y *= -1f;
}

if (heading.Y < 20f) {
heading.Y = 20f;
}

heading.Normalize();
heading *= velocity.Length();
heading.Y += Main.rand.Next(-40, 41) * 0.02f;
Projectile.NewProjectile(source, position, heading, type, damage * 2, knockback, player.whoAmI, 0f, ceilingLimit);
}

return false;
}

// Please see Content/ExampleRecipes.cs for a detailed explanation of recipe creation.
public override void AddRecipes() {
CreateRecipe()
.AddIngredient<ExampleItem>()
.AddTile<Tiles.Furniture.ExampleWorkbench>()
.Register();
}
}
}

here is the projectile's code:

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using Terraria;
using Terraria.Audio;
using Terraria.GameContent;
using Terraria.ID;
using Terraria.ModLoader;

namespace ExampleMod.Content.Projectiles
{
public class ExampleBullet : ModProjectile
{
public override void SetStaticDefaults() {
ProjectileID.Sets.TrailCacheLength[Projectile.type] = 5; // The length of old position to be recorded
ProjectileID.Sets.TrailingMode[Projectile.type] = 0; // The recording mode
}

public override void SetDefaults() {
Projectile.width = 8; // The width of projectile hitbox
Projectile.height = 32; // The height of projectile hitbox
Projectile.aiStyle = 45; // The ai style of the projectile, please reference the source code of Terraria
Projectile.friendly = true; // Can the projectile deal damage to enemies?
Projectile.hostile = false; // Can the projectile deal damage to the player?
Projectile.DamageType = DamageClass.Melee;
Projectile.penetrate = 3; // How many monsters the projectile can penetrate. (OnTileCollide below also decrements penetrate for bounces as well)
Projectile.timeLeft = 600; // The live time for the projectile (60 = 1 second, so 600 is 10 seconds)
Projectile.alpha = 255; // The transparency of the projectile, 255 for completely transparent. (aiStyle 1 quickly fades the projectile in) Make sure to delete this if you aren't using an aiStyle that fades in. You'll wonder why your projectile is invisible.
Projectile.light = 0.5f; // How much light emit around the projectile
Projectile.ignoreWater = true; // Does the projectile's speed be influenced by water?
Projectile.tileCollide = true; // Can the projectile collide with tiles?
Projectile.extraUpdates = 1; // Set to above 0 if you want the projectile to update multiple time in a frame

AIType = ProjectileID.DemonScythe; // Act exactly like default Bullet
}

public override bool OnTileCollide(Vector2 oldVelocity) {
// If collide with tile, reduce the penetrate.
// So the projectile can reflect at most 5 times
Projectile.penetrate--;
if (Projectile.penetrate <= 0) {
Projectile.Kill();
}
else {
Collision.HitTiles(Projectile.position, Projectile.velocity, Projectile.width, Projectile.height);
SoundEngine.PlaySound(SoundID.Item10, Projectile.position);

// If the projectile hits the left or right side of the tile, reverse the X velocity
if (Math.Abs(Projectile.velocity.X - oldVelocity.X) > float.Epsilon) {
Projectile.velocity.X = -oldVelocity.X;
}

// If the projectile hits the top or bottom side of the tile, reverse the Y velocity
if (Math.Abs(Projectile.velocity.Y - oldVelocity.Y) > float.Epsilon) {
Projectile.velocity.Y = -oldVelocity.Y;
}
}

return false;
}

public override bool PreDraw(ref Color lightColor) {
Main.instance.LoadProjectile(Projectile.type);
Texture2D texture = TextureAssets.Projectile[Projectile.type].Value;

// Redraw the projectile with the color not influenced by light
Vector2 drawOrigin = new Vector2(texture.Width * 0.5f, Projectile.height * 0.5f);
for (int k = 0; k < Projectile.oldPos.Length; k++) {
Vector2 drawPos = (Projectile.oldPos[k] - Main.screenPosition) + drawOrigin + new Vector2(0f, Projectile.gfxOffY);
Color color = Projectile.GetAlpha(lightColor) * ((Projectile.oldPos.Length - k) / (float)Projectile.oldPos.Length);
Main.EntitySpriteDraw(texture, drawPos, null, color, Projectile.rotation, drawOrigin, Projectile.scale, SpriteEffects.None, 0);
}

return true;
}

public override void Kill(int timeLeft) {
// This code and the similar code above in OnTileCollide spawn dust from the tiles collided with. SoundID.Item10 is the bounce sound you hear.
Collision.HitTiles(Projectile.position + Projectile.velocity, Projectile.velocity, Projectile.width, Projectile.height);
SoundEngine.PlaySound(SoundID.Item10, Projectile.position);
}
}
}
 
You have to fix your namespaces.

You have at the top - using sxjxtmod.Projectiles.woodenwindmillprojectile;
But your actual namespace in each file is still ExampleMod. You're still referencing things like ExampleItem, ExampleWorkbench, etc and your projectile class name is ExampleBullet even though it looks like you wanted to name it woodenwindmillprojectile
 
You have to fix your namespaces.

You have at the top - using sxjxtmod.Projectiles.woodenwindmillprojectile;
But your actual namespace in each file is still ExampleMod. You're still referencing things like ExampleItem, ExampleWorkbench, etc and your projectile class name is ExampleBullet even though it looks like you wanted to name it woodenwindmillprojectile
thanks!!!!! it works

the projectile's texture doesn't show but i think i might know what the problem is

edit: i do not know what the problem is
 
Last edited:
Back
Top Bottom