Standalone [1.3] tModLoader - A Modding API

If you want a bag to create your own items, you can get the ID of your item with mod.ItemType("InternalItemName").
A good, that worked. Thanks.

To make it so that an ingredient isn't consumed, you can override ModRecipe then use this hook:
https://github.com/bluemagic123/tMo...rtual-int-consumeitemint-type-int-numrequired
Ah yes, I should have said I know of this documentation and hook. But I don't know how to use it. Could you show a small example of 2 ingredients where one is not consumed?
 
A good, that worked. Thanks.


Ah yes, I should have said I know of this documentation and hook. But I don't know how to use it. Could you show a small example of 2 ingredients where one is not consumed?
First, you create a call that override ModRecipe. Then, when you're adding the recipe, create a new instance of your recipe class instead of ModRecipe. In your recipe's class, in that hook, add something like this:
Code:
if(type == /*ID of item you don't want to consume*/)
{
    return 0;
}
return numRequired;
 
@bluemagic123 I know this conversation is quite old but just now I wanted to start working on it again (I gave up on it when I couldn't get it working a while ago). What would I put in the onHitNPC to make it know that I killed the enemy? After that I will probably be able to figure out how to get the attack up.
Code:
public override void OnHitNPC(Player player, NPC target, int damage, float knockBack, bool crit)
        {
          
        }
 
@bluemagic123 I know this conversation is quite old but just now I wanted to start working on it again (I gave up on it when I couldn't get it working a while ago). What would I put in the onHitNPC to make it know that I killed the enemy? After that I will probably be able to figure out how to get the attack up.
Code:
public override void OnHitNPC(Player player, NPC target, int damage, float knockBack, bool crit)
        {
         
        }
You can just check to see if the NPC's life is less than or equal to 0, since that hook gets called after the NPC actually gets damaged.
 
Sorry if I'm getting annoying but I still can't find the NPC's life. Is it even under NPC. something?
First, let's look at the method signature:
public override void OnHitNPC(Player player, NPC target, int damage, float knockBack, bool crit)
The hook provides a parameter called "target" of type "NPC". This is the NPC that was hit, so try "target.life".
 
@bluemagic123 I don't know if these are bugs or not (probably are) but in game the damage is 10 less then it would be and the axe power is 5 times more.

Edit: Never mind it's actually 20% less damage.
 
Last edited:
Alright, after failing to decompile on my 4GB ram laptop, and an 8GB desktop, I was finally able to decompile on a machine with 64GB of ram. The biggest load I saw was about 18GB in use, so I bet a 16GB ram machine with a typical page file would make it through the process. This is just an FYI for anyone thinking of contributing to the mod source code.

Anyway, problem: Decompile works, but applydiff.exe "has stopped working". A bunch of them pop up at once. This was with the "setup" button. Does the setup button do "decompile" and all 3 patch commands? I tried the patch buttons themselves but the same errors happen. Also, I don't really get the "diff merged" and "patch merged" buttons. What exactly are they doing?

Here is an example from the log

"patching file 'src/merged\Terraria\WorldGen.cs'
Assertion failed: hunk, file patch-2.5.4/patch.c, line 343

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information."

I tried find replace all "\r\n" with "\n" as someone else alluded to, but it didn't work. Any idea?
 
@bluemagic123 I don't know if these are bugs or not (probably are) but in game the damage is 10 less then it would be and the axe power is 5 times more.
For the axe power, that's just a weird thing that the game does. You'll have to divide by 5 to compensate for that; all the vanilla items do that and the example hamaxe does that.
I'm not entirely sure what's happening with the damage. Are you sure there's no modifiers or debuffs or anything that would interfere with it?

Alright, after failing to decompile on my 4GB ram laptop, and an 8GB desktop, I was finally able to decompile on a machine with 64GB of ram. The biggest load I saw was about 18GB in use, so I bet a 16GB ram machine with a typical page file would make it through the process. This is just an FYI for anyone thinking of contributing to the mod source code.

Anyway, problem: Decompile works, but applydiff.exe "has stopped working". A bunch of them pop up at once. This was with the "setup" button. Does the setup button do "decompile" and all 3 patch commands? I tried the patch buttons themselves but the same errors happen. Also, I don't really get the "diff merged" and "patch merged" buttons. What exactly are they doing?

Here is an example from the log

"patching file 'src/merged\Terraria\WorldGen.cs'
Assertion failed: hunk, file patch-2.5.4/patch.c, line 343

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information."

I tried find replace all "\r\n" with "\n" as someone else alluded to, but it didn't work. Any idea?
It's pretty weird that it's using up that much memory for you, since I've been able to decompile it with 6GB.
Yes, the setup button uses all 3 patch commands (merged -> Terraria -> tModLoader). The merged buttons add some stuff so that it's possible to compile the server version of Terraria in addition to the client version.
Does the error happen with the "patch merged" button? Also, just to make sure, are all the patch files still there?
 
For the axe power, that's just a weird thing that the game does. You'll have to divide by 5 to compensate for that; all the vanilla items do that and the example hamaxe does that.
I'm not entirely sure what's happening with the damage. Are you sure there's no modifiers or debuffs or anything that would interfere with it?


It's pretty weird that it's using up that much memory for you, since I've been able to decompile it with 6GB.
Yes, the setup button uses all 3 patch commands (merged -> Terraria -> tModLoader). The merged buttons add some stuff so that it's possible to compile the server version of Terraria in addition to the client version.
Does the error happen with the "patch merged" button? Also, just to make sure, are all the patch files still there?
Yeah I'm sure that there aren't any modifiers or debuffs.
 
First, you create a call that override ModRecipe. Then, when you're adding the recipe, create a new instance of your recipe class instead of ModRecipe. In your recipe's class, in that hook, add something like this...

Thanks, got it to work. Here is a code example that others can use:

Code:
public override void AddRecipes()
{
  ModRecipe recipe = new ModRecipeKeep(mod, "KeepItem");
  recipe.AddIngredient(null, "RemoveItem");
  recipe.AddIngredient(null, "KeepItem");
  recipe.AddTile(TileID.TinkerersWorkbench);
  recipe.SetResult(this);
  recipe.AddRecipe();
}

Code:
using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Terraria.ModLoader {
  public class ModRecipeKeep : ModRecipe
  {
     public string keep = "";
     public ModRecipeKeep(Mod mod, string keep) : base(mod)
     {
       this.keep = keep;
     }
     public override int ConsumeItem(int type, int numRequired)
     {
       if(type == mod.ItemType(keep))
       {
         return 0;
       }
       return numRequired;
    }
  }
}
 
Is there support added for generating a custom world using a custom algorithm (e.g. generate a desert world with lava pools spanning across the entire map)? Also, how about fading the screen to black and writing text in the center? I'm new to XNA and Terraria modding. Any help is appreciated.
 
Is there support added for generating a custom world using a custom algorithm (e.g. generate a desert world with lava pools spanning across the entire map)? Also, how about fading the screen to black and writing text in the center? I'm new to XNA and Terraria modding. Any help is appreciated.
There currently is not support for any of those. So far, there's in-depth support for recipes, items, dust, tiles, and walls, and basic support for projectiles and NPCs. The next update (which is coming soon) will have in-depth support for projectiles and NPCs. After that I will focus on players, then on worlds (then it will be possible to generate custom worlds).
 
Hi. Patched the .exe. When I've tried to launch an error poped up: The application failed to start because it's side-by-side configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail.
Can someone help?
 
Back
Top Bottom