tAPI [Discontinued] tAPI - A Mod To Make Mods

Status
Not open for further replies.
Hi,
How would i make a vanilla tile drop a custom item and how would i make a spear. I have looked around on the interent for tutorials but i found nothing. I also looked at other's mods all i found was a spear code that only works in one direction. Please Help.

Thanks.
EDIT: Since I don't know what language this code is used, I have no idea how to implement a crafting recipe. (I've tried .cs/.json and obviously none of those worked.)
Not sure if anyone answered this for you but i believe its C# and i believe it should go into the OnLoad method in the base C# file.

EDIT: For example i believe your MBase.cs should look like this:

Code:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using TAPI;

namespace TUnleashed  //The Name on you mod.
{
    public class MBase : TAPI.ModBase //MBase can be any name
    {
        public override void OnLoad() {
       
        Recipe r = new Recipe();
        r.createItem.SetDefaults("<item name>");
        r.createItem.stack = <output stack>;

        r.requiredItem.Add(new Item());
        r.requiredItem[0].SetDefaults("<item name>");
        r.requiredItem[0].stack = <required stack>;

        r.requiredItem.Add(new Item());
        r.requiredItem[1].SetDefaults("<item name>");
        r.requiredItem[1].stack = <required stack>;
        // etc

        r.AddToGame();
        }
        public override void OnUnload() { }
        public override void OnAllModsLoaded()
        {
        }

    }
}

If you need more help just ask.
 
Last edited:
Hi,
How would i make a vanilla tile drop a custom item and how would i make a spear. I have looked around on the interent for tutorials but i found nothing. I also looked at other's mods all i found was a spear code that only works in one direction. Please Help.
...
Answering to first question - no, you can't. Item types for vanilla tiles are hardcoded and current version of tAPI doesn't provide hook to override them.
 
not sure if this is already mentioned but sometimes guide voodoo dolls have prefixes, most the prefixes make the voodoo doll blue rarity or higher, rendering it useless for WoF summoning.
Does this happen with mods that add prefixes? I've thrown several vodoo dolls with high quality and it has never failed on me, but I have only vanilla prefixes.
 
Hi,
How would i make a vanilla tile drop a custom item and how would i make a spear. I have looked around on the interent for tutorials but i found nothing. I also looked at other's mods all i found was a spear code that only works in one direction. Please Help.
Do you want to REPLACE the item drop, or just add a drop? Adding one is easy, replacing not so much. There's a few ways to add a drop. One is to make a global ModTileType, and in the Kill hook, drop your item.

As for a spear, look in the template mod? There's a perfectly good one there. Remember spears need a projectile to work.

no no no, when the voodoo demons drop the dolls they come with prefixes. I have to use shockah's cheat thing to remove the prefix.
This is fixed for the next version of tAPI, so that Voodoo Dolls and Music Boxes cant get prefixes (just like in vanilla)

Does this happen with mods that add prefixes? I've thrown several vodoo dolls with high quality and it has never failed on me, but I have only vanilla prefixes.
The issue was/is that items with higher rarity don't burn in lava, making it impossible to use that doll to summon the WoF.
 
Do you want to REPLACE the item drop, or just add a drop? Adding one is easy, replacing not so much. There's a few ways to add a drop. One is to make a global ModTileType, and in the Kill hook, drop your item.

As for a spear, look in the template mod? There's a perfectly good one there. Remember spears need a projectile to work.


This is fixed for the next version of tAPI, so that Voodoo Dolls and Music Boxes cant get prefixes (just like in vanilla)


The issue was/is that items with higher rarity don't burn in lava, making it impossible to use that doll to summon the WoF.
Thank you. The Template mod version i had didnt have a spear in it and yes i do want to add a drop.

EDIT: can you give me an example of how i would get what tile the player broke?
 
Last edited:
Thank you. The Template mod version i had didnt have a spear in it and yes i do want to add a drop.

EDIT: can you give me an example of how i would get what tile the player broke?

Fixed this in a post below - ignore the spoiler labeled IGNORE...

Code:
Main.NewText("What are you doing, why would you even click that? Clearly I said to ignore it... I bet if I put another spoiler that said "Click if you are dumb" you'd probably open that one too huh?");
You just had to click it...
... I lied.
 
Last edited:
Thank you. The Template mod version i had didnt have a spear in it and yes i do want to add a drop.

EDIT: can you give me an example of how i would get what tile the player broke?
Code:
Put this in ModTileType.cs

public override void PostKill(int x, int y, bool fail, bool effectsOnly, bool noItem)
{
    //this will doStuff() if the tile is dirt
    if(!noItem && Main.tile[x, y].type == 2) doStuff();
}
To add to that, you should probably also have "!noItem" in the if as well, since the whole point of noItem is to prevent item drops :dryadtongue: Also, Ark made a typo, that should be == not = :dryadtongue: I fixed it in my quote.
 
