Standalone [1.3] tModLoader - A Modding API

Whats the easiest way to create a projetile shower, like the meteorite one?
 
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;
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
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 mean, how can I make the item that the code is in not explode.
 
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:
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)?
 
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);
        }
    }
 
globalitem recipes oncraft has the arguments recipe AND item? well that changes things. i must have tried it in moditem xD. my bad :D. i simply want to apply prefix(0) so you dont get any prefix so people cant abuse it so thx for showing me my brain fart ^^
ModItem hooks don't pass in the Item because the ModItem IS the Item.
 
ModItem hooks don't pass in the Item because the ModItem IS the Item.
deleted my post because i realized that i was wrong. i remembered that i did try that at first before other stuff but it didnt work. it would simply keep the prefix.
as i said i want to remove the prefix and after looking at the prefix list (http://terraria.wiki.gg/Prefix_IDs) i thought that prefix 0 must be no prefix. well turns out i was wrong. i just tested it with prefix(1) aka "large" which worked perfectly. but now that i know that i wasted 3 hours trying to fix the wrong problem how CAN i fix the problem? what do i set the prefix to? null doesnt work and zero and negatives simply keep the prefix

edit: the reason i thought it was working was that when i spawned the item with a newitem method and the prefix(0) it would never get a prefix but now i realize that i will never get a prefix even without the prefix(0) because that how newitem works. prefix(0) does nothing.
 
Last edited:
So I have this bow that shoots 2 arrows at once and it's all working good except the fact that one of the arrows is a wooden arrow (what I'm using as ammo) and another is my own void arrow which both are supposed to be. Anyone see what's wrong ?

Code:
public override bool Shoot(Player player, ref Microsoft.Xna.Framework.Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
        {
            float spread = 3f * 0.1000f; //Replace 45 with whatever spread you want
            float baseSpeed = (float)Math.Sqrt(speedX * speedX + speedY * speedY);
            double startAngle = Math.Atan2(speedX, speedY)- spread/2;
            double deltaAngle = spread/8f;
            double offsetAngle;
            int i;
            for (i = 0; i < 1;i++ ) //Replace 2 with number of projectiles
            {
                offsetAngle = startAngle + deltaAngle * i;
                Terraria.Projectile.NewProjectile(position.X, position.Y, baseSpeed*(float)Math.Sin(offsetAngle), baseSpeed*(float)Math.Cos(offsetAngle),
mod.ProjectileType("VoidArrow")
, damage, knockBack, item.owner);
            }
            return true;
        }
 
deleted my post because i realized that i was wrong. i remembered that i did try that at first before other stuff but it didnt work. it would simply keep the prefix.
as i said i want to remove the prefix and after looking at the prefix list (http://terraria.wiki.gg/Prefix_IDs) i thought that prefix 0 must be no prefix. well turns out i was wrong. i just tested it with prefix(1) aka "large" which worked perfectly. but now that i know that i wasted 3 hours trying to fix the wrong problem how CAN i fix the problem? what do i set the prefix to? null doesnt work and zero and negatives simply keep the prefix

edit: the reason i thought it was working was that when i spawned the item with a newitem method and the prefix(0) it would never get a prefix but now i realize that i will never get a prefix even without the prefix(0) because that how newitem works. prefix(0) does nothing.
Well, you can directly modify prefix: item.prefix = 0; You might want to call setdefaults before though, since I think the effects of the old prefix would still be there if you don't.
[doublepost=1461717918,1461717764][/doublepost]
So I have this bow that shoots 2 arrows at once and it's all working good except the fact that one of the arrows is a wooden arrow (what I'm using as ammo) and another is my own void arrow which both are supposed to be. Anyone see what's wrong ?

Code:
public override bool Shoot(Player player, ref Microsoft.Xna.Framework.Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
        {
            float spread = 3f * 0.1000f; //Replace 45 with whatever spread you want
            float baseSpeed = (float)Math.Sqrt(speedX * speedX + speedY * speedY);
            double startAngle = Math.Atan2(speedX, speedY)- spread/2;
            double deltaAngle = spread/8f;
            double offsetAngle;
            int i;
            for (i = 0; i < 1;i++ ) //Replace 2 with number of projectiles
            {
                offsetAngle = startAngle + deltaAngle * i;
                Terraria.Projectile.NewProjectile(position.X, position.Y, baseSpeed*(float)Math.Sin(offsetAngle), baseSpeed*(float)Math.Cos(offsetAngle),
mod.ProjectileType("VoidArrow")
, damage, knockBack, item.owner);
            }
            return true;
        }
"for (i = 0; i < 1;i++ ) " will only loop once. Returning true will allow tmodloader to call NewProjectile itself. Return false and change "i < 1;" to either "i <= 1;" or "i < 2;", whichever makes more sense to you.
 
I probably should have announced this a couple of weeks ago, but:

I am currently on hiatus until after my school semester ends on May 13th. I've foolishly taken all the hardest classes at once this semester, and now I'm getting bogged down with final projects and final exams. Sorry for not answering as many questions lately.
 
Well, you can directly modify prefix: item.prefix = 0; You might want to call setdefaults before though, since I think the effects of the old prefix would still be there if you don't.
ok i first tried this
Code:
while (item.prefix != 0)
            {
                item.Prefix(-1);
            }
which works but then tried simply setting it to 0 like you said which also works. both seem to not keep any reforge change but both need resetting of the value and the rarity which dont get reset automatically. thanks a lot as always.

I probably should have announced this a couple of weeks ago, but:

I am currently on hiatus until after my school semester ends on May 13th. I've foolishly taken all the hardest classes at once this semester, and now I'm getting bogged down with final projects and final exams. Sorry for not answering as many questions lately.
best of luck man. i know how you feel
 
Are there any hooks that allow tiles to have input and output for wiring?
 
Help, i tried to use
public virtual bool CanExplode(int i, int j)
but it wont work. I tried to return false .
 
Help, i tried to use
public virtual bool CanExplode(int i, int j)
but it wont work. I tried to return false .
you need
to tell us
what you are doing

public override bool CanExplode(int i, int j) goes in your modtile or globaltile, whatever you are using it for

make sure those virtuals are overrides
 
If I'm not able to deny a player's picking up, I come up with a rounded way to do this.
But once again met with some problems. It's about NewItem. Item generated by this, if using player's position, will be picked instantly by the player. I noticed that there is this bool NoGrabDelay, and whatever I set it to true or false, there is no delay. The item will be picked up instantly anyways.
I dunno whether this is because it ain't working. But how to generate an item, in the way like how mobs drop items, or just grant some seconds before it can be picked up? Since NoGrabDelay ain't working, anything else can I do?
Code:
Item.NewItem((int)player.position.X, (int)player.position.Y, player.width, player.height, mod.ItemType("IchorKnifeOnPickup"), item.stack, false, 0, false, false);
 
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;
How to change the position of spawning, like, go to/spawn at mouse cursor position?
 
How to change the position of spawning, like, go to/spawn at mouse cursor position?
On your ModItem, override the shoot function, set the position vector to Main.MouseWorld and return true. Done.
 
  • Like
Reactions: Hek
On your ModItem, override the shoot function, set the position vector to Main.MouseWorld and return true. Done.
Thanks you are my savior, I have to mention you in my mod thread once more with big thanks
 
you need
to tell us
what you are doing

public override bool CanExplode(int i, int j) goes in your modtile or globaltile, whatever you are using it for

make sure those virtuals are overrides
I am trying tot make the tile inable to explode
[doublepost=1461749823,1461749799][/doublepost]
I am trying tot make the tile inable to explode
not able*
 
Back
Top Bottom