Standalone [1.3] tModLoader - A Modding API

I have few questions
1. Is it possible to modify the items dropped from vanilla treasure bags (For example I want to make WoF Bag drop Imperial Flesh)
2. How can I spawn my summon at the cursor position (I'm using BabySlime AI) and if I can change it's texture (e.g. Honey Slime Staff will be yellow slimy)
Thanks in advance
1. Yeah, look at the RightClick function for GlobalItem.
2. You'll have to override the Shoot function of a weapon and then calculate the Mouse position using Main.mouseX and Main.mouseY. Then you can set the position parameter to the position you calculated and return true.
I want to remove all recipes from the game and no tsort out every one of them :naughty:
Well, you can reset the whole thing by doing 'Main.recipe = new Recipe[arrayLength];'. Be warned though, that this will remove ALL recipes (including those loaded from other mods).
 
Hey, does anyone know how to make an item that displays everything the way Cell Phone does?
[DOUBLEPOST=1453042477,1453042180][/DOUBLEPOST]Second question:
I made a pet and it works and everything BUT, its buff doesn't display. I tried everything, I copied a lot of code from my other working buff and it still doesn't display anything. Most of the rest is copied off of the ExamplePet.

Code:
namespace EnthusiastMod
{
    public class ModdedPlayer : ModPlayer
    {
        public bool babyPanda = false;
    }
}
Code:
namespace EnthusiastMod.Projectiles
{
    public class BabyPanda_Pet : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.CloneDefaults(ProjectileID.PetLizard);
            projectile.name = "Baby panda";
            aiType = ProjectileID.PetLizard;
            Main.projFrames[projectile.type] = 10;
            projectile.width = 48;
            projectile.height = 42;
            Main.projPet[projectile.type] = true;
            projectile.tileCollide = true;
            projectile.penetrate = -1;
            projectile.ignoreWater = false;
        }

        public override bool PreAI()
        {
            Player player = Main.player[projectile.owner];
            player.lizard = false;
            return true;
        }

        public override void AI()
        {
            if (projectile.rotation < -0.25f) projectile.rotation = -0.25f;
            if (projectile.rotation > 0.25f) projectile.rotation = 0.25f;
            Player player = Main.player[projectile.owner];
            ModdedPlayer modPlayer = (ModdedPlayer)player.GetModPlayer(mod, "ModdedPlayer");
            if (player.dead)
            {
                modPlayer.babyPanda = false;
            }
            if (modPlayer.babyPanda)
            {
                projectile.timeLeft = 2;
            }
        }
    }
}
Code:
namespace EnthusiastMod.Buffs
{
    public class BabyPanda_Buff : ModBuff
    {
        public override void SetDefaults()
        {
            Main.buffName[this.Type] = "Baby panda pet";
            Main.buffTip[this.Type] = "Baby panda is following you!";
            Main.buffNoTimeDisplay[Type] = true;
            Main.vanityPet[Type] = true;
            Main.buffNoSave[Type] = true;
        }

        public override void Update(Player player, ref int buffIndex)
        {
            player.buffTime[buffIndex] = 18000;
            ((ModdedPlayer)player.GetModPlayer(mod, "ModdedPlayer")).babyPanda = true;
            bool petProjectileNotSpawned = true;
            if (player.ownedProjectileCounts[mod.ProjectileType("babyPanda")] > 0)
            {
                petProjectileNotSpawned = false;
            }
            if (petProjectileNotSpawned && player.whoAmI == Main.myPlayer)
            {
                Projectile.NewProjectile(player.position.X + (float)(player.width / 2), player.position.Y + (float)(player.height / 2), 0f, 0f, mod.ProjectileType("babyPanda"), 0, 0f, player.whoAmI, 0f, 0f);
            }
        }
    }
}
 
Can you include example code? I'm not sure how to do it.
Here's the example mod's code for adding drops to the Duke Fishron bag:
Code:
public override void OpenVanillaBag(string context, Player player, int arg)
{
    if (context == "bossBag" && arg == ItemID.FishronBossBag)
    {
        player.QuickSpawnItem(mod.ItemType("Bubble"), Main.rand.Next(8, 13));
    }
}
 
Object reference not set to an instance of an object.
in the gameterraria.Recipe.SetupRecipes()in the gameterraria.ModLoader.ModLoader.do_Load(objectthreadContext)