To add to that, you should probably also have "!noItem" in the if as well, since the whole point of noItem is to prevent item drops :dryadtongue: Also, Ark made a typo, that should be == not = :dryadtongue: I fixed it in my quote.

ModTileType.cs
Code:
public override void PostKill(int x, int y, bool fail, bool effectsOnly, bool noItem)
{
    //this will make a new item if the tile is dirt
    if(!noItem && Main.tile[x, y].type == 2)
    {
        Item.NewItem(x, y, 1, 1, ItemDef.byName["YourMod:YourItem"].type, 1, false, 0);
    }
}

Even more changes lol
 
Last edited:
Code:
public override void PostKill(int x, int y, bool fail, bool effectsOnly, bool noItem)
{
    //this will make a new item if the tile is dirt
    if(!noItem && Main.tile[x, y].type == 2)
    {
        Item.NewItem(x, x, 1, 1, ItemDef.byName["YourMod:YourItem"].type, 1, false, 0);
    }
}

Even more changes lol

Thank you. But i tried using the code for the spear thats in the example mod and it works but it doesnt display it?
 
Show me the .cs file (in a code block & spoiler please - since the file is likely long)
Code:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using TAPI;
using Terraria;

namespace TUnleashed.Projectiles
{
    public class BurningPitchfork : ModProjectile
    {

        public override void AI()
        {
            Player plr = Main.player[projectile.owner];
            AISpear(projectile, ref projectile.ai, plr.Center, plr.direction, plr.itemAnimation, plr.itemAnimationMax, 3f, 6f, 6.8f, false);
            if (projectile.direction == 1) { projectile.rotation -= (float)(Math.PI / 2f); }
        }

        public override bool PreDraw(SpriteBatch sb)
        {
            DrawProjectileSpear(sb, Main.projectileTexture[projectile.type], projectile, null, 0f, 0f);
            return false;
        }

        public static void AISpear(Projectile p, ref float[] ai, Vector2 center, int ownerDirection, int itemAnimation, int itemAnimationMax, float initialSpeed = 3f, float moveOutward = 1.4f, float moveInward = 1.6f, bool overrideKill = false)
        {
            p.direction = ownerDirection;
            p.Center = center;
            if (ai[0] == 0f) { ai[0] = initialSpeed; p.netUpdate = true; }
            if (itemAnimation < itemAnimationMax * 0.33f) { ai[0] -= moveInward; } else { ai[0] += moveOutward; }
            p.position += p.velocity * ai[0];
            if (!overrideKill && Main.player[p.owner].itemAnimation == 0) { p.Kill(); }
            p.rotation = p.velocity.ToRotation() + 2.355f;
            if (p.spriteDirection == -1) { p.rotation -= 1.57f; }
        }

        //draws the spear properly
        public static void DrawProjectileSpear(SpriteBatch sb, Texture2D texture, Projectile p, Color? overrideColor = null, float offsetX = 0f, float offsetY = 0f)
        {
            offsetX += (-texture.Width * 0.5f);
            Vector2 playerCenter = Main.player[p.owner].Center;
            Color lightColor = overrideColor != null ? (Color)overrideColor : p.GetAlpha(Lighting.GetColor((int)(playerCenter.X / 16f), (int)(playerCenter.Y / 16f)));
            Vector2 origin = new Vector2((float)texture.Width * 0.5f, (float)texture.Height * 0.5f);
            Vector2 offset = RotateVector(p.Center, p.Center + new Vector2(p.direction == -1 ? offsetX : offsetY, p.direction == 1 ? offsetX : offsetY), p.rotation - 2.355f) - p.Center;
            sb.Draw(texture, p.Center - Main.screenPosition + offset, new Rectangle(0, 0, texture.Width, texture.Height), lightColor, p.rotation, origin, p.scale, p.direction == -1 ? SpriteEffects.FlipHorizontally : SpriteEffects.None, 0f);
        }

        //rotates a vector around another vector by the rotation amount.
        public static Vector2 RotateVector(Vector2 origin, Vector2 vecToRot, float rot)
        {
            float newPosX = (float)(Math.Cos(rot) * (vecToRot.X - origin.X) - Math.Sin(rot) * (vecToRot.Y - origin.Y) + origin.X);
            float newPosY = (float)(Math.Sin(rot) * (vecToRot.X - origin.X) + Math.Cos(rot) * (vecToRot.Y - origin.Y) + origin.Y);
            return new Vector2(newPosX, newPosY);
        }
    }
}
 
public override bool ConsumeAmmo(Player p) { return true; } //called when ammo is about to be consumed. (on gun and ammo)

return true; to consume ammo

I assume you know where to put this?
I know where to put it, but let's say I want the "chance to not consume ammo" as 60%, what would that code look like?
 
Status
Not open for further replies.
Back
Top Bottom