Standalone [1.3] tModLoader - A Modding API

Can anyone explain to me how
public virtual bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox)
in modProjectile works?
I'm trying to make a projectile have a damaging trail
Two rectangles are passed in, you decide if they "intersect".

Vanilla code just checks Rectangle.Intersects(Ractangle).

The projHitbox is based on projectile.width, projectile.height, projectile.position. Similar for the targetHitbox (but for an npc maybe).

Sometimes rectangles aren't perfect for what you want, such as MoonLords beam or Last Prism laser. If you made a bounding box around a laser, it would intersect with a lot of things the visuals don't show it actually hitting.

Use Collision.CheckAABBvLineCollision if you want :
public static bool CheckAABBvLineCollision(Vector2 objectPosition, Vector2 objectDimensions, Vector2 lineStart, Vector2 lineEnd, float lineWidth, ref float collisionPoint)
 
Two rectangles are passed in, you decide if they "intersect".

Vanilla code just checks Rectangle.Intersects(Ractangle).

The projHitbox is based on projectile.width, projectile.height, projectile.position. Similar for the targetHitbox (but for an npc maybe).

Sometimes rectangles aren't perfect for what you want, such as MoonLords beam or Last Prism laser. If you made a bounding box around a laser, it would intersect with a lot of things the visuals don't show it actually hitting.

Use Collision.CheckAABBvLineCollision if you want :
public static bool CheckAABBvLineCollision(Vector2 objectPosition, Vector2 objectDimensions, Vector2 lineStart, Vector2 lineEnd, float lineWidth, ref float collisionPoint)
For my projectile, having a little inaccurate rectangle collision doesn't matter.
Do you think this would work for a damaging trail?
Code:
public virtual bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox)
        {
            for (int i = 0; i < projectile.oldPos.Length; k++)
            {
                for (int pointX = projectile.oldPos[i].X; pointX < projectile.oldPos[i].X + projectile.width; pointX++)
                {
                    for (int pointY = projectile.oldPos[i].Y; pointY < projectile.oldPos[i].Y + projectile.height; pointY++)
                    {
                        if (targetHitbox.Contains(pointX, pointY))
                        {
                            return true;
                        }
                        else
                        {
                            return false;
                        }
                    }
                }
            }
        }
 
For my projectile, having a little inaccurate rectangle collision doesn't matter.
Do you think this would work for a damaging trail?
Code:
public virtual bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox)
        {
            for (int i = 0; i < projectile.oldPos.Length; k++)
            {
                for (int pointX = projectile.oldPos[i].X; pointX < projectile.oldPos[i].X + projectile.width; pointX++)
                {
                    for (int pointY = projectile.oldPos[i].Y; pointY < projectile.oldPos[i].Y + projectile.height; pointY++)
                    {
                        if (targetHitbox.Contains(pointX, pointY))
                        {
                            return true;
                        }
                        else
                        {
                            return false;
                        }
                    }
                }
            }
        }
Move the return false to the end of the method. Should work. Make sure the original non-tail hitbox is still being checked.
 
Hey guys when I Compile the code it works correctly but i cannot seem to find/craft the items ive made.
 
Ok, same weapon, new question.

I'm trying to get it to activate the Ironskin buff when I hit an enemy. No luck so far.

Here is the code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Terravalice.Items.KnightSwords
{
public class SavetheQueen : ModItem
{
public override void SetDefaults()
{
item.name = "Save the Queen";
item.melee = true;
item.damage = 36;
item.knockBack = 5;
item.width = 30;
item.height = 30;
item.useStyle = 1;
item.useAnimation = 20;
item.useTime = 20;
item.useSound = 1;
item.value = 30000;
item.rare = 2;
}

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(Terraria.ID.ItemID.Wood, 1);
recipe.SetResult(this);
recipe.AddRecipe();
}
// Ironskin effect (protect)
public override void DamageNPC (Player myPlayer, Item item, NPC npc, ref int damage, ref float knockBack)
{
// Add the buff
myPlayer.AddBuff (BuffID.Ironskin, 600);
}
}
}

I'm working on porting over old tConfig code, so that my be messing me up. =/
 
Hello, i was wondering how you would go about updating the tModLoader, if you dont need to or if there is an explanation in the description please do tell me, Thanks!

UPDATED: Nevermind i fond out hoe to update it
 
Last edited:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Hypaxi.Items.Weapons
{
public class IronWill : ModItem
{
public override void SetDefaults()
{
item.name = "Iron Will";
item.melee = true;
item.damage = 45;
item.knockBack = 5;
item.width = 30;
item.height = 30;
item.useStyle = 1;
item.useAnimation = 20;
item.useTime = 1;
item.useSound = 1;
item.value = 30000;
item.rare = 2;
}

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(Terraria.ID.ItemID.Wood, 1);
recipe.SetResult(this);
recipe.AddRecipe();
}
}
}

Can someone actually explain what I'm doing wrong because its building the mod but i cannot get the item.
 
Ok, same weapon, new question.

I'm trying to get it to activate the Ironskin buff when I hit an enemy. No luck so far.

Here is the code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Terravalice.Items.KnightSwords
{
public class SavetheQueen : ModItem
{
public override void SetDefaults()
{
item.name = "Save the Queen";
item.melee = true;
item.damage = 36;
item.knockBack = 5;
item.width = 30;
item.height = 30;
item.useStyle = 1;
item.useAnimation = 20;
item.useTime = 20;
item.useSound = 1;
item.value = 30000;
item.rare = 2;
}

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(Terraria.ID.ItemID.Wood, 1);
recipe.SetResult(this);
recipe.AddRecipe();
}
// Ironskin effect (protect)
public override void DamageNPC (Player myPlayer, Item item, NPC npc, ref int damage, ref float knockBack)
{
// Add the buff
myPlayer.AddBuff (BuffID.Ironskin, 600);
}
}
}

I'm working on porting over old tConfig code, so that my be messing me up. =/

You want to override OnHitNPC instead of DamageNPC.
Code:
public override void OnHitNPC(Player player, NPC target, int damage, float knockback, bool crit)
{
player.AddBuff(BuffID.Ironskin, 600);
}
 
Last edited:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Hypaxi.Items.Weapons
{
public class IronWill : ModItem
{
public override void SetDefaults()
{
item.name = "Iron Will";
item.melee = true;
item.damage = 45;
item.knockBack = 5;
item.width = 30;
item.height = 30;
item.useStyle = 1;
item.useAnimation = 20;
item.useTime = 1;
item.useSound = 1;
item.value = 30000;
item.rare = 2;
}

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(Terraria.ID.ItemID.Wood, 1);
recipe.SetResult(this);
recipe.AddRecipe();
}
}
}

Can someone actually explain what I'm doing wrong because its building the mod but i cannot get the item.
Have you enabled it's? and then reloaded mods as well?
 
You want to override OnHitNPC instead of DamageNPC.
Code:
public override void OnHitNPC(Player player, NPC target, int damage, float knockback, bool crit)
{
player.AddBuff(BuffID.Ironskin, 600);
}

Of course I have
 
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Hypaxi.Items.Weapons
{
public class IronWill : ModItem
{
public override void SetDefaults()
{
item.name = "Iron Will";
item.melee = true;
item.damage = 45;
item.knockBack = 5;
item.width = 30;
item.height = 30;
item.useStyle = 1;
item.useAnimation = 20;
item.useTime = 1;
item.useSound = 1;
item.value = 30000;
item.rare = 2;
}

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(Terraria.ID.ItemID.Wood, 1);
recipe.SetResult(this);
recipe.AddRecipe();
}
}
}

Can someone actually explain what I'm doing wrong because its building the mod but i cannot get the item.
Are you setting autoload to true in the Mod.cs, do you have a class that extends mod?
 
Is there a way to change how the player animates when an item is used, kind of like HoldItemFrame, only called at the same time as UseStyle? I tried changing the player's frame in UseStyle, but it had no effect. Thanks.
 
Is there a way to change how the player animates when an item is used, kind of like HoldItemFrame, only called at the same time as UseStyle? I tried changing the player's frame in UseStyle, but it had no effect. Thanks.

Sounds like you want UseItemFrame.
 
My projectile's trail isn't being drawn on the screen. Can anyone help me?
Code:
public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
        {
            Vector2 drawOrigin = new Vector2(Main.projectileTexture[projectile.type].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);
                spriteBatch.Draw(Main.projectileTexture[projectile.type], drawPos, null, Color.White, projectile.rotation, drawOrigin, projectile.scale, SpriteEffects.None, 0f);
            }
            return true;
        }
EDIT: nevermind I fixed it
 
Can anyone tell where to find buffs in Terraria's source code? I'm trying to find source code for vanilla buffs, but it seems that there isn't a Buff class in vanilla Terraria(like with tiles).
 
Can anyone tell where to find buffs in Terraria's source code? I'm trying to find source code for vanilla buffs, but it seems that there isn't a Buff class in vanilla Terraria(like with tiles).
You should probably check with the Player class's update methods. Those should be the ones that does the stuff when the player has a buff.
 
I think you quoted the wrong person there.

No I do not think I have. and being the person whom is new at this I don't know how to do that.
 
Hello, i am having trouble playing the
ZoaklenMod
This is the error that came up once i tried to load the mod:
The classes in the module cannot be loaded.
at (wrapper managed-to-native) System.Reflection.Assembly:GetTypes (System.Reflection.Assembly,bool)
at System.Reflection.Assembly.GetTypes () [0x00000] in <filename unknown>:0
at Terraria.ModLoader.ModLoader.LoadMod (Terraria.ModLoader.IO.TmodFile modFile, Terraria.ModLoader.BuildProperties properties) [0x00000] in <filename unknown>:0
at Terraria.ModLoader.ModLoader.LoadMods () [0x00000] in <filename unknown>:0
Im posting this incase it has something to do with the mod loader and not the mod itself, if you can help that would be great. Thanks
 
how do i upgrade to the latest version :confused:
 
Back
Top Bottom