Standalone [1.3] tModLoader - A Modding API

Still having a hard time denying a certain item from being picked.... Seems I cannot find how vanilla codes deny player from picking items when his inventory is full. So gotta have to ask again. Little help?
You can use this function to determine wether or not the item can be picked up. This does not apply to items being picked up from chests, so keep that in mind.
 
how do I use this?
public virtual bool CanExplode(int i, int j)
 
how do I use this?
public virtual bool CanExplode(int i, int j)
You return false if you do not want the tile to explode and return true... For the vice-versa effect.
 
how do I use this?
public virtual bool CanExplode(int i, int j)
The int i and int j are the tile location. U can do things like
if(tile.type == ItemID.Anvils) return false;
if(Main.player[Main.myPlayer].position.X < i) return false;
and all kinds of trickery like that.
Personally I use it to prevent my house tiles from getting accidentally blown up when someone forgets they got stickybombs equipped

Edit: not to rush or anything, but i've kinda hit a roadblock in my modding.

i need some item related stuff, namely saving and loading (for GlobalItem). i would also like to make prefixes/suffixes, but the main thing i need is save/load.
also this is additional but i want to be able to
Code:
                if (tile.inActive())
                {
                    Wiring.ReActive(i, j);
                }
                else
                {
                    Wiring.DeActive(i, j);
                }
but i can't since its private
 
Last edited:
It is, with a bit of (I guess you could say) 'hacky' code.
You can override the Pre/PostDraw function on a class that derives from GlobalItem, which will make it so your UI is persistent.
Do note, however, that this is (like mentioned before) a 'hacky' approach, since offocial UI draw hooks have not been implemented in tModLoader as of yet.
 
You can use this function to determine wether or not the item can be picked up. This does not apply to items being picked up from chests, so keep that in mind.
Yeah, I know this. But... I'm desperate in expressing my idea, but I'm always ambiguous about it... Although this hook returns false, Isn't an item still can be "picked" by a player? Only this item won't appear in their inventory, but they will pick it. The item will just go missing. What I'm tryna do is to deny the player from picking the item, which means the item will not even respond to the player when he gets close to the item, precisely like when a player has a full inventory...
 
It is, with a bit of (I guess you could say) 'hacky' code.
You can override the Pre/PostDraw function on a class that derives from GlobalItem, which will make it so your UI is persistent.
Do note, however, that this is (like mentioned before) a 'hacky' approach, since offocial UI draw hooks have not been implemented in tModLoader as of yet.
thanks for the info, i guess i'll wait for "oficial" support, hacky code can be a hell to maintain, and even worse to later port to non-hacky xD
 
Well, dunno if my msg reached someone but gonna reask it, is there any way to do chlorophyte bullet like sharp turn while high speed flying homing for a projectile ?
My current code for homing is @jopojelly Vampire scourge homing code, but is isn't exactly what I need.
@Kazzymodus
@Sin Costan
@Eldrazi
Help ? ^^''
 
Well, dunno if my msg reached someone but gonna reask it, is there any way to do chlorophyte bullet like sharp turn while high speed flying homing for a projectile ?
My current code for homing is @jopojelly Vampire scourge homing code, but is isn't exactly what I need.
@Kazzymodus
@Sin Costan
@Eldrazi
Help ? ^^''
Yes, that is possible. Just use the Chlorophyte Bullet code?
 
how do i get the vanilla boss codes for use in the if()

ExampleWorld.downedAbomination
this one works but thats a modded boss

i like to get all the vanilla bosses for this
 
@Eldrazi :
Code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ModLoader;

namespace HyperTerraria.Projectiles
{
    public class EnchantedChlorophyteRound : ModProjectile
    {

        public override void SetDefaults()
        {
            projectile.name = "Enchanted Chlorophyte Bullet";
            projectile.alpha = 255;
            projectile.width = 16;
            projectile.height = 16;
            projectile.friendly = true;
            projectile.ranged = true;
           
            projectile.penetrate = 1;
            projectile.timeLeft = 2000;
            /*ProjectileID.Sets.Homing[ModProjectile] = true;
            */
            projectile.tileCollide = true;
            projectile.ignoreWater = true;
            projectile.aiStyle = 340;
            projectile.light = 1;
           
          
        }
    

  public override bool PreAI()
       
        //    return base.PreAI();
        //}

        //public override void AI()
        //{
            {
            if (projectile.alpha > 0)
            {
                projectile.alpha -= 50;
            }
            else
            {
                projectile.extraUpdates = 0;
            }
            if (projectile.alpha < 0)
            {
                projectile.alpha = 0;
            }
            projectile.rotation = (float)System.Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) - 1.57f;
            projectile.frameCounter++;
            if (projectile.frameCounter >= 6)
            {
                projectile.frame++;
                projectile.frameCounter = 0;
            }
            if (projectile.frame >= 2)
            {
                projectile.frame = 0;
            }
            for (int num363 = 0; num363 < 3; num363++)
            {
                float num364 = projectile.velocity.X / 3f * (float)num363;
                float num365 = projectile.velocity.Y / 3f * (float)num363;
                int num161 = Dust.NewDust(projectile.position, projectile.width, projectile.height, 74, 0f, 0f, 0, default(Color), 1f);
                Main.dust[num161].position.X = projectile.Center.X - num364;
                Main.dust[num161].position.Y = projectile.Center.Y - num365;
                Main.dust[num161].velocity *= 0f;
                Main.dust[num161].scale = 0.5f;
            }

            float num367 = projectile.position.X;
            float num368 = projectile.position.Y;
            float num369 = 100000f;
            bool flag10 = false;
            projectile.ai[0] += 1f;
         
                for (int num370 = 0; num370 < 200; num370++)
                {
                    if (Main.npc[num370].CanBeChasedBy(projectile, false) && (!Main.npc[num370].wet /*|| projectile.type == 307*/))
                    {
                        float num371 = Main.npc[num370].position.X + (float)(Main.npc[num370].width / 2);
                        float num372 = Main.npc[num370].position.Y + (float)(Main.npc[num370].height / 2);
                        float num373 = System.Math.Abs(projectile.position.X + (float)(projectile.width / 2) - num371) + System.Math.Abs(projectile.position.Y + (float)(projectile.height / 2) - num372);
                        if (num373 < 800f && num373 < num369 && Collision.CanHit(projectile.position, projectile.width, projectile.height, Main.npc[num370].position, Main.npc[num370].width, Main.npc[num370].height))
                        {
                            num369 = num373;
                            num367 = num371;
                            num368 = num372;
                            flag10 = true;
                        }
                    }
               
            }
            if (!flag10)
            {
                num367 = projectile.position.X + (float)(projectile.width / 2) + projectile.velocity.X * 100f;
                num368 = projectile.position.Y + (float)(projectile.height / 2) + projectile.velocity.Y * 100f;
            }
            else /*if (projectile.type == 307)*/
            {
                projectile.friendly = true;
            }
            float num374 = 6f;
            float num375 = 0.1f;

            num374 = 9f;
            num375 = 0.2f;

            Vector2 vector27 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f);
            float num376 = num367 - vector27.X;
            float num377 = num368 - vector27.Y;
            float num378 = (float)System.Math.Sqrt((double)(num376 * num376 + num377 * num377));
            num378 = num374 / num378;
            num376 *= num378;
            num377 *= num378;
            if (projectile.velocity.X < num376)
            {
                projectile.velocity.X = projectile.velocity.X + num375;
                if (projectile.velocity.X < 0f && num376 > 0f)
                {
                    projectile.velocity.X = projectile.velocity.X + num375 * 2f;
                }
            }
            else if (projectile.velocity.X > num376)
            {
                projectile.velocity.X = projectile.velocity.X - num375;
                if (projectile.velocity.X > 0f && num376 < 0f)
                {
                    projectile.velocity.X = projectile.velocity.X - num375 * 2f;
                }
            }
            if (projectile.velocity.Y < num377)
            {
                projectile.velocity.Y = projectile.velocity.Y + num375;
                if (projectile.velocity.Y < 0f && num377 > 0f)
                {
                    projectile.velocity.Y = projectile.velocity.Y + num375 * 2f;
                    return false;
                }
            }
            else if (projectile.velocity.Y > num377)
            {
                projectile.velocity.Y = projectile.velocity.Y - num375;
                if (projectile.velocity.Y > 0f && num377 < 0f)
                {
                    projectile.velocity.Y = projectile.velocity.Y - num375 * 2f;
                    return false;
                }
            }

