Standalone [1.3] tModLoader - A Modding API

Rejoice, next update you'll be able to unpublish mods you mistakenly publish.
nMBNez9.png
That went quick, very nice feature!
 
I've just gotten interested in modding (though I have a few years of C# under my belt) and I have some basic questions if people don't mind helping me out.

If I wanted to adjust the properties of say, lava (e.g. decrease damage), or adjust world gen (for different structures), or change which mobs target the player, are hooks that could support those kinds of modifications currently in tModLoader? I was just unclear if tile/world gen 'support' was included or is what was meant by the text outlining v0.7.1 and v0.7.2.

Thanks!
 
-Add PreItemCheck and PostItemCheck hooks for ModPlayer
-Add GetWeaponDamage and GetWeaponKnockback hooks for ModPlayer
-Add projOnSwing field for ModItem
-Add ConsumeAmmo, Shoot, and MeleeEffects hooks for ModPlayer
-Add OnHitAnything hook for ModPlayer
-Add CanHitNPC, ModifyHitNPC, and OnHitNPC hooks for ModPlayer - 33% Complete
-Add CanHitNPCWithProj, ModifyHitNPCWithProj, and OnHitNPCWithProj hooks for ModPlayer
-Add CanHitPvp, ModifyHitPvp, and OnHitPvp hooks for ModPlayer
-Add CanHitPvpWithProj, ModifyHitPvpWithProj, and OnHitPvpWithProj hooks for ModPlayer
-Add CanBeHitByNPC, ModifyHitByNPC, and OnHitByNPC hooks for ModPlayer - 33% Complete
-Add CanBeHitByProjectile, ModifyHitByProjectile, and OnHitByProjectile hooks for ModPlayer
-Add WalkDust, MouseOverFar, and HurtPlayer hooks for tiles
-Add hooks for grappling hooks
-Add support and hooks for PlayerLayer (custom player drawing)
-Add hooks for buffs
-Add super epic boss to ExampleMod - 10% Complete
-Add support for switching item forms
Only need those for next update im so hyped
 
I've just gotten interested in modding (though I have a few years of C# under my belt) and I have some basic questions if people don't mind helping me out.

If I wanted to adjust the properties of say, lava (e.g. decrease damage), or adjust world gen (for different structures), or change which mobs target the player, are hooks that could support those kinds of modifications currently in tModLoader? I was just unclear if tile/world gen 'support' was included or is what was meant by the text outlining v0.7.1 and v0.7.2.

Thanks!
It won't be possible to freely decrease the damage lava does until next update (although it is possible to decrease lava damage right now in a way that doesn't stack with the Obsidian Rose).

World generation stuff is planned for the update after the next one.

What exactly do you mean by changing which mobs target the player?
 
or change which mobs target the player
npc.target should help on that regard. It's a vanilla property and it accepts an int value referring to the player's id on the server.



Global question and if it has been asked before, many sorry, but granted my lack of attention paying in the past months, is there currently a cheatmenu-like mod for this API? It would help with debugging greatly.
 
npc.target should help on that regard. It's a vanilla property and it accepts an int value referring to the player's id on the server.



Global question and if it has been asked before, many sorry, but granted my lack of attention paying in the past months, is there currently a cheatmenu-like mod for this API? It would help with debugging greatly.
There's this mod, you'll have to see if this suits your tastes, though.
 
  • Like
Reactions: W1K
It won't be possible to freely decrease the damage lava does until next update (although it is possible to decrease lava damage right now in a way that doesn't stack with the Obsidian Rose).

World generation stuff is planned for the update after the next one.

What exactly do you mean by changing which mobs target the player?

I was considering making some enemies allied with the player instead of attacking them (in hindsight I suppose I should look at the Slime Crown thing that makes slimes passive).

Also, if you wanted to change the functionality of existing monsters (say, slimes) is such a thing possible? What would be the potential workflow--would you have to make a script that inherits the base slime class from default terraria, or would you have to make an entirely new 'npc' and override spawning to prevent the default slime from being spawned and instead spawn the modified version?
 
I was considering making some enemies allied with the player instead of attacking them (in hindsight I suppose I should look at the Slime Crown thing that makes slimes passive).

