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;
            }
 
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)
}
}
}
 
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;
    }
}
 
Back
Top Bottom