Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[1.7.10] Is it possible to compile and load classes during mod initialization?

Featured Replies

Posted

I was wondering if I can use the compiler API to compile one of my mod's classes during one of the initialization events (pre, init, post) and then tell the class loader to load that class as one of my mod's.

WIP mods: easyautomation, easyenergy, easyelectronics, easymoney, easytrasportation, easysecurity, easymultiverse, easyfactions, easymagick, easyalchemy, easyseasons

  • Author

cool :). It would be harder and more vulnerable to erros to dynamically write the whole class via asm. it's possible, just not an approach I wish to take if I have a choice. Is there a way to add the compiler as a dependency (an external jar)? and if yes, will it take up memory after I'm done with it?

WIP mods: easyautomation, easyenergy, easyelectronics, easymoney, easytrasportation, easysecurity, easymultiverse, easyfactions, easymagick, easyalchemy, easyseasons

  • Author

I need it because the host environment where I will run this mod has low performance and already has a lot of mods. I would create the class at runtime in an attempt to optimize it, creating only what is necessary and marking everything I can as final to allow JIT optimizations. this may sound as pre-optimization, but it really isn't. the server is already having a bad performance. I have to do anything I can to maybe avoid making it worse.

WIP mods: easyautomation, easyenergy, easyelectronics, easymoney, easytrasportation, easysecurity, easymultiverse, easyfactions, easymagick, easyalchemy, easyseasons

  • Author

the class that holds my mod's items. My mod adds a lot of item sets (armor, trinkets (currently rings and necklace from baubles. I plan to write my own custom inventory to optimize trinkets later) and weapons (either swords or bows). every tool/armor material can be customized by the user via config file, every potion effect given by wearing the set. but because of this customizations, a lot of stuff can't be

final

, otherwise it would have to be hardcoded instead. I feel the JIT would do a better job if I was able to dynamically define that class. I'm also avoiding static stuff that I will need only during initialization, to allow the GC to be able to dispose of things as soon as they are out of scope.

WIP mods: easyautomation, easyenergy, easyelectronics, easymoney, easytrasportation, easysecurity, easymultiverse, easyfactions, easymagick, easyalchemy, easyseasons

  • Author

the fields are static. each field is only set once during preInit. The JIT probably can't optimize the fields because they are static and are not set during type construction. But it's ok. I'm just trying hard to squeeze every bit of performace optimization I can, because the server is already too slow as it is. It was a lot better when I ran Cauldron instead of pure Forge, but I couldn't make my event handling code work properly for Cauldron. Anyway, thanks for the code example, that may come in handy some other time.

WIP mods: easyautomation, easyenergy, easyelectronics, easymoney, easytrasportation, easysecurity, easymultiverse, easyfactions, easymagick, easyalchemy, easyseasons

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.