            return false;
        }
    }

   
}
Please note, I don't want it to be reflecteable ^^
 
@Eldrazi :
Code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ModLoader;

namespace HyperTerraria.Projectiles
{
    public class EnchantedChlorophyteRound : ModProjectile
    {

        public override void SetDefaults()
        {
            projectile.name = "Enchanted Chlorophyte Bullet";
            projectile.alpha = 255;
            projectile.width = 16;
            projectile.height = 16;
            projectile.friendly = true;
            projectile.ranged = true;
          
            projectile.penetrate = 1;
            projectile.timeLeft = 2000;
            /*ProjectileID.Sets.Homing[ModProjectile] = true;
            */
            projectile.tileCollide = true;
            projectile.ignoreWater = true;
            projectile.aiStyle = 340;
            projectile.light = 1;
          
         
        }
   

  public override bool PreAI()
      
        //    return base.PreAI();
        //}

        //public override void AI()
        //{
            {
            if (projectile.alpha > 0)
            {
                projectile.alpha -= 50;
            }
            else
            {
                projectile.extraUpdates = 0;
            }
            if (projectile.alpha < 0)
            {
                projectile.alpha = 0;
            }
            projectile.rotation = (float)System.Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) - 1.57f;
            projectile.frameCounter++;
            if (projectile.frameCounter >= 6)
            {
                projectile.frame++;
                projectile.frameCounter = 0;
            }
            if (projectile.frame >= 2)
            {
                projectile.frame = 0;
            }
            for (int num363 = 0; num363 < 3; num363++)
            {
                float num364 = projectile.velocity.X / 3f * (float)num363;
                float num365 = projectile.velocity.Y / 3f * (float)num363;
                int num161 = Dust.NewDust(projectile.position, projectile.width, projectile.height, 74, 0f, 0f, 0, default(Color), 1f);
                Main.dust[num161].position.X = projectile.Center.X - num364;
                Main.dust[num161].position.Y = projectile.Center.Y - num365;
                Main.dust[num161].velocity *= 0f;
                Main.dust[num161].scale = 0.5f;
            }

            float num367 = projectile.position.X;
            float num368 = projectile.position.Y;
            float num369 = 100000f;
            bool flag10 = false;
            projectile.ai[0] += 1f;
        
                for (int num370 = 0; num370 < 200; num370++)
                {
                    if (Main.npc[num370].CanBeChasedBy(projectile, false) && (!Main.npc[num370].wet /*|| projectile.type == 307*/))
                    {
                        float num371 = Main.npc[num370].position.X + (float)(Main.npc[num370].width / 2);
                        float num372 = Main.npc[num370].position.Y + (float)(Main.npc[num370].height / 2);
                        float num373 = System.Math.Abs(projectile.position.X + (float)(projectile.width / 2) - num371) + System.Math.Abs(projectile.position.Y + (float)(projectile.height / 2) - num372);
                        if (num373 < 800f && num373 < num369 && Collision.CanHit(projectile.position, projectile.width, projectile.height, Main.npc[num370].position, Main.npc[num370].width, Main.npc[num370].height))
                        {
                            num369 = num373;
                            num367 = num371;
                            num368 = num372;
                            flag10 = true;
                        }
                    }
              
            }
            if (!flag10)
            {
                num367 = projectile.position.X + (float)(projectile.width / 2) + projectile.velocity.X * 100f;
                num368 = projectile.position.Y + (float)(projectile.height / 2) + projectile.velocity.Y * 100f;
            }
            else /*if (projectile.type == 307)*/
            {
                projectile.friendly = true;
            }
            float num374 = 6f;
            float num375 = 0.1f;

