tModLoader Question: Custom Pets With AI Other Than Zephyr Fish

EDIT: Figured it out. I was trying everything independently, not mixing and matching. The uppercase and lowercase versions of "ZephyrFish" were not the exact same ID. The lowercase zephyrfish refers to the Zephyr Fish in the Player.cs files, while the uppercase ZephyrFish is the projectile ID.

Google, if others search for custom pets, you better show them this!

Original post;
Howdy Terraria community, I come bearing a bit of an issue that I cannot solve in any way that is related to creating custom pets. Using every possible combination of "Pet", "TmodLoader", "Custom", "Terraria", and various other obvious search strings, Google only ever brings up outdated stuff from past TmodLoader versions, most of which don't even try to explain what they're doing besides "copy this"! Likewise, I cannot find any mods with open source that have pets for me to reference on this. ExampleMod is great, but having absolutely EVERY pet act like a Zephyr Fish is lazy and bad in the long run. Likewise, nothing is explicitly explained anywhere, leading to it being a dead end for inexperienced modders (such as myself). So, this brings up the discussion point; what in the world lets me change from ZephyrFish to other pets?

The ExamplePet.cs file is as so; (I hope it's okay to post this)
Code:
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace ExampleMod.Projectiles.Pets
{
   public class ExamplePet : ModProjectile
   {
     public override void SetStaticDefaults()
     {
       DisplayName.SetDefault("Paper Airplane");
       Main.projFrames[projectile.type] = 4;
       Main.projPet[projectile.type] = true;
     }

     public override void SetDefaults()
     {
       projectile.CloneDefaults(ProjectileID.ZephyrFish);
       aiType = ProjectileID.ZephyrFish;
     }

     public override bool PreAI()
     {
       Player player = Main.player[projectile.owner];
       player.zephyrfish = false; // Relic from aiType
       return true;
     }

     public override void AI()
     {
       Player player = Main.player[projectile.owner];
       ExamplePlayer modPlayer = player.GetModPlayer<ExamplePlayer>(mod);
       if (player.dead)
       {
         modPlayer.examplePet = false;
       }
       if (modPlayer.examplePet)
       {
         projectile.timeLeft = 2;
       }
     }
   }
}

As we see, it uses the defaults for the Zephyr Fish pet in the SetDefaults section and PreAI section. Common sense for the average Joe would dictate "Well I could just go look up the projectile ID for the pet I want to make a copy of, and replace ZephyrFish with that!", but that clearly does not work. Case in point; attempting to change ZephyrFish to "BabyHornet" causes the game to tell you that there is no ProjectileID named "BabyHornet". The same is with every other pet's Projectile ID in that you get this error;
"error CS1061: 'Terraria.Player' does not contain a definition for 'BabyHornet' and no extension method 'BabyHornet' accepting a first argument of type 'Terraria.Player' could be found (are you missing a using directive or an assembly reference?)" This causes the projectile to not load, thus preventing the mod from working. This leads to frustration, which leads to continuously doing it wrong. Since there's no tutorials out there on how to alter the examplepet.cs file, figuring out what to put in the file is a nightmare.

Let's use the Eater's Bone pet as an example here. The Eater's Bone item ID is "EatersBone" and "994", its projectile is "BabyEater" and "175", and its buff is irrelevant since buffs are easy for pets. Having a look in the code of the game with third-party tools reveals that the Projectiles.cs file has netImportant, width, height, aiStyle, friendly, penetrate, and timeLeft. Clearly we know what width and height is, and the latter three make sense as well just by reading them. Looking at aiStyle, it shares its style (26) with a huge variety of enemies, practically most of them! The netImportant string isn't one I am familiar with, though I assume that it means the pet does what some pets do when you go too far ahead and it needs to catch up. This much is easily inferred on what little we are given. However, there is no indication of its animation anywhere. The same is with the Zephyr Fish, so using assumptions based on what you would assume is common sense, you would want to replace the instances of "ZephyrFish" with "BabyEater", both of which being the projectileID for their respective items. Again, this does not work, and I do not understand why.

What would one need to do to copy a different projectile? I'm using Blushiemagic's wiki github for the list of Vanilla Projectile IDs, but no matter what pet's Projectile ID I try to use, it just causes the above error. I want to copy the details of pets other than the Zephyr Fish, not have an army of Zephyr Fish resprites.
 
Last edited:
Back
Top Bottom