question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

API restructuring (Terraria.ModLoader namespace)

See original GitHub issue

The core ModLoader namespace has always suffered from scope creep and bloating. Some classes have been moved to the Core and Engine namespaces, but there’s currently no bookkeeping thread for the class list and naming conventions. First we’ll categorise all classes in this namespace, then we’ll provide refactoring/restructuring suggestions. Most of this will likely not happen till 1.4 for compatibility but we should be prepared with our designs.

Content Classes

These classes correspond to Terraria game objects, and need to be tracked by tML with data and hooks. Instantiated at load time.

Content Global Loader Extra
Mod ModLoader ModProperties, ModSide
ModBackgroundStyle GlobalBackgroundStyle BackgroundStyleLoaders
BackgroundTextureLoader
ModBuff GlobalBuff BuffLoader
ModCommand CommandLoader
ModDust DustLoader
EquipTexture EquipLoader EquipType, AutoloadEquip
ModGore GoreLoader
ModKeybind KeybindLoader
ModItem GlobalItem ItemLoader
MapEntry MapLoader MapLegend
ModMount MountLoader MountTextureType
ModNPC GlobalNPC NPCLoader NPCSpawnInfo
NPCHeadLoader AutoloadHead
ModPlayer PlayerLoader
ModPrefix PrefixLoader
ModProjectile GlobalProjectile ProjectileLoader
ModRecipe GlobalRecipe RecipeLoader
ModSound SoundLoader SoundType
ModTile GlobalTile TileLoader
ModTileEntity missing
ModTranslation LocalizationLoader
ModWall GlobalWall WallLoader
ModWaterStyle WaterStyleLoader
ModSystem SystemLoader
ModTree/ ModPalmTree/ ModCactus > TileLoader
PlayerDrawLayer PlayerDrawLayerLoader

Utility Classes

Public classes which are used by mods to interact with hooks or perform common functions. Instantiated during gameplay. Classified as either hooks or helpers.

Class Designation
DrawableTooltipLine Hook
DrawInfo Hook
DrawLayer Hook
ModPacket Hook
NPCSpawnHelper Helper
RecipeGroupHelper Helper
MusicPriority Hook
TooltipLine Hook

ModLoader Core Classes

Core mod content management classes, with public functions mods are expected to use.

Class
CombinedHooks
ErrorLogger (Deprecated)
FrameworkVersion
Logging
ModContent
ModNet
MonoModHooks
TopoSort
MusicWrappers

Proposed Refactors

  • ~ModProperties -> AutoloadProperties~ removed
  • Move helper utilities to “Helper” or “Utilities” sub-namespace
  • ~Check ModUgBgStyle/ModSurfaceBgStyle for common code~ unified via ModBackgroundStyle
  • ModMountData -> ModMount
  • Loader vs Hooks naming. Currently roughly LoaderX if GlobalX exists, otherwise HookX. Should we keep this, and fix the non-conformers, or just pick one and stick to it.
  • Missing loader classes. Should all static bookkeeping be done in a separate Loader/Hook class? Most of the missing loader classes just weren’t made because there weren’t enough hooks required, or just a single id array/dictionary.
  • Mod Translation loader, the autoloader is currently in ModInternals, and ModContent handles all the Translation -> LocalizedText updates, should we split this out?
  • Pretty much every content class has common fields Mod mod; string name;. Make a parent class for all tracked mod content.
  • Move all autoloading code out of Mod, or at least to partial class with more shared code between functions
  • Merge a lot of the Mod.AddX common code, and move the other parts to the loader classes]

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
JavidPackcommented, May 25, 2020

I want to make sure we throw an error in XType and GetX, rather than return 0 or null. A TryGetX or something would be needed.

Returning 0 isn’t usually an issue, but it’s a little weird.

0reactions
Chicken-Bonescommented, Jan 5, 2022

This is mostly done. Closing. Remaining issues #1347, #1506

Read more comments on GitHub >

github_iconTop Results From Across the Web

Standalone - [1.3] tModLoader - A Modding API | Page 178
So, for ExampleMod, you can restructure the Weapon folder by moving the files in that folder down to the Item folder, then change...
Read more >
Modding Namespace? : r/Terraria
Im confused on the errors im getting right now. Im trying to make a yoyo but the projectile folder isnt working.
Read more >
Custom Tmodloader Accesory Not Working : r/Terraria
Currently working on making a mining accessory that combines the use of the vanilla item "Ancient chisel" with the 2 calamity mod items ......
Read more >
c# - tModLoader issues with compiling
So I am making my own Terraria Mod but I have one problem which is that when I use one the the items...
Read more >
I need Help with a mod im trying to make :: Terraria ...
That namespace is where tModLoader is looking for the item's sprite. From what I can tell, your namespace is Items. It should be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found