Skip to content

[upcoming] 6. Upgrading from v2

Luke edited this page Jul 14, 2021 · 15 revisions

Even though OTAPI3 is a complete re-write, most of the hooks still exist in one form or another - they have either been rewritten or renamed to align better with Terraria conventions.

Hooks

The OTAPI.Hooks class still exists in OTAPI.dll, but is only provided for manual IL reworked hooks. OTAPI.Runtime.dll is used for most traditional before/after wrapped hooks and can be subscribed to at runtime without the need of pre-compilation or custom IL/wrapping.

Examples of TShock being ported from v2 to v3:

Additional files

OTAPI v2 was a single dll, this version has a few more dependencies such as ModFramework and MonoMod. If you are concerned about too many files, try and use the new single file publish tools available for you from .net5+ otherwise add some extra assembly resolve handlers and place the binaries in a sub folder.

Dependency on ModFramework is currently needed specifically for ICollection<>, which is used to replace Terraria.tile's Tile[] arrays to an abstract implementation. In addition, it is also used to load supplemental modules that can feed in extra modifications written in other languages.

This dependency is certainly something to discuss, and i'm happy for you to lodge an issue or a discussion topic to talk why this wont work for your project.

Cross plugin support

ModFrameworks plugin system is active in all projects that use OTAPI no matter the type or variant. This means you can carefully write a cross platform plugin and have it be compatible on clients, pc server, mobile server & tModLoader servers. Further more plugins can now be written in various languages and have full access to .NET & Terraria using the ModFramework modules.

Porting ITile

For the end user building a host or plugin, ITile is basically the same, to the T even..or at least an upside down L since instead of living in OTAPI's namespace it now resides back in Terraria beside the original implementation.

This is because unlike v2 which hardcoded ITile, it is now 100% generated from Terraria.Tile and it feels more natural for it to be here.
Don't worry though! If this is a massive problem I don't see a problem in changing the namespace back, or we probably can come up with some sort of redirection fix.

Examples of new tooling: