• PC 1.4.3: An eye for an eye, the Terraria x Don't Starve Together Crossover Update! Get all the details here. Found some bugs? Report them with as much detail as possible here.
  • Xbox & PS 1.4: Get all the info on the Journey's End update by clicking here. Known Issues and FAQ can be read here. For any other bugs, report them (with as much detail as possible) here.
  • Switch 1.4: Journey's End will launch on Switch January 4, 2022! More details here.
  • Mobile News: Stay up to date with the latest mobile news here. Report mobile bugs here

tModLoader Help with Ore Generation

Neonite

Skeletron Prime
Hello!
I'm trying to get ore to spawn at the bottom of the cavern layer after a
boss has been defeated, and it isn't spawning in the ore. Does anyone
know how I could fix this? I can't get help anywhere else. Thanks!


Code:
            if (npc.type == NPCID.EyeofCthulhu)

            {
                if (!Mworld.spawnOre)
                {
                    Main.NewText("A feeling of hope washes over your mind, a green light shines in the darkness below", 0, 200, 0);
                    for (int k = 0; k < (int)((double)(WorldGen.rockLayer * Main.maxTilesY) * 40E-05); k++)
                    {
                        int X = WorldGen.genRand.Next(0, Main.maxTilesX);
                        int Y = WorldGen.genRand.Next((int)WorldGen.rockLayer, Main.maxTilesY - 200);
                        WorldGen.TileRunner(X, Y, WorldGen.genRand.Next(9, 15), WorldGen.genRand.Next(5, 9), (ushort)mod.TileType("NeoniteOre"));
                    }
                }
                Mworld.spawnOre = true;
            }
 

Quethed

Terrarian
Note: This thread is spam, here is the correct thread: tModLoader - Official tModLoader Help Thread
I have noticed that we think the same "(WorldGen.rockLayer * Main.maxTilesY)"
Note: NEVER use WorldGen.TileRunner after world gen, it overrides ANYTHING. I "think" OreRunner(int i, int j, double strength, int steps, int type) is what is needed

(untested, and if this still does nothing, replace NPC.downedBoss1 with Mworld.spawnOre)

public override void NPCLoot(NPC npc){
if (!NPC.downedBoss1&&npc.type==NPCID.EyeofCthulhu){
Main.NewText("A feeling of hope washes over your mind, a green light shines in the darkness below", 0, 200, 0);
for (int k = 0; k < (int)((WorldGen.rockLayer * Main.maxTilesY) * 5); k++){
int X = WorldGen.genRand.Next(0, Main.maxTilesX);
int Y = WorldGen.genRand.Next((int)WorldGen.rockLayer, Main.maxTilesY - 200);
WorldGen.OreRunner(X, Y, 5/*idk*/, 5/*idk*/,mod.TileType("NeoniteOre"));//Sadly I found nowhere to put WorldGen.genRand.Next(5, 9)
}
}
}
 

CrimsonTek

Terrarian
I see a few things I would consider changing, and I slightly rewrote your code with comments on how I would fix them. Hope this helps :)

C#:
if (npc.type == NPCID.EyeofCthulhu)
{
    if (!Mworld.spawnOre)
    {
        // setting these two to true may allow some functions to work differently, might help?
        WorldGen.noTileActions = true;
        WorldGen.gen = true;
        
        Main.NewText("A feeling of hope washes over your mind, a green light shines in the darkness below", 0, 200, 0);
        
        // WorldGen.rockLayer may not exist after the world is created.
        // (int)((double)(WorldGen.rockLayer * Main.maxTilesY) * 40E-05) evaluates to ~3528 for a large world
        // (int)((Main.maxTilesX * Main.maxTilesY) * 1.75E-4) will yield a silimar result, can will work at any stage of the game
        for (int k = 0; k < (int)((Main.maxTilesX * Main.maxTilesY) * 1.75E-4); k++)
        {
            // techically these should be lowercase, but they dont have to be
            int x = WorldGen.genRand.Next(0, Main.maxTilesX);
            int y = WorldGen.genRand.Next((int)WorldGen.rockLayer, Main.maxTilesY - 200);
            // consider using WorldGen.OreRunner instead of this. Also, use ModContent.TileType<NeoniteOre>(), as mod.TileType is deprecated
            WorldGen.OreRunner(x, y, WorldGen.genRand.Next(9, 15), WorldGen.genRand.Next(5, 9), (short)ModContent.TileType<NeoniteOre>());
            
            // you can use something like this to see if this code is getting run enough
            Main.NewText($"Tried to create ore at {x} {y}. (iteration {k} of {(int)((double)(WorldGen.rockLayer * Main.maxTilesY) * 40E-05)})");
        }
        
        // gotta be sure to set this back to false
        WorldGen.noTileActions = false;
        WorldGen.gen = false;
        
        Mworld.spawnOre = true;
    }
}
 
Top Bottom