• For issues you find with the Switch and Console releases, please follow this link and give as much detail as possible. This is the speediest way to get info to Pipeworks and get a hotfix in the works.
  • 1.4 will bring many changes to the PC version. We strongly advise making plans to back up your worlds and players prior to updating your game. More details here.
  • Begin your search for Journey's End information here and here. Please report bugs and issues for Journey's End here.
  • For issues you find with the Mobile 1.4 update, please follow this link and give as much detail as possible. This is the speediest way to get info to DR Studios to look at your issue. Also, some troubleshooting hints here.

Standalone [1.3] tModLoader - A Modding API

wch

Terrarian
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...
 

jokekid

Terrarian
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
 

dinidini4000

Skeletron Prime
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
 

Mine_Sasha

Terrarian
@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

Eater of Worlds
@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?
 

jopojelly

Retinazer
tModLoader
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
 

Endershot355

Steampunker
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;
 

Hek

Eye of Cthulhu


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;
 

alienmist325

Terrarian
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?
 

Eldrazi

Eater of Worlds


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;
This is because of how the projectile is drawn. If you want it to draw along its origin correctly, use the following code on your ModProjectile in the PreDraw function:
Code:
Texture2D texture = Main.projectileTexture[projectile.type];
Vector2 origin = new Vector2((float)texture.Width * 0.5f, (float)(texture.Height / Main.projFrames[projectile.type]) * 0.5f);
SpriteEffects effect = projectile.spriteDirection == -1 ? SpriteEffects.FlipHorizontally : SpriteEffects.None;
Main.spriteBatch.Draw(texture, projectile.Center - Main.screenPosition, new Rectangle?(Utils.Frame(texture, 1, Main.projFrames[projectile.type], 0, projectile.frame)), lightColor * projectile.Opacity, projectile.rotation, origin, projectile.scale, effect, 0);
return false;
 
  • Like
Reactions: Hek

wch

Terrarian
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
Don't get ya idea. But it seems a player's picking up cannot be denied. I'd have a good think through this....

BTW, I made a little wand for myself. And it kinda has a symmetrical structure. So, when used, the character would hold one end and swing, which looks super wired in this case. Is there anything I can do to make the swing point move to the middle of the weapon?
Remember several months ago, Eldrazi told me this to draw my AWP closer to the player, but it doesn't work well on the wand. Guess it's because the wand is a swing weapon...
I dunno whether I state my mind clearly. Maybe I should add some details here. I just wanna move the swing start point to the middle of weapon - means if a player is gonna grab a weapon and swing it, he no longer grabs at the bottom left corner, but the middle of the weapon...
If I'm about to be ambiguous again, sorry is what I want to express urgently in advance.
Code:
        public int dir = 1;
        public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
        {
            dir = Main.mouseX + Main.screenPosition.X > player.Center.X ? 1 : -1;
            return true;
        }

        public override void UseStyle(Player player)
        {
            int distance = -15;
            player.itemLocation.X += (float)(Math.Cos(player.itemRotation) * distance) * dir;
            player.itemLocation.Y += (float)(Math.Sin(player.itemRotation) * distance) * dir;
        }
EDIT: Oh, it suddenly hits me that quest fish cannot be picked up while you r having the item in your inventory. Any way that I can simulate this?
 
Last edited:

Goldenrevolver

Terrarian
hey i need to control the reforge modifiers of all new mod items crafted. its easy to do for item bags as i can get their id when i create the item myself with the newitem method and simply .prefix(0) them but i cant do that for recipes. my current workaround is setting the recipe result to 0 and spawning the desired item with the oncraft call which works but has 2 problems. the first one is that the icon for the recipes doesnt display anymore as i think the stack needs to be greater than 0 to do that, the text still displays fine. the second problem is that the item goes directly into the inventory and not in the players hand (nothing major).

so i need to get the players hold item to fix the prefix but i looked at like every method in the player class and couldnt find a method for it. i could find some for the selected item, the old selected, the item in the trash slot; of course all accessories and armor slots but not the players hold item slot. it would be enough if i could delete it and replace it but even that i cant do.

the only other alternative would be to make the recipe spawn a bag which i then can control the prefix off but thats not desirable for the user. so how can i get the players holding item (which would during the oncraft all be the crafted item) or how can i get the created item id (not the type)?
 

jopojelly

Retinazer
tModLoader
hey i need to control the reforge modifiers of all new mod items crafted. its easy to do for item bags as i can get their id when i create the item myself with the newitem method and simply .prefix(0) them but i cant do that for recipes. my current workaround is setting the recipe result to 0 and spawning the desired item with the oncraft call which works but has 2 problems. the first one is that the icon for the recipes doesnt display anymore as i think the stack needs to be greater than 0 to do that, the text still displays fine. the second problem is that the item goes directly into the inventory and not in the players hand (nothing major).

so i need to get the players hold item to fix the prefix but i looked at like every method in the player class and couldnt find a method for it. i could find some for the selected item, the old selected, the item in the trash slot; of course all accessories and armor slots but not the players hold item slot. it would be enough if i could delete it and replace it but even that i cant do.

the only other alternative would be to make the recipe spawn a bag which i then can control the prefix off but thats not desirable for the user. so how can i get the players holding item (which would during the oncraft all be the crafted item) or how can i get the created item id (not the type)?
Why not just set the prefix in the OnCraft hook? Also, "player.inventory[player.selectedItem]" is the selected Item instance. (Or were you talking about the mouse item? Main.mouseItem)

This works. You'll have to make sure to only try to apply the correct prefixes, otherwise it will give you a random one:
Code:
    public class A : GlobalItem
    {
        public override void OnCraft(Item item, Recipe recipe)
        {
            item.Prefix(81);
        }
    }
 
Top Bottom