This is Many
Retinazer
Introduction
Hi everyone! This tutorial will be about creating a simple item (material) and a sword.
Perhaps I'm exaggerating a little, starting with 2 objects at once, but for those who read the previous tutorial and, as advised there, learned C#, this won't be difficult.
And one very important anon - we will now make mod for 1.4.4, not for 1.4.3!!!
Let's go!
What are we going to study in this tutorial:
- How to create simple item
- How to create a sword that can poison enemy
How to create simple item
This item will be the material for all subsequent items that we will create.
First draw the sprite. The size of most materials in Terraria doesn't exceed 40x40px.
You can use any raster graphics editor, from Paint.net to Photoshop.
I'm using PikoPixel (only able on macOS) and Piskel.
So, create an item sprite. My will be 22x24px.
IMPORTANT: Default Terraria pixel is 2x2px in every graphics editor.
How it looks in game
Second, create a .cs file for your material code.
Put it here - ModSources/YourModName/Content/Items/Materials. It's optional but most of mods uses this path.
And then, put this code in it (// are explanations):
It isn't hard, is it?
Your first item is ready, congrats!
How to create a sword that can poison enemy
Sword is the simpliest weapon you can make, so we'll increase "risk and reward" - we will add poison effect to enemies we hit.
Also, we will emit poison themed dust when the sword is swing for better effect.
For the primary sword we need this code:
Oof, sweaty. But this is just a generic sword that swings and deals 50 melee damage.
But we want to add some visuals (Dust) and combat advantages (Poison)
For Dust you need one more library:
And some additional code:
Also, we want to add poison effect to this sword, so we need this code:
Full code of poisoning sword looks like that:
Yeah, finally, that's done!
Ending
Thanks to everyone who read this tutorial! I hope you learned something new. Also, sorry for so long tutorial waiting.
Any questions are allowed! See you on the next tutorial!
Previous Tutorial / Next Tutorial
Hi everyone! This tutorial will be about creating a simple item (material) and a sword.
Perhaps I'm exaggerating a little, starting with 2 objects at once, but for those who read the previous tutorial and, as advised there, learned C#, this won't be difficult.
And one very important anon - we will now make mod for 1.4.4, not for 1.4.3!!!
Let's go!
What are we going to study in this tutorial:
- How to create simple item
- How to create a sword that can poison enemy
How to create simple item
This item will be the material for all subsequent items that we will create.
First draw the sprite. The size of most materials in Terraria doesn't exceed 40x40px.
You can use any raster graphics editor, from Paint.net to Photoshop.
I'm using PikoPixel (only able on macOS) and Piskel.
So, create an item sprite. My will be 22x24px.
IMPORTANT: Default Terraria pixel is 2x2px in every graphics editor.
How it looks in game
Second, create a .cs file for your material code.
Put it here - ModSources/YourModName/Content/Items/Materials. It's optional but most of mods uses this path.
And then, put this code in it (// are explanations):
C#:
// What libraries we use in the code
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.Localization;
using Terraria.GameContent.Creative;
namespace SteelMod.Content.Items.Materials // Where your code located
{
public class SteelShard : ModItem // Your item name (SteelShard) and type (ModItem)
{
public override void SetStaticDefaults()
{
CreativeItemSacrificesCatalog.Instance.SacrificeCountNeededByItemId[Type] = 100; // How many items need for research in Journey Mode
}
public override void SetDefaults()
{
Item.width = 22; // Width of an item sprite
Item.height = 24; // Height of an item sprite
Item.maxStack = 9999; // How many items can be in one inventory slot
Item.value = 100; // Item sell price in copper coins
Item.rare = ItemRarityID.Blue; // The color of item's name in game. Check https://terraria.wiki.gg/wiki/Rarity
}
}
}
Your first item is ready, congrats!
How to create a sword that can poison enemy
Sword is the simpliest weapon you can make, so we'll increase "risk and reward" - we will add poison effect to enemies we hit.
Also, we will emit poison themed dust when the sword is swing for better effect.
For the primary sword we need this code:
C#:
using SteelMod.Content.Items.Materials; // Using our Materials folder
using Terraria;
using Terraria.GameContent.Creative;
using Terraria.ID;
using Terraria.ModLoader;
namespace SteelMod.Content.Items.Weapons.Melee // Where is your code locates
{
public class SteelSword : ModItem
{
public override void SetStaticDefaults()
{
CreativeItemSacrificesCatalog.Instance.SacrificeCountNeededByItemId[Type] = 1; // How many items need for research in Journey Mode
}
public override void SetDefaults()
{
// Visual properties
Item.width = 40; // Width of an item sprite
Item.height = 40; // Height of an item sprite
Item.scale = 1f; // Multiplicator of item size, for example is you set this to 2f our sword will be biger twice. IMPORTANT: If you are using numbers with floating point, write "f" in their end, like 1.5f, 3.14f, 2.1278495f etc.
Item.rare = ItemRarityID.Blue; // The color of item's name in game. Check https://terraria.wiki.gg/wiki/Rarity
// Combat properties
Item.damage = 50; // Item damage
Item.DamageType = DamageClass.Melee; // What type of damage item is deals, Melee, Ranged, Magic, Summon, Generic (takes bonuses from all damage multipliers), Default (doesn't take bonuses from any damage multipliers)
// useTime and useAnimation often use the same value, but we'll see examples where they don't use the same values
Item.useTime = 20; // How long the swing lasts in ticks (60 ticks = 1 second)
Item.useAnimation = 20; // How long the swing animation lasts in ticks (60 ticks = 1 second)
Item.knockBack = 6f; // How far the sword punches enemies, 20 is maximal value
Item.autoReuse = true; // Can the item auto swing by holding the attack button
// Other properties
Item.value = 10000; // Item sell price in copper coins
Item.useStyle = ItemUseStyleID.Swing; // This is how you're holding the weapon, visit https://terraria.wiki.gg/wiki/Use_Style_IDs for list of possible use styles
Item.UseSound = SoundID.Item1; // What sound is played when using the item, all sounds can be found here - https://terraria.wiki.gg/wiki/Sound_IDs
}
// Creating item craft
public override void AddRecipes()
{
Recipe recipe = CreateRecipe();
recipe.AddIngredient<SteelShard>(7); // We are using custom material for the craft, 7 Steel Shards
recipe.AddIngredient(ItemID.Wood, 3); // Also, we are using vanilla material to craft, 3 Wood
recipe.AddTile(TileID.Anvils); // Crafting station we need for craft, WorkBenches, Anvils etc. You can find them here - https://terraria.wiki.gg/wiki/Tile_IDs
recipe.Register();
}
}
}
But we want to add some visuals (Dust) and combat advantages (Poison)
For Dust you need one more library:
C#:
using Microsoft.Xna.Framework; // Using another one library
And some additional code:
C#:
public override void MeleeEffects(Player player, Rectangle hitbox)
{
if (Main.rand.NextBool(3)) // With 1/3 chance per tick (60 ticks = 1 second)...
{
// ...spawning dust
Dust.NewDust(new Vector2(hitbox.X, hitbox.Y), // Position to spawn
hitbox.Width, hitbox.Height, // Width and Height
DustID.Poisoned, // Dust type. Check https://terraria.wiki.gg/wiki/Dust_IDs
0, 0, // Speed X and Speed Y of dust, it have some randomization
125); // Dust transparency, 0 - full visibility, 255 - full transparency
}
}
C#:
// What is happening on hitting living entity
public override void OnHitNPC(Player player, NPC target, NPC.HitInfo hit, int damageDone)
{
if (Main.rand.NextBool(4)) // 1/4 chance, or 25% in other words
{
target.AddBuff(BuffID.Poisoned, // Adding Poisoned to target
300); // for 5 seconds (60 ticks = 1 second)
}
}
C#:
using Microsoft.Xna.Framework; // Using another one library
using SteelMod.Content.Items.Materials; // Using our Materials folder
using Terraria;
using Terraria.GameContent.Creative;
using Terraria.ID;
using Terraria.ModLoader;
namespace SteelMod.Content.Items.Weapons.Melee // Where is your code locates
{
public class PoisonedSteelSword : ModItem
{
public override void SetStaticDefaults()
{
CreativeItemSacrificesCatalog.Instance.SacrificeCountNeededByItemId[Type] = 1; // How many items need for research in Journey Mode
}
public override void SetDefaults()
{
// Visual properties
Item.width = 40; // Width of an item sprite
Item.height = 40; // Height of an item sprite
Item.scale = 1f; // Multiplicator of item size, for example is you set this to 2f our sword will be biger twice. IMPORTANT: If you are using numbers with floating point, write "f" in their end, like 1.5f, 3.14f, 2.1278495f etc.
Item.rare = ItemRarityID.Blue; // The color of item's name in game. See https://terraria.wiki.gg/wiki/Rarity
// Combat properties
Item.damage = 50; // Item damage
Item.DamageType = DamageClass.Melee; // What type of damage item is deals, Melee, Ranged, Magic, Summon, Generic (takes bonuses from all damage multipliers), Default (doesn't take bonuses from any damage multipliers)
// useTime and useAnimation often use the same value, but we'll see examples where they don't use the same values
Item.useTime = 20; // How long the swing lasts in ticks (60 ticks = 1 second)
Item.useAnimation = 20; // How long the swing animation lasts in ticks (60 ticks = 1 second)
Item.knockBack = 6f; // How far the sword punches enemies, 20 is maximal value
Item.autoReuse = true; // Can the item auto swing by holding the attack button
// Other properties
Item.value = 10000; // Item sell price in copper coins
Item.useStyle = ItemUseStyleID.Swing; // This is how you're holding the weapon, visit https://terraria.wiki.gg/wiki/Use_Style_IDs for list of possible use styles
Item.UseSound = SoundID.Item1; // What sound is played when using the item, all sounds can be found here - https://terraria.wiki.gg/wiki/Sound_IDs
}
public override void MeleeEffects(Player player, Rectangle hitbox)
{
if (Main.rand.NextBool(3)) // With 1/3 chance per tick (60 ticks = 1 second)...
{
// ...spawning dust
Dust.NewDust(new Vector2(hitbox.X, hitbox.Y), // Position to spawn
hitbox.Width, hitbox.Height, // Width and Height
DustID.Poisoned, // Dust type. Check https://terraria.wiki.gg/wiki/Dust_IDs
0, 0, // Speed X and Speed Y of dust, it have some randomization
125); // Dust transparency, 0 - full visibility, 255 - full transparency
}
}
// What is happening on hitting living entity
public override void OnHitNPC(Player player, NPC target, NPC.HitInfo hit, int damageDone)
{
if (Main.rand.NextBool(4)) // 1/4 chance, or 25% in other words
{
target.AddBuff(BuffID.Poisoned, // Adding Poisoned to target
300); // for 5 seconds (60 ticks = 1 second)
}
}
// Creating item craft
public override void AddRecipes()
{
Recipe recipe = CreateRecipe();
recipe.AddIngredient<SteelShard>(7); // We are using custom material for the craft, 7 Steel Shards
recipe.AddIngredient(ItemID.Wood, 3); // Also, we are using vanilla material to craft, 3 Wood
recipe.AddIngredient(ItemID.JungleSpores, 5); // I've added some Jungle Spores to craft
recipe.AddTile(TileID.Anvils); // Crafting station we need for craft, WorkBenches, Anvils etc. You can find them here - https://terraria.wiki.gg/wiki/Tile_IDs
recipe.Register();
}
}
}
Yeah, finally, that's done!
Ending
Thanks to everyone who read this tutorial! I hope you learned something new. Also, sorry for so long tutorial waiting.
Any questions are allowed! See you on the next tutorial!
Previous Tutorial / Next Tutorial
Last edited: