Standalone [1.3] tModLoader - A Modding API

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 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?
 
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
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
 
Back
Top Bottom