Standalone [1.3] tModLoader - A Modding API

How would I make a custom ore generate in a world?
Code:
        public override void ModifyWorldGenTasks(List<GenPass> tasks, ref float totalWeight)
        {
            int ShiniesIndex = tasks.FindIndex(genpass => genpass.Name.Equals("Micro Biomes"));
            if (ShiniesIndex == -1)
            {
                // Shinies pass removed by some other mod.
                return;
            }
            tasks.Insert(ShiniesIndex + 1, new PassLegacy("Example Mod Ores", delegate (GenerationProgress progress)
            {
                progress.Message = "Example Mod Ores";

                for (int k = 0; k < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 6E-05); k++)
                {
                    WorldGen.TileRunner(WorldGen.genRand.Next(0, Main.maxTilesX), WorldGen.genRand.Next((int)WorldGen.worldSurfaceLow, Main.maxTilesY), (double)WorldGen.genRand.Next(3, 6), WorldGen.genRand.Next(2, 6), mod.TileType("ExampleBlock"), false, 0f, 0f, false, true);
                }
            }));
        }
where "mod.TileType("ExampleBlock")" is the tile, 6E-05 is a multiplier on the number of loops, and I forget all the parameters for TileRunner right now.
 
Look in NPC.cs for the setdefaults of the NPC you are interested in. You'll see the type and aistyle for that NPC. Then, look for aistyle == (number here) and you should find the ai code for that ai style. Within that block of code there may be if statements to further refine the aistyle due to the type (aka NPCid) of the NPC. You'll need to look through it and attempt to understand the code.
where would i find NPC.cs
 
Code:
        public override void ModifyWorldGenTasks(List<GenPass> tasks, ref float totalWeight)
        {
            int ShiniesIndex = tasks.FindIndex(genpass => genpass.Name.Equals("Micro Biomes"));
            if (ShiniesIndex == -1)
            {
                // Shinies pass removed by some other mod.
                return;
            }
            tasks.Insert(ShiniesIndex + 1, new PassLegacy("Example Mod Ores", delegate (GenerationProgress progress)
            {
                progress.Message = "Example Mod Ores";

                for (int k = 0; k < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 6E-05); k++)
                {
                    WorldGen.TileRunner(WorldGen.genRand.Next(0, Main.maxTilesX), WorldGen.genRand.Next((int)WorldGen.worldSurfaceLow, Main.maxTilesY), (double)WorldGen.genRand.Next(3, 6), WorldGen.genRand.Next(2, 6), mod.TileType("ExampleBlock"), false, 0f, 0f, false, true);
                }
            }));
        }
where "mod.TileType("ExampleBlock")" is the tile, 6E-05 is a multiplier on the number of loops, and I forget all the parameters for TileRunner right now.

When I inserted that code into my world file I got this error
c:\Users\Julian Romero\Documents\My Games\Terraria\ModLoader\Mod Sources\EpicnessMod\EpicnessWorld.cs(55,48) : error CS0246: The type or namespace name 'PassLegacy' could not be found (are you missing a using directive or an assembly reference?)
Here is the code of the world file:
Code:
using System.IO;
using System.Collections.Generic;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.World.Generation;
using Microsoft.Xna.Framework;
using System;

namespace EpicnessMod
{
    public class EpicnessWorld : ModWorld
    {
        private const int saveVersion = 0;
        public static bool downedDarkNebula = false;
        public static int DarkNebulaDefeated;
        public const int MSG_BLESS = 1;   
        //public struct EpicnessMsgs
//{
public static string[] misc = {"Your world has been infected with Corrupt Ore!"};
//}

        public override void Initialize()
        {
            downedDarkNebula = false;
        }

        public override void SaveCustomData(BinaryWriter writer)
        {
            writer.Write(saveVersion);
            byte flags = 0;
            writer.Write(DarkNebulaDefeated);
            if (downedDarkNebula)
            {
                flags |= 1;
            }
            writer.Write(flags);
        }