Also, if you wanted to change the functionality of existing monsters (say, slimes) is such a thing possible? What would be the potential workflow--would you have to make a script that inherits the base slime class from default terraria, or would you have to make an entirely new 'npc' and override spawning to prevent the default slime from being spawned and instead spawn the modified version?
You can create a class and make it derive from GlobalNPC. From there you can override the PreAI function and check if the type is correct (so you are modifying the NPC you want). You can then change around the whole functionality for that specific NPC. (hope I'm not too vague).
 
You can create a class and make it derive from GlobalNPC. From there you can override the PreAI function and check if the type is correct (so you are modifying the NPC you want). You can then change around the whole functionality for that specific NPC. (hope I'm not too vague).

Okay, thanks. I'm sure it'll be a little while before I manage to wrap my head around working with tModLoader and Terraria's source. Also, is there any way to see how the game content is coded? For example, I've got Terraria as a reference in VS, but if I wanted to see how the Slime Crown was coded, or which methods it uses, and so on--I can't seem to find where that code truly is. I've been poking around inside the 'Terraria' reference and I can see the Slime Crown in Terraria.ID.ItemID, but no class the contains its functionality.
 
Okay, thanks. I'm sure it'll be a little while before I manage to wrap my head around working with tModLoader and Terraria's source. Also, is there any way to see how the game content is coded? For example, I've got Terraria as a reference in VS, but if I wanted to see how the Slime Crown was coded, or which methods it uses, and so on--I can't seem to find where that code truly is. I've been poking around inside the 'Terraria' reference and I can see the Slime Crown in Terraria.ID.ItemID, but no class the contains its functionality.
You can take a look at a program called IlSpy. This will actually decompile the source code to a viewable version, which allows you to stroll through the source itself.
There are VERY big files though, so that's a heads up.
 
You can take a look at a program called IlSpy. This will actually decompile the source code to a viewable version, which allows you to stroll through the source itself.
There are VERY big files though, so that's a heads up.

Awesome, thanks! That helps out a lot. Not sure 100% yet if I want to pursue terraria modding, but if I do I'm sure I'll be here asking many questions. Thanks again for pointing me in the right direction.
 
Awesome, thanks! That helps out a lot. Not sure 100% yet if I want to pursue terraria modding, but if I do I'm sure I'll be here asking many questions. Thanks again for pointing me in the right direction.
I asked loads of questions myself and now that I understand the usage of tModLoader (and Terraria's source :sigh:) a bit more, I'm eager to help you find the answers to your questions. Keep 'em comming!
 
Okay, I got some wired problems once again.
I successfully made my short swords shoot something:
Code:
        public override void SetDefaults()
        {
            item.name = "Orichalcum Shortsword";
            item.damage = 50;
            item.crit = 10;
            item.melee = true;
            item.width = 32;
            item.height = 32;
            item.useTime = 12;
            item.useAnimation = 12;
            item.useStyle = 3;
            item.knockBack = 4;
            item.value = 154000;
            item.rare = 3;
            item.useSound = 1;
            item.autoReuse = true;
            item.shoot = ProjectileID.Meowmere;
        }

        public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
        {
            speedX = 30f;
            return true;
        }
But, well, whichever direction I point, it will only shoot to the left. Why is this?
 
Okay, I got some wired problems once again.
I successfully made my short swords shoot something:
Code:
        public override void SetDefaults()
        {
            item.name = "Orichalcum Shortsword";
            item.damage = 50;
            item.crit = 10;
            item.melee = true;
            item.width = 32;
            item.height = 32;
            item.useTime = 12;
            item.useAnimation = 12;
            item.useStyle = 3;
            item.knockBack = 4;
            item.value = 154000;
            item.rare = 3;
            item.useSound = 1;
            item.autoReuse = true;
            item.shoot = ProjectileID.Meowmere;
        }

        public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
        {
            speedX = 30f;
            return true;
        }
But, well, whichever direction I point, it will only shoot to the left. Why is this?
It's because you're setting the horizontal velocity (speedX) to a positive number.
 
It's because you're setting the horizontal velocity (speedX) to a positive number.
Aha, I thought it only refers to speed. Haven't thought it also contains the direction.
Then What should I set, so it has a changeable direction and a high speed at the same time?
 
Aha, I thought it only refers to speed. Haven't thought it also contains the direction.
Then What should I set, so it has a changeable direction and a high speed at the same time?
You can set 'item.shootSpeed = 10;' or something of the sorts in the SetDefaults method of your item.
 
Back
Top Bottom