Damn :(
I used it:

public override void AddRecipes()
{
Main.recipe = new Recipe[1802];
}
 
1. Yeah, look at the RightClick function for GlobalItem.
2. You'll have to override the Shoot function of a weapon and then calculate the Mouse position using Main.mouseX and Main.mouseY. Then you can set the position parameter to the position you calculated and return true.

Well, you can reset the whole thing by doing 'Main.recipe = new Recipe[arrayLength];'. Be warned though, that this will remove ALL recipes (including those loaded from other mods).
How to delete specific recipe from Terraria?
 
Object reference not set to an instance of an object.
in the gameterraria.Recipe.SetupRecipes()in the gameterraria.ModLoader.ModLoader.do_Load(objectthreadContext)


Damn :(
I used it:

public override void AddRecipes()
{
Main.recipe = new Recipe[1802];
}
Yeah, it won't be as easy as 1-2-3 I'm afraid. My advice is for you to go looking through Terraria's source to see how recipes are handled and how you can cancel that out.
How to delete specific recipe from Terraria?
Almost same as above, see how vanilla recipes are handled in Terraria's source (look at Recipe.CS).
 
Yeah, it won't be as easy as 1-2-3 I'm afraid. My advice is for you to go looking through Terraria's source to see how recipes are handled and how you can cancel that out.

Almost same as above, see how vanilla recipes are handled in Terraria's source (look at Recipe.CS).
Recipes in this file setup in Private method, but Blumagic said about looping and i don't know what i need to do
 
Recipes in this file setup in Private method, but Blumagic said about looping and i don't know what i need to do
Yup, looping. Do you know how arrays work and for loops? Main.recipe is an array of recipes, which means that it has multiple entries (0, 1, 2, etc.).
Look into arrays and for loops for c# and you'll know what to do ;)
 
Here's the example mod's code for adding drops to the Duke Fishron bag:
Code:
public override void OpenVanillaBag(string context, Player player, int arg)
{
    if (context == "bossBag" && arg == ItemID.FishronBossBag)
    {
        player.QuickSpawnItem(mod.ItemType("Bubble"), Main.rand.Next(8, 13));
    }
}

Ok, thanks a lot!
 
Does ay one know how to get a custom town npc to spawn?

Here is my town npc's code:
Code:
using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace EpicnessMod.NPCs
{
    public class InfectedMan : ModNPC
    {
        public override bool Autoload(ref string name, ref string texture)
        {
            name = "Zomb";
            return mod.Properties.Autoload;
        }

        public override void SetDefaults()
        {
            npc.name = "InfectedMan";
            npc.townNPC = true;
            npc.friendly = true;
            npc.width = 18;
            npc.height = 40;
            npc.aiStyle = 7;
            npc.damage = 10;
            npc.defense = 15;
            npc.lifeMax = 250;
            npc.soundHit = 1;
            npc.soundKilled = 1;
            npc.knockBackResist = 0.5f;
            Main.npcFrameCount[npc.type] = 3;
            NPCID.Sets.ExtraFramesCount[npc.type] = 3;
            NPCID.Sets.DangerDetectRange[npc.type] = 700;
            NPCID.Sets.AttackType[npc.type] = 0;
            NPCID.Sets.AttackTime[npc.type] = 90;
            NPCID.Sets.AttackAverageChance[npc.type] = 30;
            animationType = NPCID.Zombie;
        }
        public static bool TownSpawn()
{
    return true;
}
        public override string TownNPCName()
        {
            switch (WorldGen.genRand.Next(4))
            {
                case 0:
                    return "Zomb";
                case 1:
                    return "Zombro";
                case 2:
                    return "Jason";
                default:
                    return "Zomb";
            }
        }

        public override string GetChat()
        {
            int Merchant = NPC.FindFirstNPC(NPCID.Merchant);
            if (Merchant >= 0 && Main.rand.Next(4) == 0)
            {
                return "Can you please tell " + Main.npc[Merchant].displayName + " to stop trying to sell me angel statues?";
            }
            switch (Main.rand.Next(3))
            {
                case 0:
                    return "Why does everyone think I'm a zombie?";
                case 1:
                    return "I am a npc.... not a player.. What you caught me in a deep state of mind.";
                default:
                    return "Sometimes.... AI can be harsh..";
            }
        }

        public override void SetChatButtons(ref string button, ref string button2)
        {
            button = Lang.inter[28];
        }

        public override void OnChatButtonClicked(bool firstButton, ref bool shop)
        {
            if (firstButton)
            {
                shop = true;
            }
        }

        public override void SetupShop(Chest shop, ref int nextSlot)
        {
            shop.item[nextSlot].SetDefaults(mod.ItemType("SuperWood"));
            nextSlot++;
            shop.item[nextSlot].SetDefaults(mod.ItemType("DarkMatterBar"));
            nextSlot++;
            if (Main.bloodMoon == true)
            {
                shop.item[nextSlot].SetDefaults(mod.ItemType("Bloodarang"));
                nextSlot++;
            }
           
           
        }

        public override void TownNPCAttackStrength(ref int damage, ref float knockback)
        {
            damage = 35;
            knockback = 4f;
        }

        public override void TownNPCAttackCooldown(ref int cooldown, ref int randExtraCooldown)
        {
            cooldown = 30;
            randExtraCooldown = 30;
        }

        public override void TownNPCAttackProj(ref int projType, ref int attackDelay)
        {
            projType = mod.ProjectileType("Bloodarang");
            attackDelay = 1;
        }

        public override void TownNPCAttackProjSpeed(ref float multiplier, ref float gravityCorrection, ref float randomOffset)
        {
            multiplier = 12f;
            randomOffset = 2f;
        }
    }
}
 
Yup, looping. Do you know how arrays work and for loops? Main.recipe is an array of recipes, which means that it has multiple entries (0, 1, 2, etc.).
Look into arrays and for loops for c# and you'll know what to do ;)
Well, i've found recipe. How to reset it?
 
Set it to 'new Recipe()' or modify it's values (ingredients/tiles) directly.
for (int i = 0; i < Recipe.maxRecipes; i++)
{
if (i == 3509)
{
Main.recipe = new Recipe{i}; // {} = square brackets
recipe.AddIngredient(ItemID.CursedFlame, 99);
recipe.AddRecipe();
}
}
It's doesn't change recipe, why?
 
Does ay one know how to get a custom town npc to spawn?

Here is my town npc's code:
Code:
using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace EpicnessMod.NPCs
{
    public class InfectedMan : ModNPC
    {
        public override bool Autoload(ref string name, ref string texture)
        {
            name = "Zomb";
            return mod.Properties.Autoload;
        }

        public override void SetDefaults()
        {
            npc.name = "InfectedMan";
            npc.townNPC = true;
            npc.friendly = true;
            npc.width = 18;
            npc.height = 40;
            npc.aiStyle = 7;
            npc.damage = 10;
            npc.defense = 15;
            npc.lifeMax = 250;
            npc.soundHit = 1;
            npc.soundKilled = 1;
            npc.knockBackResist = 0.5f;
            Main.npcFrameCount[npc.type] = 3;
            NPCID.Sets.ExtraFramesCount[npc.type] = 3;
            NPCID.Sets.DangerDetectRange[npc.type] = 700;
            NPCID.Sets.AttackType[npc.type] = 0;
            NPCID.Sets.AttackTime[npc.type] = 90;
            NPCID.Sets.AttackAverageChance[npc.type] = 30;
            animationType = NPCID.Zombie;
        }
        public static bool TownSpawn()
{
    return true;
}
        public override string TownNPCName()
        {
            switch (WorldGen.genRand.Next(4))
            {
                case 0:
                    return "Zomb";
                case 1:
                    return "Zombro";
                case 2:
                    return "Jason";
                default:
                    return "Zomb";
            }
        }

        public override string GetChat()
        {
            int Merchant = NPC.FindFirstNPC(NPCID.Merchant);
            if (Merchant >= 0 && Main.rand.Next(4) == 0)
            {
                return "Can you please tell " + Main.npc[Merchant].displayName + " to stop trying to sell me angel statues?";
            }
            switch (Main.rand.Next(3))
            {
                case 0:
                    return "Why does everyone think I'm a zombie?";
                case 1:
                    return "I am a npc.... not a player.. What you caught me in a deep state of mind.";
                default:
                    return "Sometimes.... AI can be harsh..";
            }
        }

        public override void SetChatButtons(ref string button, ref string button2)
        {
            button = Lang.inter[28];
        }

        public override void OnChatButtonClicked(bool firstButton, ref bool shop)
        {
            if (firstButton)
            {
                shop = true;
            }
        }

        public override void SetupShop(Chest shop, ref int nextSlot)
        {
            shop.item[nextSlot].SetDefaults(mod.ItemType("SuperWood"));
            nextSlot++;
            shop.item[nextSlot].SetDefaults(mod.ItemType("DarkMatterBar"));
            nextSlot++;
            if (Main.bloodMoon == true)
            {
                shop.item[nextSlot].SetDefaults(mod.ItemType("Bloodarang"));
                nextSlot++;
            }
         
         
        }

        public override void TownNPCAttackStrength(ref int damage, ref float knockback)
        {
            damage = 35;
            knockback = 4f;
        }

        public override void TownNPCAttackCooldown(ref int cooldown, ref int randExtraCooldown)
        {
            cooldown = 30;
            randExtraCooldown = 30;
        }

        public override void TownNPCAttackProj(ref int projType, ref int attackDelay)
        {
            projType = mod.ProjectileType("Bloodarang");
            attackDelay = 1;
        }

        public override void TownNPCAttackProjSpeed(ref float multiplier, ref float gravityCorrection, ref float randomOffset)
        {
            multiplier = 12f;
            randomOffset = 2f;
        }
    }
}

I think you're missing these (?)
Code:
public override bool CanTownNPCSpawn(int numTownNPCs, int money)
        {
            return true;
        }

        public override bool CheckConditions(int left, int right, int top, int bottom)
        {
            return true;
        }
 
Somehow, the damage blocking effect I wrote for my mod's light/dark world system is causing enemy casters to attack each other and take damage every time they shoot a projectile, and I have no idea how the code's causing it.
This is the damage blocking code:
Code:
        public override bool? CanHitNPC(Item item, NPC target)
        {
            if(!target.friendly)
            {
                return (zoneDarkness == TerrariaReforged.IsDarkMob(target)) || TerrariaReforged.IsDualWorldMob(target);
            }
            else
            {
            return null;
            }
        }
        public override bool? CanHitNPCWithProj(Projectile proj, NPC target)
        {
            if(!target.friendly)
            {
                return (zoneDarkness == TerrariaReforged.IsDarkMob(target)) || TerrariaReforged.IsDualWorldMob(target);
            }
            else
            {
            return null;
            }
        }
        public override bool CanBeHitByNPC(NPC npc, ref int cooldownSlot)
        {
            return (zoneDarkness == TerrariaReforged.IsDarkMob(npc)) || TerrariaReforged.IsDualWorldMob(npc);
        }
        public override bool CanBeHitByProjectile(Projectile proj)
        {
            return !zoneDarkness;
        }
 
@bluemagic123 I've found another issue with performance. Any modded armor or armor vanity piece reduces framerate when worn. For example: I'm using Tremor Remastered and when I put on full set of Living Wood armor the framerate drops. Vanilla items aren't affected. I don't know whether it's the mod loader or the mod itself, so I'm only guessing.
 
for (int i = 0; i < Recipe.maxRecipes; i++)
{
if (i == 3509)
{
Main.recipe = new Recipe{i}; // {} = square brackets
recipe.AddIngredient(ItemID.CursedFlame, 99);
recipe.AddRecipe();
}
}
It's doesn't change recipe, why?
First of all, why are you looping through all recipes if you know which index you want?
Second, why are you resetting the WHOLE Main.recipe array?
Then which recipe are you trying to access? You'll probably want to modify the recipe at the given index, right?
All things together, this ain't gonna work. I'm currently not behind my own PC, so I can't look at the source of Terraria, but you'll probably want to start with the following: get the recipe via 'Main.recipe[3509]'. Then modify the ingredients and tiles needed for the recipe (look into the source to see how to do that). The ingredients and tiles needed are both being kept in an array, so you're probably looking for two integer arrays.
 
hey! I love the mod launcher you've created to help us experience terraria as it was meant to be played: with a million mods installed at once :p...that being said..there's 1 thing you still need to add......if you don't add in minion support within the next 2 years..preferably sooner..you're gonna have a Bad Time~


sans_512.jpg
 
hey! I love the mod launcher you've created to help us experience terraria as it was meant to be played: with a million mods installed at once :p...that being said..there's 1 thing you still need to add......if you don't add in minion support within the next 2 years..preferably sooner..you're gonna have a Bad Time~


sans_512.jpg
Correct me if I'm wrong, but minions have been added in the 0.7 update...
 
Back
Top Bottom