        public override void LoadCustomData(BinaryReader reader)
        {
            reader.ReadInt32();
            DarkNebulaDefeated = reader.ReadInt32();
            byte flags = reader.ReadByte();
            downedDarkNebula = ((flags & 1) == 1);
        }
        public override void ModifyWorldGenTasks(List<GenPass> tasks, ref float totalWeight)
        {
            int ShiniesIndex = tasks.FindIndex(genpass => genpass.Name.Equals("Micro Biomes"));
            if (ShiniesIndex == -1)
            {
                // Shinies pass removed by some other mod.
                return;
            }
            tasks.Insert(ShiniesIndex + 1, new PassLegacy("Corrupt Ore", delegate (GenerationProgress progress)
            {
                progress.Message = "Corrupt Ore";

                for (int k = 0; k < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 6E-05); k++)
                {
                    WorldGen.TileRunner(WorldGen.genRand.Next(0, Main.maxTilesX), WorldGen.genRand.Next((int)WorldGen.worldSurfaceLow, Main.maxTilesY), (double)WorldGen.genRand.Next(3, 6), WorldGen.genRand.Next(2, 6), mod.TileType("Corrupt Ore"), false, 0f, 0f, false, true);
                }
            }));
        }
        }
    }
 
When I inserted that code into my world file I got this error
c:\Users\Julian Romero\Documents\My Games\Terraria\ModLoader\Mod Sources\EpicnessMod\EpicnessWorld.cs(55,48) : error CS0246: The type or namespace name 'PassLegacy' could not be found (are you missing a using directive or an assembly reference?)
Here is the code of the world file:
Code:
using System.IO;
using System.Collections.Generic;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.World.Generation;
using Microsoft.Xna.Framework;
using System;

namespace EpicnessMod
{
    public class EpicnessWorld : ModWorld
    {
        private const int saveVersion = 0;
        public static bool downedDarkNebula = false;
        public static int DarkNebulaDefeated;
        public const int MSG_BLESS = 1;  
        //public struct EpicnessMsgs
//{
public static string[] misc = {"Your world has been infected with Corrupt Ore!"};
//}

        public override void Initialize()
        {
            downedDarkNebula = false;
        }

        public override void SaveCustomData(BinaryWriter writer)
        {
            writer.Write(saveVersion);
            byte flags = 0;
            writer.Write(DarkNebulaDefeated);
            if (downedDarkNebula)
            {
                flags |= 1;
            }
            writer.Write(flags);
        }

        public override void LoadCustomData(BinaryReader reader)
        {
            reader.ReadInt32();
            DarkNebulaDefeated = reader.ReadInt32();
            byte flags = reader.ReadByte();
            downedDarkNebula = ((flags & 1) == 1);
        }
        public override void ModifyWorldGenTasks(List<GenPass> tasks, ref float totalWeight)
        {
            int ShiniesIndex = tasks.FindIndex(genpass => genpass.Name.Equals("Micro Biomes"));
            if (ShiniesIndex == -1)
            {
                // Shinies pass removed by some other mod.
                return;
            }
            tasks.Insert(ShiniesIndex + 1, new PassLegacy("Corrupt Ore", delegate (GenerationProgress progress)
            {
                progress.Message = "Corrupt Ore";

                for (int k = 0; k < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 6E-05); k++)
                {
                    WorldGen.TileRunner(WorldGen.genRand.Next(0, Main.maxTilesX), WorldGen.genRand.Next((int)WorldGen.worldSurfaceLow, Main.maxTilesY), (double)WorldGen.genRand.Next(3, 6), WorldGen.genRand.Next(2, 6), mod.TileType("Corrupt Ore"), false, 0f, 0f, false, true);
                }
            }));
        }
        }
    }

If you aren't using Visual Studio yet, you should really try.

Anyway, the using statement is "using Terraria.GameContent.Generation;"
 

If you aren't using Visual Studio yet, you should really try.

Anyway, the using statement is "using Terraria.GameContent.Generation;"

No, I don't have visual studio.... for some reason when I try to use it it kills it self :/.
Thanks for the help :)
[doublepost=1459210733,1459210260][/doublepost]

If you aren't using Visual Studio yet, you should really try.

Anyway, the using statement is "using Terraria.GameContent.Generation;"

This might be a stupid question but where would the ore appear now that it is generates (so that I have a reference point to find it)
 
