Standalone [1.3] tModLoader - A Modding API

there is two why and the first one doesn't work so there is an other copy the file and paste it in the terraria folder and i have already the older version there
 
the error
Code:
c:\Users\Dominik\Documents\My Games\Terraria\ModLoader\Mod Sources\TheRebirthMod\TheRebirthMod.cs(8,26) : error CS0115: 'TheRebirthMod.TheRebirthMod
the code
Code:
using System;
using Terraria;
using Terraria.ModLoader;

namespace TheRebirthMod {
public class TheRebirthMod : Mod
{
    public override void SetModInfo(out string name, ref ModProperties properties)
    {
        name = "TheRebirthMod";
        properties.Autoload = true;
    }
}}
 
I've met with a horrible bug (maybe for me it's horrible) with my throwing knife's durability system in multiplayer... I dunno whether it is a exclusive bug for the multiplayer or whether it is fixable for now.
First I'd give a brief description of my throwing knife's durability system.
Every throwing knife is supposed to have 3 "items/parts":
Code:
    public class IchorKnife : ModItem
    {
        public int durability = 1000;

        public override void SetDefaults()
        {
            item.name = "Ichor Knife";
            item.toolTip = "Decreases target's defense";
            item.autoReuse = true;
            item.useStyle = 1;
            item.shootSpeed = 12f;
            item.damage = 29;
            item.width = 18;
            item.height = 20;
            item.useSound = 39;
            item.useAnimation = 16;
            item.useTime = 16;
            item.noUseGraphic = true;
            item.noMelee = true;
            item.value = Item.sellPrice(0, 20, 0, 0);
            item.knockBack = 2.75f;
            item.melee = true;
            item.rare = 8;
            item.shoot = mod.ProjectileType("IchorKnifeProjectile");
        }

        public override void PostDrawInInventory(SpriteBatch spriteBatch, Vector2 position, Rectangle frame, Color drawColor, Color itemColor, Vector2 origin, float scale)
        {
            Main.spriteBatch.DrawString(Main.fontItemStack, durability.ToString(), new Vector2(position.X - 8f, position.Y + 11f), Color.White, 0f, default(Vector2), scale, SpriteEffects.None, 0f);
        }

        public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
        {
            durability--;
            return true;
        }

        public override bool CanUseItem(Player player)
        {
            return durability > 0;
        }

        public override void SaveCustomData(BinaryWriter writer)
        {
            writer.Write(durability);
        }

        public override void LoadCustomData(BinaryReader reader)
        {
            durability = reader.ReadInt32();
        }
Code:
    public class IchorKnifeProjectile : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.name = "Ichor Knife";
            projectile.alpha = 0;
            projectile.scale = 1f;
            projectile.width = 14;
            projectile.height = 28;
            projectile.aiStyle = 2;
            projectile.friendly = true;
            projectile.penetrate = 3;
            projectile.melee = true;
            //projectile.light = 0.2f;
            projectile.ignoreWater = true;
            //aiType = 48;
        }

        public override bool PreAI()
        {
            Lighting.AddLight((int)((projectile.position.X + (float)(projectile.width / 2)) / 16f), (int)((projectile.position.Y + (float)(projectile.height / 2)) / 16f), 1f, 1f, 0f);

            int d = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 169, 0f, 0f, 100, default(Color), 1f);
            if (Main.rand.Next(2) == 0)
            {
                Main.dust[d].noGravity = true;
                Main.dust[d].scale *= 1.5f;
            }

            projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 1.57f;

            projectile.ai[0] += 1f;
            if (projectile.ai[0] >= 35f)
            {
                projectile.velocity.Y = projectile.velocity.Y + 0.4f;
                projectile.velocity.X = projectile.velocity.X * 0.97f;
            }

            if (projectile.velocity.Y > 16f)
            {
                projectile.velocity.Y = 16f;
            }
            return false;
        }

        public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
        {
            target.AddBuff(69, 600, false);
        }

        public override bool OnTileCollide(Vector2 oldVelocity)
        {
            Main.PlaySound(0, (int)projectile.position.X, (int)projectile.position.Y, 1);
            return true;
        }