            num374 = 9f;
            num375 = 0.2f;

            Vector2 vector27 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f);
            float num376 = num367 - vector27.X;
            float num377 = num368 - vector27.Y;
            float num378 = (float)System.Math.Sqrt((double)(num376 * num376 + num377 * num377));
            num378 = num374 / num378;
            num376 *= num378;
            num377 *= num378;
            if (projectile.velocity.X < num376)
            {
                projectile.velocity.X = projectile.velocity.X + num375;
                if (projectile.velocity.X < 0f && num376 > 0f)
                {
                    projectile.velocity.X = projectile.velocity.X + num375 * 2f;
                }
            }
            else if (projectile.velocity.X > num376)
            {
                projectile.velocity.X = projectile.velocity.X - num375;
                if (projectile.velocity.X > 0f && num376 < 0f)
                {
                    projectile.velocity.X = projectile.velocity.X - num375 * 2f;
                }
            }
            if (projectile.velocity.Y < num377)
            {
                projectile.velocity.Y = projectile.velocity.Y + num375;
                if (projectile.velocity.Y < 0f && num377 > 0f)
                {
                    projectile.velocity.Y = projectile.velocity.Y + num375 * 2f;
                    return false;
                }
            }
            else if (projectile.velocity.Y > num377)
            {
                projectile.velocity.Y = projectile.velocity.Y - num375;
                if (projectile.velocity.Y > 0f && num377 < 0f)
                {
                    projectile.velocity.Y = projectile.velocity.Y - num375 * 2f;
                    return false;
                }
            }

            return false;
        }
    }

  
}
Please note, I don't want it to be reflecteable ^^
Hmm, have you tried changing these values:
Code:
num374 = 9f;
num375 = 0.2f;
in the AI to something bigger? Like 14 instead of 9?
 
i'd like to either use the tinkerer's reforge to improve a weapon, or create my own, anyone know a way how?
 
Yeah, I know this. But... I'm desperate in expressing my idea, but I'm always ambiguous about it... Although this hook returns false, Isn't an item still can be "picked" by a player? Only this item won't appear in their inventory, but they will pick it. The item will just go missing. What I'm tryna do is to deny the player from picking the item, which means the item will not even respond to the player when he gets close to the item, precisely like when a player has a full inventory...
There isn't a hook for that. Why not just have it make a second item in your inventory and start counting from 0 durability again
 
The int i and int j are the tile location. U can do things like
if(tile.type == ItemID.Anvils) return false;
if(Main.player[Main.myPlayer].position.X < i) return false;
and all kinds of trickery like that.
Personally I use it to prevent my house tiles from getting accidentally blown up when someone forgets they got stickybombs equipped

Edit: not to rush or anything, but i've kinda hit a roadblock in my modding.

i need some item related stuff, namely saving and loading (for GlobalItem). i would also like to make prefixes/suffixes, but the main thing i need is save/load.
also this is additional but i want to be able to
Code:
                if (tile.inActive())
                {
                    Wiring.ReActive(i, j);
                }
                else
                {
                    Wiring.DeActive(i, j);
                }
but i can't since its private
I dont understand. should I just do return true;
 
giphy.gif


How to let the projectiles spin on its own axis?

And, why does the staff floats a little bit above the players hand ?
I already added
Code:
Item.staff[item.type] = true;
 
I dont understand. should I just do return true;
CanExplode = things that can be exploded

in my example, i made it so anvils cannot be exploded. return false anything you want to be protected from explosions
 
I have been trying to create a boss. Currently, I only have 2 lines of (non-debugging & assigning at the beginning) code in my AI method
npc.velocity.X = vx * toBoolInt(px - nx);
npc.velocity.Y = vy * toBoolInt(py - ny);
vx is the x velocity, px, is the player x pos and nx is the npc x pos. The rest can be inferred. Also, toBoolInt is a method which returns -1 or 1 based on whether the input is negative or positive. For some reason, when I get far enough away from the boss (I think), it disappears. There are no drastic changes in velocity nor position so it must be despawning. Is there a reason why this is occuring?
 
Back
Top Bottom