Standalone [1.3] tModLoader - A Modding API

So with tile properties, are there some common mistakes I would be making if I were trying to make ore bars placeable on top of each other? For example, in vanilla, you can place silver bars on the ground, then copper bars on top of those. But I've messed up somehow and made my modded bars only placeable on the top of vanilla bars. Anyone know a fix?

Code:
namespace ThoriumMod.Tiles
{
    public class ThoriumBar : ModTile
    {
        public override void SetDefaults()
        {
            Main.tileSolidTop[Type] = true;
            Main.tileFrameImportant[Type] = true;
            Main.tileNoAttach[Type] = false;
            Main.tileLavaDeath[Type] = true;
            TileObjectData.newTile.CopyFrom(TileObjectData.Style1x1);
            TileObjectData.newTile.Origin = new Point16(0, 0);
            TileObjectData.newTile.DrawYOffset = +2;
            TileObjectData.newTile.CoordinateHeights = new int[]{ 16 };
            TileObjectData.addTile(Type);
            drop = mod.ItemType("ThoriumBar");
            AddMapEntry(new Color(80, 200, 200), "Thorium Bar");
            dustType = 15;
            disableSmartCursor = true;
            adjTiles = new int[]{ TileID.Bottles };
        }
      
        public override void NumDust(int i, int j, bool fail, ref int num)
        {
            num = fail ? 15 : 3;
        }
    }
}
 
I try and run this, but it just cant find terraria.exe

Solution?

(I dunno if there's another post like mine, theres just 457 pages)
 
So with tile properties, are there some common mistakes I would be making if I were trying to make ore bars placeable on top of each other? For example, in vanilla, you can place silver bars on the ground, then copper bars on top of those. But I've messed up somehow and made my modded bars only placeable on the top of vanilla bars. Anyone know a fix?

Code:
namespace ThoriumMod.Tiles
{
    public class ThoriumBar : ModTile
    {
        public override void SetDefaults()
        {
            Main.tileSolidTop[Type] = true;
            Main.tileFrameImportant[Type] = true;
            Main.tileNoAttach[Type] = false;
            Main.tileLavaDeath[Type] = true;
            TileObjectData.newTile.CopyFrom(TileObjectData.Style1x1);
            TileObjectData.newTile.Origin = new Point16(0, 0);
            TileObjectData.newTile.DrawYOffset = +2;
            TileObjectData.newTile.CoordinateHeights = new int[]{ 16 };
            TileObjectData.addTile(Type);
            drop = mod.ItemType("ThoriumBar");
            AddMapEntry(new Color(80, 200, 200), "Thorium Bar");
            dustType = 15;
            disableSmartCursor = true;
            adjTiles = new int[]{ TileID.Bottles };
        }
     
        public override void NumDust(int i, int j, bool fail, ref int num)
        {
            num = fail ? 15 : 3;
        }
    }
}
The vanilla bars have: Main.tileSolid[239] = true;, so try that.
[doublepost=1461556346,1461556314][/doublepost]
I placed the files into my steam terraria, fresh install.
Then you just manually installed, no need to run the installer
[doublepost=1461556461][/doublepost]
How to deny an item's being picked up under certain conditions?
You can return false to stop the vanilla pickup in onPickup, but I'm not sure if there is any way to not make it gravitate towards the player, if that is what you are asking.
[doublepost=1461556532][/doublepost]
I need help, every time i cast my Guardian Sphere spell tome it always shoots the projectile towards the bottom right corner of my screen no matter which was i'm facing. Help would be much appreciated, thank you in advance.


Code:
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace RCT.Projectiles
{
    public class GuardianSphereProj : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.name = "Guardian Sphere Projectile";
            projectile.width = 20;
            projectile.height = 20;
            projectile.aiStyle = 47;
            projectile.ranged = true;
            projectile.penetrate = 2;
            projectile.timeLeft = 1800;
            projectile.ignoreWater = true;
            projectile.friendly = true;
            projectile.hostile = false;
            projectile.tileCollide = false;
          
        }
        public override void AI()
        {
            projectile.rotation += (float)projectile.direction * 0.8f;
            projectile.velocity.X = 0.5f;
            projectile.velocity.Y = 0.5f;
          
            projectile.light = 1;
            Player owner = Main.player[projectile.owner];
            if (projectile.position.X < owner.position.X + owner.width && projectile.position.X + projectile.width > owner.position.X && projectile.position.Y < owner.position.Y + owner.height && projectile.position.Y + projectile.height > owner.position.Y) // Need to fix (make it so if within a certain radius)
            {
          
                    owner.AddBuff(2, 1800);

            }
        }
    }
}
Your code sets velocity x and y to positive .5, so it will move in that direction. maybe you might want to rotate the velocity by rotation?
 
