Standalone [1.3] tModLoader - A Modding API

How would i go about Generating Ore onto new maps ?
There is an example one post above your post, the ModifyWorldGenTasks portion.
[DOUBLEPOST=1457339147,1457338972][/DOUBLEPOST]
Do I change the numbers to define the rarity?
This part:
for (int k = 0; k < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 6E-05); k++)
is how many splotches, ant the other variables relate to how big the splotches are.
public static void TileRunner(int i, int j, double strength, int steps, int type, bool addTile = false, float speedX = 0f, float speedY = 0f, bool noYChange = false, bool overRide = true)
 
How do you edit the loottables of randomly generated chests (like pyridmid chests)
I've made an example:

Code:
        public override void PostWorldGen()
        {
            // Place some items in Ice Chests
            int[] itemsToPlaceInWaterChests = new int[] { mod.ItemType("CarKey"), mod.ItemType("ExampleLightPet"), ItemID.PinkJellyfishJar };
            int itemsToPlaceInWaterChestsChoice = 0;
            for (int chestIndex = 0; chestIndex < 1000; chestIndex++)
            {
                Chest chest = Main.chest[chestIndex];
                if (chest != null && Main.tile[chest.x, chest.y].frameX == 11 * 36)
                {
                    for (int inventoryIndex = 0; inventoryIndex < 40; inventoryIndex++)
                    {
                        if (chest.item[inventoryIndex].type == 0)
                        {
                            chest.item[inventoryIndex].SetDefaults(itemsToPlaceInWaterChests[itemsToPlaceInWaterChestsChoice]);
                            itemsToPlaceInWaterChestsChoice = (itemsToPlaceInWaterChestsChoice + 1) % itemsToPlaceInWaterChests.Length;
                            break;
                        }
                    }
                }
            }
        }
 
Code:
c:\Users\Devin\Documents\My Games\Terraria\ModLoader\Mod Sources\Enderuim\Tiles\ExampleBlock.cs(33,32) : error CS0115: 'ExampleMod.Tiles.ExampleBlock.ModifyWorldGenTasks(System.Collections.Generic.List<Terraria.World.Generation.GenPass>, ref float)': no suitable method found to override


using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using System.Collections.Generic;
using Terraria.World.Generation;
namespace ExampleMod.Tiles
{
    public class ExampleBlock : ModTile
    {
        public override void SetDefaults()
        {
            Main.tileSolid[Type] = true;
            Main.tileMergeDirt[Type] = true;
            Main.tileBlockLight[Type] = true;
            Main.tileLighted[Type] = true;
            dustType = mod.DustType("Sparkle");
            AddMapEntry(new Color(200, 200, 200));
        }

        public override void NumDust(int i, int j, bool fail, ref int num)
        {
            num = fail ? 1 : 3;
        }

        public override void ModifyLight(int i, int j, ref float r, ref float g, ref float b)
        {
            r = 0.5f;
            g = 0.5f;
            b = 0.5f;
        }
                public override void ModifyWorldGenTasks(List<GenPass> tasks, ref float totalWeight)
        {
            int ShiniesIndex = tasks.FindIndex(genpass => genpass.Name.Equals("Shinies"));

            tasks.Insert(ShiniesIndex + 1, new PassLegacy("Crazy Ore", delegate (GenerationProgress progress)
            {
                progress.Message = "Growing Enderuim Crystals...";

                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);
                }
            }));
        }
    }
}
 
Code:
c:\Users\Devin\Documents\My Games\Terraria\ModLoader\Mod Sources\Enderuim\Tiles\ExampleBlock.cs(33,32) : error CS0115: 'ExampleMod.Tiles.ExampleBlock.ModifyWorldGenTasks(System.Collections.Generic.List<Terraria.World.Generation.GenPass>, ref float)': no suitable method found to override


using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using System.Collections.Generic;
using Terraria.World.Generation;
namespace ExampleMod.Tiles
{
    public class ExampleBlock : ModTile
    {
        public override void SetDefaults()
        {
            Main.tileSolid[Type] = true;
            Main.tileMergeDirt[Type] = true;
            Main.tileBlockLight[Type] = true;
            Main.tileLighted[Type] = true;
            dustType = mod.DustType("Sparkle");
            AddMapEntry(new Color(200, 200, 200));
        }

        public override void NumDust(int i, int j, bool fail, ref int num)
        {
            num = fail ? 1 : 3;
        }

        public override void ModifyLight(int i, int j, ref float r, ref float g, ref float b)
        {
            r = 0.5f;
            g = 0.5f;
            b = 0.5f;
        }
                public override void ModifyWorldGenTasks(List<GenPass> tasks, ref float totalWeight)
        {
            int ShiniesIndex = tasks.FindIndex(genpass => genpass.Name.Equals("Shinies"));

            tasks.Insert(ShiniesIndex + 1, new PassLegacy("Crazy Ore", delegate (GenerationProgress progress)
            {
                progress.Message = "Growing Enderuim Crystals...";

                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);
                }
            }));
        }
    }
}
You do not want to put the ModifyWorldGenTasks in a ModTile class.
Instead, create a class that derives from ModWorld and put it in there.
 
Code:
c:\Users\Devin\Documents\My Games\Terraria\ModLoader\Mod Sources\Enderuim\Tiles\ExampleBlock.cs(33,32) : error CS0115: 'ExampleMod.Tiles.ExampleBlock.ModifyWorldGenTasks(System.Collections.Generic.List<Terraria.World.Generation.GenPass>, ref float)': no suitable method found to override


using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using System.Collections.Generic;
using Terraria.World.Generation;
namespace ExampleMod.Tiles
{
    public class ExampleBlock : ModTile
    {
        public override void SetDefaults()
        {
            Main.tileSolid[Type] = true;
            Main.tileMergeDirt[Type] = true;
            Main.tileBlockLight[Type] = true;
            Main.tileLighted[Type] = true;
            dustType = mod.DustType("Sparkle");
            AddMapEntry(new Color(200, 200, 200));
        }

        public override void NumDust(int i, int j, bool fail, ref int num)
        {
            num = fail ? 1 : 3;
        }

        public override void ModifyLight(int i, int j, ref float r, ref float g, ref float b)
        {
            r = 0.5f;
            g = 0.5f;
            b = 0.5f;
        }
                public override void ModifyWorldGenTasks(List<GenPass> tasks, ref float totalWeight)
        {
            int ShiniesIndex = tasks.FindIndex(genpass => genpass.Name.Equals("Shinies"));

            tasks.Insert(ShiniesIndex + 1, new PassLegacy("Crazy Ore", delegate (GenerationProgress progress)
            {
                progress.Message = "Growing Enderuim Crystals...";

                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);
                }
            }));
        }
    }
}
Well, it's a ModWorld method not a ModTile method.
 
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using System.Collections.Generic;
using Terraria.World.Generation;
{
namespace ExampleMod.Tiles   
    {
            public override void ModifyWorldGenTasks(List<GenPass> tasks, ref float totalWeight)
        {
            int ShiniesIndex = tasks.FindIndex(genpass => genpass.Name.Equals("Shinies"));

            tasks.Insert(ShiniesIndex + 1, new PassLegacy("Crazy Ore", delegate (GenerationProgress progress)
            {
                progress.Message = "Growing Enderuim Crystals...";

                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);
                }
            }));
        }
    }
}
c:\Users\Devin\Documents\My Games\Terraria\ModLoader\Mod Sources\Enderuim\Tiles\ExampleBlockGen.cs(8,1) : error CS0116: A namespace cannot directly contain members such as fields or methods

c:\Users\Devin\Documents\My Games\Terraria\ModLoader\Mod Sources\Enderuim\Tiles\ExampleBlockGen.cs(11,26) : error CS1518: Expected class, delegate, enum, interface, or struct

c:\Users\Devin\Documents\My Games\Terraria\ModLoader\Mod Sources\Enderuim\Tiles\ExampleBlockGen.cs(15,48) : error CS1518: Expected class, delegate, enum, interface, or struct

c:\Users\Devin\Documents\My Games\Terraria\ModLoader\Mod Sources\Enderuim\Tiles\ExampleBlockGen.cs(15,81) : error CS1031: Type expected

c:\Users\Devin\Documents\My Games\Terraria\ModLoader\Mod Sources\Enderuim\Tiles\ExampleBlockGen.cs(15,110) : error CS1002: ; expected

c:\Users\Devin\Documents\My Games\Terraria\ModLoader\Mod Sources\Enderuim\Tiles\ExampleBlockGen.cs(16,13) : error CS0116: A namespace cannot directly contain members such as fields or methods

c:\Users\Devin\Documents\My Games\Terraria\ModLoader\Mod Sources\Enderuim\Tiles\ExampleBlockGen.cs(23,14) : error CS0116: A namespace cannot directly contain members such as fields or methods

c:\Users\Devin\Documents\My Games\Terraria\ModLoader\Mod Sources\Enderuim\Tiles\ExampleBlockGen.cs(24,9) : error CS1022: Type or namespace definition, or end-of-file expected
 
EDIT: WRONG QUOTE, SORRY FOR THAT
here's the proper quote:

I've made an example:

Code:
        public override void PostWorldGen()
        {
            // Place some items in Ice Chests
            int[] itemsToPlaceInWaterChests = new int[] { mod.ItemType("CarKey"), mod.ItemType("ExampleLightPet"), ItemID.PinkJellyfishJar };
            int itemsToPlaceInWaterChestsChoice = 0;
            for (int chestIndex = 0; chestIndex < 1000; chestIndex++)
            {
                Chest chest = Main.chest[chestIndex];
                if (chest != null && Main.tile[chest.x, chest.y].frameX == 11 * 36)
                {
                    for (int inventoryIndex = 0; inventoryIndex < 40; inventoryIndex++)
                    {
                        if (chest.item[inventoryIndex].type == 0)
                        {
                            chest.item[inventoryIndex].SetDefaults(itemsToPlaceInWaterChests[itemsToPlaceInWaterChestsChoice]);
                            itemsToPlaceInWaterChestsChoice = (itemsToPlaceInWaterChestsChoice + 1) % itemsToPlaceInWaterChests.Length;
                            break;
                        }
                    }
                }
            }
        }


are you sure using a fix number in the loop is a good idea?
isn't there a method to retrieve all chests in the world so you can use that array/list/whatever's length property?
what if that code runs and there are 999 chests? you'd definitely get a index out of range exception
 
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using System.Collections.Generic;
using Terraria.World.Generation;
{
namespace ExampleMod.Tiles 
    {
            public override void ModifyWorldGenTasks(List<GenPass> tasks, ref float totalWeight)
        {
            int ShiniesIndex = tasks.FindIndex(genpass => genpass.Name.Equals("Shinies"));

            tasks.Insert(ShiniesIndex + 1, new PassLegacy("Crazy Ore", delegate (GenerationProgress progress)
            {
                progress.Message = "Growing Enderuim Crystals...";

                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);
                }
            }));
        }
    }
}
c:\Users\Devin\Documents\My Games\Terraria\ModLoader\Mod Sources\Enderuim\Tiles\ExampleBlockGen.cs(8,1) : error CS0116: A namespace cannot directly contain members such as fields or methods

c:\Users\Devin\Documents\My Games\Terraria\ModLoader\Mod Sources\Enderuim\Tiles\ExampleBlockGen.cs(11,26) : error CS1518: Expected class, delegate, enum, interface, or struct

c:\Users\Devin\Documents\My Games\Terraria\ModLoader\Mod Sources\Enderuim\Tiles\ExampleBlockGen.cs(15,48) : error CS1518: Expected class, delegate, enum, interface, or struct

c:\Users\Devin\Documents\My Games\Terraria\ModLoader\Mod Sources\Enderuim\Tiles\ExampleBlockGen.cs(15,81) : error CS1031: Type expected

c:\Users\Devin\Documents\My Games\Terraria\ModLoader\Mod Sources\Enderuim\Tiles\ExampleBlockGen.cs(15,110) : error CS1002: ; expected

c:\Users\Devin\Documents\My Games\Terraria\ModLoader\Mod Sources\Enderuim\Tiles\ExampleBlockGen.cs(16,13) : error CS0116: A namespace cannot directly contain members such as fields or methods

c:\Users\Devin\Documents\My Games\Terraria\ModLoader\Mod Sources\Enderuim\Tiles\ExampleBlockGen.cs(23,14) : error CS0116: A namespace cannot directly contain members such as fields or methods

c:\Users\Devin\Documents\My Games\Terraria\ModLoader\Mod Sources\Enderuim\Tiles\ExampleBlockGen.cs(24,9) : error CS1022: Type or namespace definition, or end-of-file expected
You did not create a class, just a namespace.
Code:
namespace ExampleMod.Tiles
{
    public class MyModWorld : ModWorld // Make sure you create a class (and close it, ofc).
    {
    }
}
EDIT: WRONG QUOTE, SORRY FOR THAT
here's the proper quote:




are you sure using a fix number in the loop is a good idea?
isn't there a method to retrieve all chests in the world so you can use that array/list/whatever's length property?
what if that code runs and there are 999 chests? you'd definitely get a index out of range exception
Well, Terraria itself also loops using hardcoded values, so nothing wrong there (although I do agree that in some cases using Length might be better).
Anyway, it's a good idea to hardcode your loops when modding Terraria, since in many arrays (such as Main.npc and Main.player) there is one array index (the last to be precise) which is not supposed to be looped through (it's a faulty index, only used when spawning/creating the NPCs/Players/etc. goes wrong).
Now in these cases, using something like Main.npc.Length - 1 may also work... But meh.
 
Last edited:
im trying to make stuff happen BEFORE the player uses a weapon, with the possibility to cancel the usage of said item, is there a hook for this?
 
Little help please, didnt work got the error,
NewOre.cs(34,22) : error CS0115: 'DarkArmorReforged.Tiles.Block.NewOre.ModifyWorldGenTasks(System.Collections.Generic.List<Terraria.World.Generation.GenPass>, ref float)': no suitable method found to override

Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using System.Collections.Generic;
using Terraria.World.Generation;

namespace DarkArmorReforged.Tiles.Block
{
    public class NewOre : ModTile
    {
        public override void SetDefaults()
        {
            Main.tileSolid[Type] = true;
            Main.tileMergeDirt[Type] = true;
            Main.tileBlockLight[Type] = true;
            Main.tileLighted[Type] = true;
            dustType = mod.DustType("Sparkle");
            AddMapEntry(new Color(200, 200, 200));
        }

        public override void NumDust(int i, int j, bool fail, ref int num)
        {
            num = fail ? 1 : 3;
        }

        public override void ModifyLight(int i, int j, ref float r, ref float g, ref float b)
        {
            r = 0.5f;
            g = 0.5f;
            b = 0.5f;
    }
public override void ModifyWorldGenTasks(List<GenPass> tasks, ref float totalWeight)
{
int ShiniesIndex = tasks.FindIndex(genpass => genpass.Name.Equals("Shinies"));

tasks.Insert(ShiniesIndex + 1, new PassLegacy("NewOre", delegate (GenerationProgress progress)
{
progress.Message = "Adding NewOre...";

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("NewOre"), false, 0f, 0f, false, true);
}
}));
}
}
}
 
Little help please, didnt work got the error,
NewOre.cs(34,22) : error CS0115: 'DarkArmorReforged.Tiles.Block.NewOre.ModifyWorldGenTasks(System.Collections.Generic.List<Terraria.World.Generation.GenPass>, ref float)': no suitable method found to override

Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using System.Collections.Generic;
using Terraria.World.Generation;

namespace DarkArmorReforged.Tiles.Block
{
    public class NewOre : ModTile
    {
        public override void SetDefaults()
        {
            Main.tileSolid[Type] = true;
            Main.tileMergeDirt[Type] = true;
            Main.tileBlockLight[Type] = true;
            Main.tileLighted[Type] = true;
            dustType = mod.DustType("Sparkle");
            AddMapEntry(new Color(200, 200, 200));
        }

        public override void NumDust(int i, int j, bool fail, ref int num)
        {
            num = fail ? 1 : 3;
        }

        public override void ModifyLight(int i, int j, ref float r, ref float g, ref float b)
        {
            r = 0.5f;
            g = 0.5f;
            b = 0.5f;
    }
public override void ModifyWorldGenTasks(List<GenPass> tasks, ref float totalWeight)
{
int ShiniesIndex = tasks.FindIndex(genpass => genpass.Name.Equals("Shinies"));

tasks.Insert(ShiniesIndex + 1, new PassLegacy("NewOre", delegate (GenerationProgress progress)
{
progress.Message = "Adding NewOre...";

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("NewOre"), false, 0f, 0f, false, true);
}
}));
}
}
}
If you go to this post and see the answers given on that, you can see you made the exact same mistake (and how to fix it too ;) ).
 
So your saying it should be
public class NewOre : ModWorld
{

What about the

public override void SetDefaults()
{
Main.tileSolid[Type] = true;
Main.tileMergeDirt[Type] = true;
Main.tileBlockLight[Type] = true;
Main.tileLighted[Type] = true;
dustType = mod.DustType("Sparkle");
AddMapEntry(new Color(200, 200, 200));
}
 
i'm confused, the hook you told me is from the ModItem, what I'm looking for is a method called by the player whenever he uses any item, since im trying to do stuff to vanilla items
 
Hey guys. Is it possible to play multiplayer in current version of Tmodloader and Tremor remastared?... If it is can you please tell me how to host a server. Tnx for answers!:joy:
 
So your saying it should be
public class NewOre : ModWorld
{

What about the

public override void SetDefaults()
{
Main.tileSolid[Type] = true;
Main.tileMergeDirt[Type] = true;
Main.tileBlockLight[Type] = true;
Main.tileLighted[Type] = true;
dustType = mod.DustType("Sparkle");
AddMapEntry(new Color(200, 200, 200));
}
You don't need that in the ModWorld hook, you'll only want a ModTile class for that.
i'm confused, the hook you told me is from the ModItem, what I'm looking for is a method called by the player whenever he uses any item, since im trying to do stuff to vanilla items
Ah, if that is the case, you'll want to use that hook but then on a class that derives from GlobalItem (also to be found on that wiki).
 
im not sure if im understanding the GlobalItem class properly, do i need one instance for each vanilla item i want to modify??
 
im not sure if im understanding the GlobalItem class properly, do i need one instance for each vanilla item i want to modify??
No, you can use one instance for ALL vanilla items, you just want to check the type of the item in question to see if it's the item you're looking for.
Creating multiple instances of GlobalItem will result in (massive) lag/FPS loss.
 
Back
Top Bottom