tModLoader Need help making colored light emit from dust.

RazzyB

Terrarian
I am making a mod (Shank's Mod) and have ran into a little problem. I am not sure how to make dust from melee weapons emit light.
The code for the weapon and the dust are here.
 
Weapon Code:


using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace ShanksMod.Items
{
public class Vendetta : ModItem
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Vendetta");
Tooltip.SetDefault("Forged specially for someone...");
}
public override void SetDefaults()
{
item.damage = 60;
item.melee = true;
item.width = 40;
item.height = 40;
item.useTime = 10;
item.useAnimation = 10;
item.useStyle = 1;
item.knockBack = 6;
item.value = 10000;
item.rare = 8;
item.UseSound = SoundID.Item1;
item.autoReuse = true;
item.useTurn = true;

}

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.HellstoneBar, 20);
recipe.AddIngredient(ItemID.SoulofMight, 10);
recipe.AddIngredient(ItemID.SoulofSight, 10);
recipe.AddIngredient(ItemID.SoulofFright, 10);
recipe.AddIngredient(ItemID.HallowedBar, 15);
recipe.AddIngredient(null, "VendetiteBar", 10);
recipe.AddTile(TileID.MythrilAnvil);
recipe.SetResult(this);
recipe.AddRecipe();
}
public override void MeleeEffects(Player player, Rectangle hitbox)
{
if (Main.rand.Next(3) == 0)
{

Dust.NewDust(new Vector2(hitbox.X, hitbox.Y), hitbox.Width, hitbox.Height, mod.DustType("VendetiteToolDust"));
}
}
}
}
[doublepost=1514235536,1514235513][/doublepost]Dust code:


using Terraria;
using Terraria.ModLoader;

namespace ShanksMod.Items
{
public class VendetiteToolDust : ModDust
{
public override void OnSpawn(Dust dust)
{
dust.velocity *= 0.6f; // Mulitiply the Velocity on both X and Y by a float (Example 0.6f)
dust.noGravity = true; // Dust doesn't fall to the ground
dust.noLight = false; // Dust doesn't emit light
dust.scale *= 1f; // The scale of the graphic (Default: 1f)
}

public override bool Update(Dust dust)
{
dust.position += dust.velocity; // Moves the dust according to the velocity.
dust.rotation += dust.velocity.X * 0.2f; // Will rotate the dust based on Velocity.
dust.scale *= 0.90f; // Will decrease the scale over time
if (dust.scale < 0.5f)
{
dust.active = false;
}
return false;
}

}
}
}
 
Okay, I don't know if anyone is reading this in 2020 but I was trying to figure this out for like 2 days... I finally got something that I'm satisfied with. To be completely honest, about 75% is copied and pasted from various mods or other forums, so I don't understand all of it. There also may be a WAYYYY easier way to do this, so don't just read this and accept it as law. I am always looking to learn, so if anyone can do this better, please show me!

The override of the Update(Dust dust) method will occur somewhere in the extended ModDust file. (Most likely "YourDustNameHere.cs", and beneath the overridden OnSpawn.)

The comments below are all my own basic explanations of what each line does. Keep in mind the Update method is called continuously why dust particles are active, and then stops once dust.active is set to a value of false.

Notice the two lines in the middle without comments. These were a little more complicated, and have to do with the brightness and color of the emitted light. The first of those two lines creates a float value called 'light' that gets smaller with each call of the Update method because the scale of the dust particle is also getting smaller with every call. The second light tells the light to be added at the position of the dust particle, and then gives the instructions for the color and brightness. Each of the three parenthesis group includes an rgb value multiplied by 0.01 (in this case, 255, 255, 255), a float constant (0.5), and the diminishing 'light' value from the previous line. The rgb value obviously determines the color, but the larger the number is, the brighter it is. (Hence my multiplying each value by 0.01 and then 0.5.) Feel free to mess around with these numbers however you want! Hint: a little goes a long way, try using 255, 255, and 255 directly in the code instead of 2.55, 2.55, 2.55 and see what happens.

I hope this helps!


public override bool Update(Dust dust)
{
dust.position += dust.velocity; // Moves the dust particle
dust.rotation += dust.velocity.X * 0.15f; // Rotates the dust particle so it doesn't move in the same direction every time
dust.scale *= 0.95f; // Makes the dust particle smaller by scaling it down to 95%
float light = 0.35f * dust.scale;
Lighting.AddLight(dust.position, (2.55f * 0.5f * light), (2.55f * 0.5f * light), (2.55f * 0.5f * light));
if (dust.scale < 0.5f) // checks to see if the size of the dust particle is smaller than specified scale limit (0.5f) in this case
{
dust.active = false; // if size of dust particle IS smaller than specified scale limit, the dust will disappear
}
return false;
}
 
Last edited:
I'm reading this. Thank you, actually, I've been trying to create a custom npc that glows but didn't know what to use. I know that isn't what this thread is about but thanks!
 
Okay, I don't know if anyone is reading this in 2020 but I was trying to figure this out for like 2 days... I finally got something that I'm satisfied with. To be completely honest, about 75% is copied and pasted from various mods or other forums, so I don't understand all of it. There also may be a WAYYYY easier way to do this, so don't just read this and accept it as law. I am always looking to learn, so if anyone can do this better, please show me!

The override of the Update(Dust dust) method will occur somewhere in the extended ModDust file. (Most likely "YourDustNameHere.cs", and beneath the overridden OnSpawn.)

The comments below are all my own basic explanations of what each line does. Keep in mind the Update method is called continuously why dust particles are active, and then stops once dust.active is set to a value of false.

Notice the two lines in the middle without comments. These were a little more complicated, and have to do with the brightness and color of the emitted light. The first of those two lines creates a float value called 'light' that gets smaller with each call of the Update method because the scale of the dust particle is also getting smaller with every call. The second light tells the light to be added at the position of the dust particle, and then gives the instructions for the color and brightness. Each of the three parenthesis group includes an rgb value multiplied by 0.01 (in this case, 255, 255, 255), a float constant (0.5), and the diminishing 'light' value from the previous line. The rgb value obviously determines the color, but the larger the number is, the brighter it is. (Hence my multiplying each value by 0.01 and then 0.5.) Feel free to mess around with these numbers however you want! Hint: a little goes a long way, try using 255, 255, and 255 directly in the code instead of 2.55, 2.55, 2.55 and see what happens.

I hope this helps!


public override bool Update(Dust dust)
{
dust.position += dust.velocity; // Moves the dust particle
dust.rotation += dust.velocity.X * 0.15f; // Rotates the dust particle so it doesn't move in the same direction every time
dust.scale *= 0.95f; // Makes the dust particle smaller by scaling it down to 95%
float light = 0.35f * dust.scale;
Lighting.AddLight(dust.position, (2.55f * 0.5f * light), (2.55f * 0.5f * light), (2.55f * 0.5f * light));
if (dust.scale < 0.5f) // checks to see if the size of the dust particle is smaller than specified scale limit (0.5f) in this case
{
dust.active = false; // if size of dust particle IS smaller than specified scale limit, the dust will disappear
}
return false;
}
Thanks! This is SUPER helpfull!
 
Back
Top Bottom