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.

Featured Replies

Posted

@Instance("ModID")

public static ClassName instance;

How does this work? I understand it makes an Instance from which MinecraftForge can work from, but how does it achieve this?

Also, what's the difference between the aformentioned code and this:

@Instance

public static ClassName instance = new ClassName();

 

Do they both achieve the same thing?

 

The Instance annotation sets the field to the specific instance of your mod that Forge is using internally via reflection. You shouldn't instantiate your mod class yourself, the one you've instantiated won't be the one Forge uses.

Don't make mods if you don't know Java.

Check out my website: http://shadowfacts.net

Developer of many mods

  • Author

@Instance("ModID")

public static ClassName instance;

How does this instantiate anything though?

@Instance("ModID") so here I pass along the ModID as a string to this annotation...

public static ClassName instance; how does this line set the field to the instance of my mod? is the word instance here connected to the annotation @Instance?

 

@Instance

public static ClassName instance = new ClassName();

Why does this one still work?

@Instance why is there no ModID being passed along here?

public static ClassName instance = new ClassName(); doesn't this make more sense as it is creating a New instance? Is it this one you said won't be the one forge uses?

FML will construct any @Mod it finds.

It will also apply any @Instance it finds.

If it finds a @Instance with no modid inside a class with a @Mod it will assume that it wants its own instance.

 

Calling new ClassName() yourself creates a extra instance of your class that is never used because that field would be instantly replaced by FML to the instance that FML created.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

@Instance("ModID")

public static ClassName instance;

How does this instantiate anything though?

@Instance("ModID") so here I pass along the ModID as a string to this annotation...

public static ClassName instance; how does this line set the field to the instance of my mod? is the word instance here connected to the annotation @Instance?

 

FML scans for all Instance annotations and uses reflection to populate the field with the instance of your mod being used internally. No, the field name is not connected.

 

@Instance

public static ClassName instance = new ClassName();

Why does this one still work?

@Instance why is there no ModID being passed along here?

public static ClassName instance = new ClassName(); doesn't this make more sense as it is creating a New instance? Is it this one you said won't be the one forge uses?

 

You still need to pass in the mod id to the annotation.

 

Yes, the only correct instance of your mod is the one created by Forge, not one you yourself instantiate.

Don't make mods if you don't know Java.

Check out my website: http://shadowfacts.net

Developer of many mods

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.