Code:
    public class IchorKnifeOnPickup : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "Ichor Knife";
            item.consumable = true;
            item.maxStack = 1000;
            item.width = 18;
            item.height = 20;
            item.rare = 8;
        }

        public override bool OnPickup(Player player)
        {
            for (int i = 0; i < 51; i++)
            {
                Item item2 = player.inventory[i];
                if (item2.stack > 0 && item2.type > 0 && item2.type == mod.ItemType("IchorKnife"))
                {
                    if (((IchorKnife)item2.modItem).durability <= 999)
                    {
                        Main.PlaySound(7, (int)player.position.X, (int)player.position.Y, 0);
                        ItemText.NewText(item, item.stack, false, false);
                        ((IchorKnife)item2.modItem).durability += item.stack;
                        break;
                    }
                }
                if (i == 50)
                {
                    int a = Item.NewItem((int)player.position.X, (int)player.position.Y, player.width, player.height, mod.ItemType("IchorKnifeOnPickup"), item.stack, false, 0, false, false);
                    Main.item[a].noGrabDelay = 60;
                }
            }
            return false;
        }
  • Every throwing knife will be crafted with a maximum durability 1000.
  • The durability will be reduced upon using. (conduct by shoot hook)
  • The throwing knife will act like the vanilla throwing weapons. It has its 50% chance to drop the ammo when killed.
  • In this case, it won't drop the weapon itself, which is "IchorKnife". It will drop the exclusive item "IchorKnifeOnPickup" instead.
  • When the "IchorKnifeOnPickup" was picked up by a player,
  • if the player has the apt throwing knife and the durability was not full, he will pick it up, and increase the durability of the particular throwing knife, but the item won't appear in his inventory (the OnPickup hook returns false);
  • if the player does not has the throwing knife, he will also pick it up, but meanwhile a new and totally identical item will be created on his face, which makes it look like that he cannot pick up the item (I swear, this is the best case I can think out after several days' rocking my head).
However, this made-look-like-cannot-pickup function went dead when it comes to multiplayer. The player will pick up the "IchorKnifeOnPickup" regardless of their having the apt throwing knife facts. If a player possesses the throwing knife, yeah, the durability will get increased damn nice. But every player without the knife will swallow the "IchorKnifeOnPickup" as if they love to eat it...
This is the first time that I ever found that something worked like a charm in single player will end up screwing up in the multiplayer. This is frustrating and I have totally totally no idea about what's going on, and I need help!!!

EDIT: @jopojelly I duuno whether you're online but your profit pic is green. If you see this, well, please give a quick look. Thx:)
 
Last edited:
the error
Code:
c:\Users\Dominik\Documents\My Games\Terraria\ModLoader\Mod Sources\TheRebirthMod\TheRebirthMod.cs(8,26) : error CS0115: 'TheRebirthMod.TheRebirthMod
the code
Code:
using System;
using Terraria;
using Terraria.ModLoader;

namespace TheRebirthMod {
public class TheRebirthMod : Mod
{
    public override void SetModInfo(out string name, ref ModProperties properties)
    {
        name = "TheRebirthMod";
        properties.Autoload = true;
    }
}}

namespace TheRebirthMod
{
public class TheRebirthMod: Mod
{
public TheRebirthMod()
{
Properties = new ModProperties()
{
Autoload = true,
AutoloadGores = true,
AutoloadSounds = true
};
}
}
}

try this
 
When I try to build my mod I get this:


c:\Users\Bryson\Documents\My Games\Terraria\ModLoader\Mod Sources\Randomness\Randomness\Randomness.cs(12,30) : error CS0115: 'Randomness.Randomness.SetModInfo(out string, ref Terraria.ModLoader.ModProperties)': no suitable method found to override
 
When you build a mod how do you test it, where does the build go?
When you build, it should show up in the Mods menu. I'm not sure if it is automatically enabled, so enable it and reload, then go in game and see if your recipes worked.
[doublepost=1462244616,1462244550][/doublepost]
ERROR: can open up the 'Mod Browser", but can't search or something other.
Please fix!
[P.S.: I'm on mac]
There are issues with Mac/Linux and the mod browser. Download mods from the threads here.
 
Is anyone having the same problem as me? I've loaded built and reloaded my mod and this is what I'm getting:
upload_2016-5-3_14-30-27.png

I've already tried the example mod bluemagic has and it's the same thing, and yes I've built and reloaded my mod i've checked the codes but there aren't any problems so, help anyone?
 
Can you please make tmodloader as easy to mod as tAPI? i just don't understand how to mod using .cs files
Well, from my understanding, everything you could do with json you can just do in the SetDefaults method:

For example, the .json:
Code:
{
    "code": "MissileLauncher",
    "displayName": "Missile Launcher",
    "tooltip": ["Fires Missiles"],
    "size": [24,16],
    "scale": 0.8,
    "maxStack": 1,
    "value": [0,2,0,0],
    "useStyle": 5,
    "useAnimation": 8,
    "useTime": 8,
    "damage": 20,
    "rare": 1,
    "noUseGraphic": true,
    "knockback": 5.5,
    "autoReuse": false,
    "useSound": "MetroidMod:MissileShot",
    "shoot": "MetroidMod:MissileProj",
    "shootSpeed": 15,
    "noMelee": true,
    "ranged": true,

    "recipes":
    [{
        "items": { "Meteorite Bar": 10, "Musket": 1, "Grenade": 3 },
        "tiles": [ "Anvil" ],
        "creates": 1   
    },
    {
        "items": { "Meteorite Bar": 10, "The Undertaker": 1, "Grenade": 3 },
        "tiles": [ "Anvil" ],
        "creates": 1   
    }]
}

turns into this .cs file:
Code:
using Terraria.ID;
using Terraria.ModLoader;
namespace ExampleMod.Items
{
    public class MissileLauncher : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "Missile Launcher";
            item.toolTip = "Fires Missiles";
            item.width = 24;
            item.height = 16;
            item.scale = 0.8f;
            item.maxStack = 1;
            item.value = 200000;
            item.useStyle = 5;
            item.useAnimation = 8;
            item.useTime = 8;
            item.damage = 20;
            item.rare = 1;
            item.noUseGraphic = true;
            item.knockBack = 5.5f;
            item.autoReuse = true;
            item.useSound = mod.GetSoundSlot(SoundType.Item, "MissileShot");
            item.shoot = mod.ProjectileType("MissileProj");
            item.shootSpeed = 15;
            item.noMelee = true;
            item.ranged = true;
        }
        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.MeteoriteBar, 10);
            recipe.AddIngredient(ItemID.Musket, 1);
            recipe.AddIngredient(ItemID.Grenade, 3);
            recipe.AddTile(TileID.Anvils);
            recipe.SetResult(this, 1);
            recipe.AddRecipe();
           
            recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.MeteoriteBar, 10);
            recipe.AddIngredient(ItemID.TheUndertaker, 1);
            recipe.AddIngredient(ItemID.Grenade, 3);
            recipe.AddTile(TileID.Anvils);
            recipe.SetResult(this, 1);
            recipe.AddRecipe();
        }
    }
}

As you can see, they are practically the same, and very easy to automate or convert. Also, even in tAPI, you'd have to make a .cs file to go with it to make it do anything worthwhile or interesting anyway. I think a long term plan might be .json files, but they really don't get the modder any gains, especially with how easy it would be to make a spelling mistake without Visual Studio there to identify and fix it for you.
 
Back
Top Bottom