Skip to content

Instantly share code, notes, and snippets.

@jdrews
Created August 12, 2023 23:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdrews/c5fc3a8dbefd3fd61766551548671e4e to your computer and use it in GitHub Desktop.
Save jdrews/c5fc3a8dbefd3fd61766551548671e4e to your computer and use it in GitHub Desktop.
Terraria Mod Sword
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace DrewsSword.Items
{
public class DrewSword : ModItem
{
// The Display Name and Tooltip of this item can be edited in the Localization/en-US_Mods.DrewsSword.hjson file.
public override void SetDefaults()
{
Item.damage = 100;
Item.DamageType = DamageClass.Melee;
Item.width = 40;
Item.height = 40;
Item.useTime = 10;
Item.useAnimation = 10;
Item.useStyle = 1;
Item.knockBack = 6;
Item.value = 10000;
Item.rare = 2;
Item.UseSound = SoundID.Item1;
Item.autoReuse = true;
}
public override void AddRecipes()
{
Recipe recipe = CreateRecipe();
recipe.AddIngredient(ItemID.DirtBlock, 10);
recipe.AddTile(TileID.WorkBenches);
recipe.Register();
}
public override void MeleeEffects(Player player, Rectangle hitbox)
{
if (Main.rand.NextBool(3))
{
// Emit dusts when the sword is swung
Dust.NewDust(new Vector2(hitbox.X, hitbox.Y), hitbox.Width, hitbox.Height, 74);
}
}
public override void OnHitNPC(Player player, NPC target, NPC.HitInfo hit, int damageDone)
{
// Inflict the OnFire debuff for 1 second onto any NPC/Monster that this hits.
// 60 frames = 1 second
target.AddBuff(BuffID.OnFire, 60);
}
}
}