tModLoader Error CS0120 (1.4) - Fixed

RADICALAdrift

Official Terrarian
Hi There,

Im getting this as 1 of many errors trying to convert my mod to TModloader 1.4

C#:
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Microsoft.Xna.Framework;
using OPDefense.Items.Placeable;
 
namespace OPDefense.Tiles
{
    public class CraytaniumOreTile : ModTile
    {
        public void SetDefaults() //Dont know if if it should be public override void SetDefaults() or public void SetDefaults()
        {
            Main.tileSolid[Type] = true;
            Main.tileMergeDirt[Type] = true;
            Main.tileSpelunker[Type] = true;
            Main.tileShine[Type] = 800;
            Main.tileShine2[Type] = true;
            Main.tileBlockLight[Type] = false;
            Main.tileLighted[Type] = true;
            ModTile.ItemDrop = ("CraytaniumOre"); //This Line is what is giving me the error
            soundType = SoundID.Tink;
            soundStyle = 1;
            dustType == "84"; //This probably should be = not == but what do i know, Originally 1 = (lol)
        }
        public void SetStaticDefaults() //Dont know if if it should be public override void SetStaticDefaults() or public void SetStaticDefaults()
        {
            ModTranslation name = CreateMapEntryName();
            name.SetDefault("Craytanium Ore");
            AddMapEntry(new Color(198, 33, 101), name);
        }
        public override void ModifyLight(int i, int j, ref float r, ref float g, ref float b)
        {
            r = 0.198f;
            g = 0.033f;
            b = 0.101f;
        }
    }
}
20220418044808_11.jpg


I have a basic understanding of C# (very basic but enough to do what i need) anyway can someone explain what error is trying to tell me & what i need to change in my code
Thanks In Advance

Regards,
RADICALAdrift
 
Last edited:
You should put everything in SetDefaults() into SetStaticDefaults() and you should override SetStaticDefaults().

soundType, soundStyle, and dustType need to be capitalized as SoundType, SoundStyle, and DustType.

DustType should be = and no quotes around the number. A single = is the assignment operator and double == is compare operator. Aka "x = y" means "x is now equal to y" and "x == y" is "is x is the same as y?". Quotes around the number implies that it is a string and not an integer like it should.

This isn't required, but I would change the 84 to DustID.Platinum. It makes it easier to read and know what it is just by looking at the code. You can change the DustID to anything you want. Here is a wiki page I made with all of the DustIDs: User:Rijam/Dust IDs (tModLoader) - The Official Terraria Wiki

Remove the ModTile from ModTile.ItemDrop.

Your ItemDrop code is not valid. It should be ModContent.ItemType<CraytaniumOre>(). NOTE: It will actually be ModContent.ItemType<Namespace.MyItemClass>() with the namespace being the file path that the item is located and MyItemClass being the class name of the item. However, since you already specified using OPDefense.Items.Placeable; at the top, you do not need to specify the namespace here.


Take a look at ExampleOre: tModLoader/ExampleOre.cs at 1.4 · tModLoader/tModLoader

I also highly recommend using Visual Studios. It will tell you what is wrong before you try to build in game and it will offer suggestions for fixes. Developing with Visual Studio · tModLoader/tModLoader Wiki

P.S. Thank you for putting your code in a code block. It makes it so much easier to read.
 
You should put everything in SetDefaults() into SetStaticDefaults() and you should override SetStaticDefaults().

soundType, soundStyle, and dustType need to be capitalized as SoundType, SoundStyle, and DustType.

DustType should be = and no quotes around the number. A single = is the assignment operator and double == is compare operator. Aka "x = y" means "x is now equal to y" and "x == y" is "is x is the same as y?". Quotes around the number implies that it is a string and not an integer like it should.

This isn't required, but I would change the 84 to DustID.Platinum. It makes it easier to read and know what it is just by looking at the code. You can change the DustID to anything you want. Here is a wiki page I made with all of the DustIDs: User:Rijam/Dust IDs (tModLoader) - The Official Terraria Wiki

Remove the ModTile from ModTile.ItemDrop.

Your ItemDrop code is not valid. It should be ModContent.ItemType<CraytaniumOre>(). NOTE: It will actually be ModContent.ItemType<Namespace.MyItemClass>() with the namespace being the file path that the item is located and MyItemClass being the class name of the item. However, since you already specified using OPDefense.Items.Placeable; at the top, you do not need to specify the namespace here.


Take a look at ExampleOre: tModLoader/ExampleOre.cs at 1.4 · tModLoader/tModLoader

I also highly recommend using Visual Studios. It will tell you what is wrong before you try to build in game and it will offer suggestions for fixes. Developing with Visual Studio · tModLoader/tModLoader Wiki

P.S. Thank you for putting your code in a code block. It makes it so much easier to read.
Hey No Problem and thanks for the DustID link, i'm already using Visual Studio 2019 with the C# code section installed
 
I would guess it would help if i did that with every file in my mod
You should put everything in SetDefaults() into SetStaticDefaults() and you should override SetStaticDefaults().
Which would be to move everything in SetDefaults() into SetStaticDefaults() just like ive now done in the code in question
 
Hey No Problem and thanks for the DustID link, i'm already using Visual Studio 2019 with the C# code section installed
Make sure you are opening your mod's csproj instead of the individual files. Error checking and such won't work if you don't open the csproj.
 
Make sure you are opening your mod's csproj instead of the individual files. Error checking and such won't work if you don't open the csproj.
I'm opening my mod's csproj file as im opening from the in-game mod sources menu however it seems to use MVS2019 and not MVS2022 (which seems to be recommended for TML 1.4 modding)
 
Back
Top Bottom