tModLoader Official tModLoader Help Thread

How would I make a new AI for my mod?

I want it to be exactly like king slime's AI except he doesn't teleport or drop blue slimes when damaged.

If possible, I also what the ModNPC that uses this AI to drop a ModItem.
 
Hey, I´m trying to make a mod that adds a 7th accessory slot after the Demon Heart similar to Calamity´s Celestial Onion, but every time I try to use my item, the 7th accessory slot quickly flashes and disappears while still consuming the item... This is what i have so far ->
Any help is much appreciated.
upload_2019-1-27_13-6-22.png
 
Expected resource not found:
Placeable/terrariaplus
Closest guess: (Is there a spelling or folder placement error?)
Placeable/Shadowstone

at Terraria.ModLoader.Mod.GetTexture(String name)
at Terraria.ModLoader.ModLoader.GetTexture(String name)
at Terraria.ModLoader.ModItem.AutoStaticDefaults()
at Terraria.ModLoader.Mod.SetupContent()
at Terraria.ModLoader.ModLoader.do_Load(Object threadContext)

Item:

using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
// If you are using c# 6, you can use: "using static Terraria.Localization.GameCulture;" which would mean you could just write "DisplayName.AddTranslation(German, "");"
using Terraria.Localization;

namespace terrariaplus.Placeable
{
public class terrariaplus : ModItem
{
public override void SetStaticDefaults()
{
Tooltip.SetDefault("Only carried by a very powerful person");

// This is an example of how translations are coded into the game. Making your mod Open Source is a good way to enlist help with translations and make your mod more popular worldwide. Be sure to have "using Terraria.Localization".
DisplayName.AddTranslation(GameCulture.German, "Beispielblock");
Tooltip.AddTranslation(GameCulture.German, "Dies ist ein modded Block");
DisplayName.AddTranslation(GameCulture.Italian, "Blocco di esempio");
Tooltip.AddTranslation(GameCulture.Italian, "Questo è un blocco moddato");
DisplayName.AddTranslation(GameCulture.French, "Bloc d'exemple");
Tooltip.AddTranslation(GameCulture.French, "C'est un bloc modgé");
DisplayName.AddTranslation(GameCulture.Spanish, "Bloque de ejemplo");
Tooltip.AddTranslation(GameCulture.Spanish, "Este es un bloque modded");
DisplayName.AddTranslation(GameCulture.Russian, "Блок примера");
Tooltip.AddTranslation(GameCulture.Russian, "Это модифицированный блок");
DisplayName.AddTranslation(GameCulture.Chinese, "例子块");
Tooltip.AddTranslation(GameCulture.Chinese, "这是一个修改块");
DisplayName.AddTranslation(GameCulture.Portuguese, "Bloco de exemplo");
Tooltip.AddTranslation(GameCulture.Portuguese, "Este é um bloco modded");
DisplayName.AddTranslation(GameCulture.Polish, "Przykładowy blok");
Tooltip.AddTranslation(GameCulture.Polish, "Jest to modded blok");
}

public override void SetDefaults()
{
item.width = 12;
item.height = 12;
item.maxStack = 999;
item.useTurn = true;
item.autoReuse = true;
item.useAnimation = 15;
item.useTime = 10;
item.useStyle = 1;
item.consumable = true;
item.createTile = mod.TileType("Shadowstonetile");
}
}
}

Anyone know whats going on
 
hey @jopojelly
u said i need to put the code in setdefaults, well. IT STILL WONT WORK
pls help ._.
Code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ModLoader;

namespace SacredTools.Tiles
{
    public class OblivionOreBlock : ModTile
    {
        public override void SetDefaults()
        {
            Main.tileSolid[Type] = true;
            Main.tileMergeDirt[Type] = true;
            Main.tileBlockLight[Type] = true;  //true for block to emit light
            Main.tileLighted[Type] = true;
            drop = mod.ItemType("OblivionOre");   //put your CustomBlock name
            AddMapEntry(new Color(181, 53, 212));
            public float mineResist = 225f;
   
            public int dustType = mod.DustType("ShadowDust");
   
            public int minPick = 225;
   
            public int soundType = 0;
   
            public int soundStyle = 2;
   
            public override int SaplingGrowthType(ref int style)
            {
                style = 0;
                return mod.TileType("FlameSapling");
            }
         
        }
     
     
     
     
     
     
     
   
        public override void ModifyLight(int i, int j, ref float r, ref float g, ref float b)   //light colors
        {
            r = 1.81f;
            g = 0.53f;
            b = 2.12f;
        }
    }
}

EDIT: i think i got it now, changed a bit of the code...
what did you do? im having same problem
 
2/1/2019 8:53:46 PM
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'Texture2D'.
at Microsoft.Xna.Framework.Helpers.CheckDisposed(Object obj, IntPtr pComPtr)
at Microsoft.Xna.Framework.Graphics.TextureCollection.set_Item(Int32 index, Texture value)
at Microsoft.Xna.Framework.Graphics.SpriteBatch.RenderBatch(Texture2D texture, SpriteInfo[] sprites, Int32 offset, Int32 count)
at Microsoft.Xna.Framework.Graphics.SpriteBatch.Flush()
at Microsoft.Xna.Framework.Graphics.SpriteBatch.End()
at Terraria.Main.do_Draw(GameTime gameTime)
at Terraria.Main.DoDraw(GameTime gameTime)
at Terraria.Main.Draw(GameTime gameTime)
at Microsoft.Xna.Framework.Game.DrawFrame()
at Microsoft.Xna.Framework.Game.Tick()
at Microsoft.Xna.Framework.Game.HostIdle(Object sender, EventArgs e)
at Microsoft.Xna.Framework.GameHost.OnIdle()
at Microsoft.Xna.Framework.WindowsGameHost.RunOneFrame()
at Microsoft.Xna.Framework.WindowsGameHost.ApplicationIdle(Object sender, EventArgs e)
at System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FDoIdle(Int32 grfidlef)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at Microsoft.Xna.Framework.WindowsGameHost.Run()
at Microsoft.Xna.Framework.Game.RunGame(Boolean useBlockingRun)
at Terraria.Program.LaunchGame(String[] args, Boolean monoArgs)

What does this mean because after the re-logic image thing goes away my game crashes with this message.
 
Final Question, how can I make a ModItem drop from the moon lord?
Is that item placeable?
[doublepost=1549306876,1549306825][/doublepost]
Im confused because I've sat here trying to figure out what went wrong when i opened up terraria and got this message https://imgur.com/8rkgXvO
Delete Config.json in my games/Terraria or in my games/Terraria/Modloader.
[doublepost=1549307456][/doublepost]
I put this error in its own thread, but it can't hurt to ask here.
This has happened on three worlds so far. After defeating the cultist, every time I open the settings menu, the game crashes. Another issue is that monsters do not display their name and hp when hovered over. This is a very annoying bug, and I would very much appreciate help with it.
Mod list:
Calamity
Thorium
Sacred Tools
Qwerty's bosses and items
Initiate Mod
Intrucial
Fargo's
IMK sushi
IMK sushi old recipies
Magic Storage
Omniswing
Luiafk
Shorter Respawn
AlchemistNPC
VeinMiner
Wing Slot

System Specs
OS: linux mint 19
RAM 8gb

I know it's quite old but try and delete Config.json and see if it works.
 
Can i have some help please? I need help with two things: a boulder trap (with infinite uses) and a mine trap, they each need help on at least one thing about them, mine trap: i need to make it remove itself WITHOUT dropping a item, boulder trap (edited because i fixed one issue, and found another, fixed it, and found a few more): i need it to have a delay and place able on any side of any block (without being place able midair), the block can also be placed on in the end, and the top and sides have collision (not the inside or the bottom), here is my code:
mine trap:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.DataStructures;
using Terraria.ObjectData;
namespace XtraTraps.Tiles
{
public class MineTrap : ModTile
{
public override void SetDefaults()
{
Main.tileSolid[Type] = false;
Main.tileMergeDirt[Type] = false;
Main.tileBlockLight[Type] = false;
Main.tileLighted[Type] = true;
dustType = mod.DustType("Sparkle");
drop = mod.ItemType("MineTrap");
AddMapEntry(new Color(200, 200, 200));
}
public override bool Dangersense(int i, int j, Player player)
{
return true;
}
public override void HitWire(int i, int j)
{
Projectile.NewProjectile((i + 0.5f) * 16f, (j + 0.5f) * 16f, 0f, 0f, mod.ProjectileType("MineExplode"), 70, 10f, Main.myPlayer, 0f, 0f);
WorldGen.KillTile(i, j);
}
}
}






boulder trap:
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.DataStructures;
using Terraria.Enums;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.ObjectData;
namespace XtraTraps.Tiles
{
// This example shows how to have a tile that is cut by weapons, like vines and grass.
// This example also shows how to spawn a projectile on death like Beehive and Boulder trap.
class BoulderTrapTile : ModTile
{
public override void SetDefaults()
{
Main.tileFrameImportant[Type] = true;
TileObjectData.newTile.CopyFrom(TileObjectData.Style2x2);
// We need to change the 3x3 default to allow only placement anchored to top rather than on bottom. Also, the 1,1 means that only the middle tile needs to attach
TileObjectData.newTile.AnchorTop = new AnchorData(AnchorType.SolidTile | AnchorType.SolidSide,0,1);
TileObjectData.newTile.AnchorBottom = new AnchorData(AnchorType.SolidTile | AnchorType.SolidSide,0,1);
TileObjectData.newTile.AnchorLeft = new AnchorData(AnchorType.SolidTile | AnchorType.SolidSide,0,1);
TileObjectData.newTile.AnchorRight = new AnchorData(AnchorType.SolidTile | AnchorType.SolidSide,0,1);
// This is so we can place from above.
TileObjectData.newTile.Origin = new Point16(0, 0);
TileObjectData.addTile(Type);
}
public override bool Dangersense(int i, int j, Player player)
{
return true;
}
public override bool CreateDust(int i, int j, ref int type)
{
return false;
}
public override void HitWire(int i, int j)
{
int y = j - (Main.tile[i, j].frameY / 18);
int x = i - (Main.tile[i, j].frameX / 18);
Projectile.NewProjectile((x + 1f) * 16f, (y + 1f) * 16f, 0f, 0f, ProjectileID.Boulder, 70, 10f, Main.myPlayer, 0f, 0f);
}
public override void KillMultiTile(int i, int j, int frameX, int frameY)
{
Item.NewItem(i * 16, j * 16, 16, 32, mod.ItemType("BoulderTrapItem"));
}
}
class BoulderTrapItem : ModItem
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Boulder Trap");
}
public override void SetDefaults()
{
item.CloneDefaults(ItemID.DartTrap);
item.createTile = mod.TileType("BoulderTrapTile");
item.value = 1000;
}
public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.DirtBlock, 1);
recipe.SetResult(this);
recipe.AddRecipe();
}
}
}


(edit #1)
The dirt blocks for the recipes are temporary, so i can test them easier


(edit #2)
i also have a fireball trap, does anyone know what the ID of the fire flower fireball is, because that is the fire i want it to launch


(edit #3)
also, can you tell me how to make hammering a block change the block type? I dont want sloped blocks in my mod, and i also need to know how to make a block appear different depending on what it is placed on (if there is a background wall, use texture one, left, texture 2, top, texture 3, etc)
 
Last edited:
Hey guys, I'm trying to load Thorium from a separate mod so I can use an accessory in the second mod to boost Thorium's damage types. I'm trying the following to get the mod to load in the item's CS file:

Mod thoriumMod = ModLoader.GetMod("ThoriumMod");
ModPlayer thoriumPlayer = player.GetModPlayer<ThoriumMod.ThoriumPlayer>();
thoriumPlayer.radiantBoost += radiantDMGBonus;


However, when I make this change to the item's file and try to compile, it gives me "the type or namespace 'ThoriumMod' could not be found". I'm not that good at coding C#, but from what I understand it's saying that ModLoader.GetMod is not loading the mod's name properly. Is there anything else I need to do somewhere else in the project to avoid this error and have my code load up Thorium's modplayer?
 
Hey guys, I'm trying to load Thorium from a separate mod so I can use an accessory in the second mod to boost Thorium's damage types. I'm trying the following to get the mod to load in the item's CS file:

Mod thoriumMod = ModLoader.GetMod("ThoriumMod");
ModPlayer thoriumPlayer = player.GetModPlayer<ThoriumMod.ThoriumPlayer>();
thoriumPlayer.radiantBoost += radiantDMGBonus;


However, when I make this change to the item's file and try to compile, it gives me "the type or namespace 'ThoriumMod' could not be found". I'm not that good at coding C#, but from what I understand it's saying that ModLoader.GetMod is not loading the mod's name properly. Is there anything else I need to do somewhere else in the project to avoid this error and have my code load up Thorium's modplayer?
Yes, read this https://github.com/blushiemagic/tModLoader/wiki/Expert-Cross-Mod-Content
 
i have done programming before in a language similar to java, thus it is being easy to learn this fast, i still don't know how to fix my issues above, any help would be appreciated (i usually spell a lot of words right, forgot how to spell the last word, so i used spellcheck, hoped i got it right)!
 
@Andrew87Sky, i want the item to drop, also, i found the fire flower projectile, i wanted the item to not place if there were not anchor blocks touching the multi-tile when placed, but thank you for trying.
@jopojelly, i quit discord for good 2 months ago, so i cant post my problem, i did it because, reasons.
[doublepost=1549513450,1549513379][/doublepost]and i am fine with waiting a bit, i got help on one of my other issues with another game, after 2 weeks passed after i asked, so i can wait patiently for a while.
[doublepost=1549513581][/doublepost]btw, if you reply in the next 12 hours, i wont see it til the internet black out in my home passes, my internet only works for 12 hours a day...
 
I really like TModLoader and all, and it's fun to play with mods, but I was wondering…
Is there a way to have TModLoader Terraria separate from vanilla Terraria? Like, I could boot up either one individually without having to remove TModLoader?
 
Back
Top Bottom