Jump to content

Recommended Posts

Posted

Hey,

 

My TF2 Teleporter, Sentry and Dispenser are done, and I'm on the TeamAddon now.

I use this addon to change fields in the other mod-classes, it worked fine with 1.2.5.

But if I'm using this code:

 

@PostInit
public void modsLoaded(FMLPostInitializationEvent evt)
{
	updateMods();
}

private static void updateMods()
{
	List<ModContainer> mods = Loader.instance().getActiveModList();
	try
	{

		for(ModContainer mod : mods){
			if(mod.getMod() instanceof TF2.Sentry.common.TF2SentryMod){
				TF2.Sentry.common.TF2SentryMod.teamsEnabled = teamsEnabled;
			}else if(mod.getMod() instanceof TF2.Dispenser.common.TF2DispenserMod){
				TF2.Dispenser.common.TF2DispenserMod.teamsEnabled = teamsEnabled;
			}else if(mod.getMod() instanceof TF2.Teleporter.common.TF2TeleporterMod){
				TF2.Teleporter.common.TF2TeleporterMod.teamsEnabled = teamsEnabled;
			}
		}

	}catch (Exception e){

	}

}

 

I get that error everytime, if I start minecraft without telporter and so on:

 

 

  Reveal hidden contents

 

 

In generall catching an Exception would work, but I still get this LoaderException :/

Any ideas how I can get rid of that problem?

Posted

Doing instanceof of is a really really bad thing you're making a hard dependancy on the other mods.

What you *should* be doing is checking if the class name equals a string, or something to that effect.

 

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

Posted

It's working now, thx!

 

	@PostInit
public void modsLoaded(FMLPostInitializationEvent evt)
{
	updateMods();
}

private static void updateMods()
{
	try
	{

		for(ModContainer mod : Loader.instance().getModList()){
			if(mod.getMod() == null){
				continue;
			}
			Class<?> c = mod.getMod().getClass();
			String s = c.toString();
			if(s.equals("class TF2.Sentry.common.TF2SentryMod")){
				c.getDeclaredField("teamsEnabled").setBoolean(null, true);
			}else if(s.equals("class TF2.Dispenser.common.TF2DispenserMod")){
				c.getDeclaredField("teamsEnabled").setBoolean(null, true);
			}else if(s.equals("class TF2.Teleporter.common.TF2TeleporterMod")){
				c.getDeclaredField("teamsEnabled").setBoolean(null, true);
			}
		}

	}catch (Exception e){
		e.printStackTrace();
	}

}

Posted

you should prolly use c.getName() for more consistent results. toString is platform dependent IIRC.

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

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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