Custom Ore in Custom World?

Discussion in 'Released Mods' started by >:SYNTAX, Dec 13, 2012.

  1. >:SYNTAX Mouse

    so i decided to make a another realm for my mod today with totally different blocks and monsters as such, but when i tried to add in custom ores they don't generate with the world.

    so i tried taking my "Global" folder out of my mod pack to it wouldn't generate a different world but still generate the ores, and they show up in the default Terraria world but not mine, so what I'm asking dose anyone know the code for getting a custom world to generate custom ores

    These are the pices of code that i am currently using,

    world generation (open)

    public void GenerateWorld()

    {
    int SectionType = 0;
    int SectionWidth = 0;
    double SectionHeight = (double)Main.maxTilesY * 0.3;
    SectionHeight *= (double)WorldGen.genRand.Next(90, 110) * 0.005;
    double rockLayer = SectionHeight + (double)Main.maxTilesY * 0.2;
    rockLayer *= (double)WorldGen.genRand.Next(90, 110) * 0.01;
    double worldSurfaceL = SectionHeight;
    double rockLayerL = rockLayer;

    for (int i = 0; i < Main.maxTilesX; i++)
    {

    if (SectionHeight > worldSurfaceL)
    {
    worldSurfaceL = SectionHeight; // the deepest the surface goes down
    }
    if (rockLayer > rockLayerL)
    {
    rockLayerL = rockLayer; // the lowest the rocklayer starts
    }

    // when the section runs out, make a new section.
    if (SectionWidth <= 0)
    {
    SectionType = WorldGen.genRand.Next(0, 5);
    SectionWidth = WorldGen.genRand.Next(5, 40);
    if (SectionType == 0)
    {
    SectionWidth *= (int)((double)WorldGen.genRand.Next(5, 30) * 0.2);
    }
    }
    SectionWidth--;

    // end section width assesment, begin section height assessment

    if (SectionType == 0) // small variation only
    {
    while (WorldGen.genRand.Next(0, 7) == 0)
    {
    SectionHeight += (double)WorldGen.genRand.Next(-1, 2);
    }
    }
    else if (SectionType == 1) // generally decrease (higher ground)
    {
    while (WorldGen.genRand.Next(0, 4) == 0)
    {
    SectionHeight -= 1.0;
    }
    while (WorldGen.genRand.Next(0, 10) == 0)
    {
    SectionHeight += 1.0;
    }
    }
    else if (SectionType == 2) // generally increase (lower ground)
    {
    while (WorldGen.genRand.Next(0, 4) == 0)
    {
    SectionHeight += 1.0;
    }
    while (WorldGen.genRand.Next(0, 10) == 0)
    {
    SectionHeight -= 1.0;
    }
    }
    else if (SectionType == 3) // steep decrease (much higher ground)
    {
    while (WorldGen.genRand.Next(0, 2) == 0)
    {
    SectionHeight -= 1.0;
    }
    while (WorldGen.genRand.Next(0, 6) == 0)
    {
    SectionHeight += 1.0;
    }
    }
    else if (SectionType == 4) // steep increase (much lower ground)
    {
    while (WorldGen.genRand.Next(0, 2) == 0)
    {
    SectionHeight += 1.0;
    }
    while (WorldGen.genRand.Next(0, 5) == 0)
    {
    SectionHeight -= 1.0;
    }
    }

    // if the section is too high or low, put the height at the bound and stop the section.
    if (SectionHeight < (double)Main.maxTilesY * 0.17)
    {
    SectionHeight = (double)Main.maxTilesY * 0.17;
    SectionWidth = 0;
    }
    else if (SectionHeight > (double)Main.maxTilesY * 0.3)
    {
    SectionHeight = (double)Main.maxTilesY * 0.3;
    SectionWidth = 0;
    }

    // control height at the sides of the world
    if ((i < 275 || i > Main.maxTilesX - 275) && SectionHeight > (double)Main.maxTilesY * 0.25)
    {
    SectionHeight = (double)Main.maxTilesY * 0.25;
    SectionWidth = 1;
    }

    // push rocklayer down to between .05-.35maxY below the surface
    while (WorldGen.genRand.Next(0, 3) == 0)
    {
    rockLayer += (double)WorldGen.genRand.Next(-2, 3);
    }
    if (rockLayer < SectionHeight + (double)Main.maxTilesY * 0.05)
    {
    rockLayer += 1.0;
    }
    if (rockLayer > SectionHeight + (double)Main.maxTilesY * 0.35)
    {
    rockLayer -= 1.0;
    }

    // make empty tiles down to SectionHeight, dirt down to rockLayer, stone below that
    for (int j = 0; j < Main.maxTilesY; j++)
    {
    if ((double)j < SectionHeight)
    {
    Main.tile[i, j].active = false;
    Main.tile[i, j].frameX = -1; // this is the bit for the empty tiles to go dont tamper with this unlass you want to have blocks everywhere and sufacate
    Main.tile[i, j].frameY = -1;
    }
    else if ((double)j < rockLayer)
    {
    Main.tile[i, j].active = true;
    Main.tile[i, j].type =151;// the tile that the first layer is made out of this includes the surface layer. this has to be set as a number
    Main.tile[i, j].frameX = -1;
    Main.tile[i, j].frameY = -1;
    }
    else
    {
    Main.tile[i, j].active = true;
    Main.tile[i, j].type = 153; //what the second layer is made out of (the rock layer)
    Main.tile[i, j].frameX = -1;
    Main.tile[i, j].frameY = -1;

    }



    }
    }

    // now that the surface is made, set some values for levels.
    Main.worldSurface = worldSurfaceL + 25.0;
    Main.rockLayer = Main.worldSurface + (double)((int)((rockLayerL - Main.worldSurface) / 6.0) * 6);

    int spawnTileX = Main.maxTilesX / 2 + WorldGen.genRand.Next(-5, 6);
    for (int spawnTileY = 0; spawnTileY < Main.maxTilesY; spawnTileY++)
    {
    if (Main.tile[spawnTileX, spawnTileY].active)
    {
    Main.spawnTileX = spawnTileX;
    Main.spawnTileY = spawnTileY;
    break;
    }
    }

    // spawn grass on the surface
    for (int i = 151; i < Main.maxTilesX; i++)
    {
    for (int j = 151; j < Main.maxTilesY; j++)
    {
    if (Main.tile[i, j].active)
    {
    try
    {
    WorldGen.grassSpread = 151;
    WorldGen.SpreadGrass(i, j, 151, 152, true);
    }
    catch
    {
    WorldGen.grassSpread = 151;
    WorldGen.SpreadGrass(i, j, 151, 152, false);
    }
    }
    }
    }



    }



    Ore generation (open)


    public void ModifyWorld()
    {
    Main.statusText = "Adding My Ore..."; //feel free to tweak
    int Amount_Of_Spawns = 1000+(int)(Main.maxTilesY/5); //feel free to tweak
    for(int i=0;i<Amount_Of_Spawns;i++) AddTitan();
    }
    public void AddTitan()
    {
    int LowX = 200; //after ocean on left edge of map
    int HighX = Main.maxTilesX-200; //before ocean on right edge of map
    int LowY = (int)Main.worldSurface; //where the brown background and the sky background meets
    int HighY = Main.maxTilesY-200; //where hell and the grey background meets

    int X = WorldGen.genRand.Next(LowX,HighX); //don't touch
    int Y = WorldGen.genRand.Next(LowY,HighY); //don't touch

    int OreMinimumSpread = 20; //feel free to tweak
    int OreMaximumSpread = 32; //feel free to tweak

    int OreMinimumFrequency = 20; //feel free to tweak
    int OreMaximumFrequency = 32; //feel free to tweak

    int OreSpread = WorldGen.genRand.Next(OreMinimumSpread,OreMaximumSpread+1); //don't touch
    int OreFrequency = WorldGen.genRand.Next(OreMinimumFrequency,OreMaximumFrequency+1); //don't touch

    WorldGen.OreRunner(X, Y, (double)OreSpread, OreFrequency, Config.tileDefs.ID["Craytium"]);
    }


    Code by: Yoraiz0r
    Edited by: Mango97
  2. Where do you want the ore to be generated in?
  3. >:SYNTAX Mouse


    i want it to be generated in my custom world but when i generate a new world(custom one) it dosent show up but if i generate a normal world (default) it shows up

    other wise i want it to show up everywhere but the surface and hell,
  4. So, what you are saying is in your mod the world is generated differently?
  5. >:SYNTAX Mouse

    this is how my world looks
    the block with the rust is 152
    the block without the rust is 151


    this world is going to be like somewhere you go after you beat all 3 hard mode bosses, and its like a robot land im still working on it but the problem of my custom ore not spawning in it is getting in the way.
    [IMG]
  6. Since the ore works in the original code, why not use that but replacing the dirt blocks with the rust/iron blocks.
  7. >:SYNTAX Mouse

    well theres a big problem the code for world generation in the original terraria is 20,000 lines long, and i dont really want to try to fined where ever in it it spawns the ore, but thanks for trying :)
  8. Empio Blazing Wheel

    As far as I know OreRunner works off Terraria's default tile types. So it never actually hits a tile to spawn ore around.
  9. How about replacing silver ore with the ore you want.
  10. Empio Blazing Wheel

    Here's the custom generation code I wrote for the derelict Monster Hunter Tri mod.

    The code itself is pretty old, but it shouldn't be too hard to understand.

    Attached Files:

  11. For all we know you're just bad at finding ores. Try notching up (no minecraft reference here) the frequency.
  12. >:SYNTAX Mouse


    thanks for the code il sift through it tonight and its well documented so it should be no problem
  13. FreyModder Giant Worm

    What is an originaly code for spawn ore?
  14. spawn ore in ground lol ][]][[][
  15. >:SYNTAX Mouse

    your point?

Share This Page