You can return false to stop the vanilla pickup in onPickup, but I'm not sure if there is any way to not make it gravitate towards the player, if that is what you are asking.
EM... ambiguous again, sorry.
OnPickup is not suitable for my aim. Making OnPickup return false only stop the item appearing in the inventory, but I need to entirely ban a player from picking the item under certain circumstance. Something like... say, when a player's inventory was full, he can't even pick any items he doesn't have, right?
Since I resupply the durability of my throwing knife upon picking up the dropping items, I need to make sure that a player without relative throwing knife won't grab the dropping throwing knife accidentally. This will disappoint the player who is ready to grab his knives!
 
I have a question, I'm using the AI for the magnet sphere and i want my projectile to move at a constant slow speed. Is there a way to slow down the projectile (As of right now when the projectile is shot it starts off moving fast but then slows down to a constant speed) or is there a way to set the speed of the projectile to a constant rate? If so some example code would be extremely helpful. Thank you in advance.
 
I have a question, I'm using the AI for the magnet sphere and i want my projectile to move at a constant slow speed. Is there a way to slow down the projectile (As of right now when the projectile is shot it starts off moving fast but then slows down to a constant speed) or is there a way to set the speed of the projectile to a constant rate? If so some example code would be extremely helpful. Thank you in advance.

When you initialise the projectile through NewProjectile, the arguments you give for the velocity parameters give it a constant speed. I presume the movement speed cap is hard coded in the Magnet Sphere AI, so you either need to reduce the velocity or to rewrite it.
 
Last edited:
I just have no clue, I just DO NOT HAVE
TQqA3JD.gif

Why the hell the player changes direction, I did not even add any line with "direction"
I do not know what the arrays projectile.ai[0] make, I do not know how to change the flying angle, I do not know how to change gravity, I hate this feeling not knowing what to do, and it stops me from being creative :mad:
 
I just have no clue, I just DO NOT HAVE
TQqA3JD.gif

Why the hell the player changes direction, I did not even add any line with "direction"
I do not know what the arrays projectile.ai[0] make, I do not know how to change the flying angle, I do not know how to change gravity, I hate this feeling not knowing what to do, and it stops me from being creative :mad:
Could you show your item code (probably once more)? :)
 
@jopojelly : I have a question/request, do you have a more "optimized" homing code ? I am currently using your vampire scourge homing code but is there a way to optimize it ? I want it to be able to go faster but still sharply turn in midair, kinda like chloro bullets ^^
 
Could you show your item code (probably once more)? :)
It is a little bit messed up
Code:
using Terraria.ModLoader;
using Terraria.ID;
using Microsoft.Xna.Framework.Graphics;


namespace Terranova.Projectiles
{
    public class prjMokbiShuriken : ModProjectile
    {
        private Player player = new Player();

        private int timeLeftIndicator;
      

        public override void SetDefaults()
        {
            projectile.name = "mokbiShuriken";
            projectile.width = 22;
            projectile.height = 22;
            projectile.friendly = true;
            projectile.magic = false;
            projectile.penetrate = 2;
            projectile.extraUpdates = 1;
            projectile.hide = false;
          
           // projectile.aiStyle = ProjectileID.Shuriken;
          
            timeLeftIndicator = 1000;
            player = Main.player[projectile.owner];
        }
        public override bool PreAI()
        {
            if (projectile.timeLeft > timeLeftIndicator)
                projectile.timeLeft = timeLeftIndicator;
            return true;
        }
        public override void AI()
        {
            projectile.rotation += 1;
            projectile.velocity.Y = projectile.ai[0];
            projectile.velocity.X = 2.5f;

        }
        public override bool OnTileCollide(Vector2 oldVelocity)
        {
            projectile.penetrate--;
            if (projectile.penetrate <= 0)
            {
                projectile.Kill();
            }
          
              
                Main.PlaySound(3, (int)projectile.position.X, (int)projectile.position.Y, 4);


                return false;
          
        }
        public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
        {
            if(projectile.penetrate == 0)
            {
                projectile.Kill();
            }
            else
            {
                projectile.penetrate--;
                projectile.ai[1] += 0.1f;
                projectile.velocity *= 0.75f;
            }       
            base.OnHitNPC(target, damage, knockback, crit);
        }
    }
}
 
It is a little bit messed up
Code:
using Terraria.ModLoader;
using Terraria.ID;
using Microsoft.Xna.Framework.Graphics;


namespace Terranova.Projectiles
{
    public class prjMokbiShuriken : ModProjectile
    {
        private Player player = new Player();

        private int timeLeftIndicator;
     

        public override void SetDefaults()
        {
            projectile.name = "mokbiShuriken";
            projectile.width = 22;
            projectile.height = 22;
            projectile.friendly = true;
            projectile.magic = false;
            projectile.penetrate = 2;
            projectile.extraUpdates = 1;
            projectile.hide = false;
         
           // projectile.aiStyle = ProjectileID.Shuriken;
         
            timeLeftIndicator = 1000;
            player = Main.player[projectile.owner];
        }
        public override bool PreAI()
        {
            if (projectile.timeLeft > timeLeftIndicator)
                projectile.timeLeft = timeLeftIndicator;
            return true;
        }
        public override void AI()
        {
            projectile.rotation += 1;
            projectile.velocity.Y = projectile.ai[0];
            projectile.velocity.X = 2.5f;

        }
        public override bool OnTileCollide(Vector2 oldVelocity)
        {
            projectile.penetrate--;
            if (projectile.penetrate <= 0)
            {
                projectile.Kill();
            }
         
             
                Main.PlaySound(3, (int)projectile.position.X, (int)projectile.position.Y, 4);


                return false;
         
        }
        public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
        {
            if(projectile.penetrate == 0)
            {
                projectile.Kill();
            }
            else
            {
                projectile.penetrate--;
                projectile.ai[1] += 0.1f;
                projectile.velocity *= 0.75f;
            }      
            base.OnHitNPC(target, damage, knockback, crit);
        }
    }
}
Ah, I'm not looking for your projectile code. I need your item code instead.
 
Ah, I'm not looking for your projectile code. I need your item code instead.
Code:
using Terraria.ModLoader;
using Terranova;
using Terranova.Items;

namespace Terranova.Items.Weapons
{
    class MokbiShuriken : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "Mokbi Shuriken";
            item.width = 22;
            item.height = 22;
            item.useStyle = 1;
            item.useTime = 1;
            item.useAnimation = 4;
            item.reuseDelay = 20;
            item.autoReuse = true;
            item.shootSpeed = 1.5f;
            item.shoot = mod.ProjectileType("prjMokbiShuriken");
            item.damage = 10;
            item.width = 18;
            item.height = 20;
            item.maxStack = 999;
            item.consumable = true;
            item.useSound = 1;
            item.noUseGraphic = true;
            item.noMelee = true;
            item.value = 15;
            item.thrown = true;

        }

        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.Shuriken, 1);
            recipe.AddIngredient(ItemID.StoneBlock, 1);
            recipe.AddTile(TileID.Anvils);
            recipe.SetResult(this, 1);
            recipe.AddRecipe();
        }
      

    }
}
 
Code:
using Terraria.ModLoader;
using Terranova;
using Terranova.Items;

namespace Terranova.Items.Weapons
{
    class MokbiShuriken : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "Mokbi Shuriken";
            item.width = 22;
            item.height = 22;
            item.useStyle = 1;
            item.useTime = 1;
            item.useAnimation = 4;
            item.reuseDelay = 20;
            item.autoReuse = true;
            item.shootSpeed = 1.5f;
            item.shoot = mod.ProjectileType("prjMokbiShuriken");
            item.damage = 10;
            item.width = 18;
            item.height = 20;
            item.maxStack = 999;
            item.consumable = true;
            item.useSound = 1;
            item.noUseGraphic = true;
            item.noMelee = true;
            item.value = 15;
            item.thrown = true;

        }

        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.Shuriken, 1);
            recipe.AddIngredient(ItemID.StoneBlock, 1);
            recipe.AddTile(TileID.Anvils);
            recipe.SetResult(this, 1);
            recipe.AddRecipe();
        }
     

    }
}
Allright hang on, what exactly is the problem here?
Does the player face the correctdirection but does the projectile not do the same?
 
  • Like
Reactions: Hek
Allright hang on, what exactly is the problem here?
Does the player face the correctdirection but does the projectile not do the same?
There are plenty of of problems, first of all it just changes the player direction of throwing, next comes all the direction and velocity changes. I just would like to make something like the original shuriken just adjust some things like speed, penetration and direction
 
There are plenty of of problems, first of all it just changes the player direction of throwing, next comes all the direction and velocity changes. I just would like to make something like the original shuriken just adjust some things like speed, penetration and direction
Whelp, it's not really that strange the projectile persists with a certain velocity. Below is your AI code:
Code:
public override void AI()
{
    projectile.rotation += 1;
    projectile.velocity.Y = projectile.ai[0];
    projectile.velocity.X = 2.5f;
}
In here you're hardcoding the X value of the projectiles velocity to 2.5, because of which your projectile will keep moving to the right.
 
  • Like
Reactions: Hek
Whelp, it's not really that strange the projectile persists with a certain velocity. Below is your AI code:
Code:
public override void AI()
{
    projectile.rotation += 1;
    projectile.velocity.Y = projectile.ai[0];
    projectile.velocity.X = 2.5f;
}
In here you're hardcoding the X value of the projectiles velocity to 2.5, because of which your projectile will keep moving to the right.
So how to fix it? and btw: is there any thread explaining all projectile.* types?
 
Back
Top Bottom