This might be a stupid question but where would the ore appear now that it is generates (so that I have a reference point to find it)
Here is the method signature.
sBjOSEl.png

i and j are tile coordinates, so if you read the current code, it says "WorldGen.genRand.Next(0, Main.maxTilesX)" for i, so it will appear at all x coordinates. For j, it says "
WorldGen.genRand.Next((int)WorldGen.worldSurfaceLow, Main.maxTilesY)", which means it will show up at depths from worldsurfacelow all the way down to the bottom of the map. worldsurfacelow is actually the highest surface height, so you could change it to rockLayer if you want it below the rock layer line.


Also, "mod.TileType("Corrupt Ore")" is most likely wrong. The class name is not Corrupt Ore, it might be CorruptOre maybe?
 
Would this be appropriate to make an enemy only spawn in the sky...? Maybe - 250 should be like, - 350? Now that I think about it, this probably only works on a small world...
Code:
public override float CanSpawn(NPCSpawnInfo spawnInfo)
        {
            Player player = Main.player[Main.myPlayer];
            int x = spawnInfo.spawnTileX;
            int y = spawnInfo.spawnTileY;
            int tile = (int)Main.tile[x, y].type;
            return (ThoriumMod.NormalSpawn(spawnInfo)) && spawnInfo.spawnTileY < Main.worldSurface - 250 && (int)(player.position.Y / 16) < Main.maxTilesY - 200 && Main.evilTiles < 100 && Main.snowTiles < 100 && Main.sandTiles < 100 && Main.bloodTiles < 100 && Main.jungleTiles < 100 && Main.dungeonTiles < 100 ? 0.20f : 0f;

        }
 
can some one help me i would like my Helmet to shoot a laser in a enemy direction but not going after it
Could you explain a bit more?
Are you already shooting the projectile? If so, could you show us the code where you spawn the projectile, as well as the code of the projectile in question?
 
How do I make custom wings (I would like to make infinite)?
The following is an example:
Code:
public override bool Autoload(ref string name, ref string texture, IList<EquipType> equips)
{
    equips.Add(EquipType.Wings);
    return true;
}

public override void SetDefaults()
{
    item.name = "ings";
    item.width = 24;
    item.height = 30;
    item.toolTip = "Allows for infinite flight";
    item.value = Item.sellPrice(5, 0, 0, 0);
    item.rare = 10;
    item.accessory = true;
}

public override void UpdateAccessory(Player player, bool hideVisual)
{
    player.wingTimeMax = 18000; // 5 minutes flight.
}

public override void VerticalWingSpeeds(ref float ascentWhenFalling, ref float ascentWhenRising,
    ref float maxCanAscendMultiplier, ref float maxAscentMultiplier, ref float constantAscend)
{
    ascentWhenFalling = 0.85f;
    ascentWhenRising = 0.15f;
    maxCanAscendMultiplier = 1f;
    maxAscentMultiplier = 3f;
    constantAscend = 0.135f;
}

public override void HorizontalWingSpeeds(ref float speed, ref float acceleration)
{
    speed = 10f;
    acceleration *= 3f;
}
// NOTE: The following function is used to allow for infinite flight. This is UNTESTED so keep that in mind.
// If you want to add effects when using your wings, this is also the place to do that.
public override void WingUpdate(Player player, bool inUse)
{
    if (inUse)
    {
        player.wingTime = 10;
    }
}
I'm guessing a lot of the names of the used variables should explain what they do. If you're wondering what they do, just change their values and see what changes in-game.
As for the custom item groups (I'm guessing you're referring to CraftGroup?): There is a function you can override in your class that derives from Mod:
Code:
public override void AddCraftGroups()
{   
    AddCraftGroup("CraftGroupName", Lang.misc[37] + " " + "Craft Group Display Name",
        ItemType("MyItem1"), ItemType("MyItem2"), ItemType("MyItem3"), ItemType("MyItem4")); 
}
As you can see, the first parameter is the name you call the craft group with (when creating a recipe that uses this CraftGroup), the second is the name that is displayed to the player and then you can fill the rest of the function with the IDs of the items you want to include in this CraftGroup.

Hope this works for ya.
 
Back
Top Bottom