Jump to content

[given up]How do I make my mod gracefully fail to load?


leftler

Recommended Posts

There are some environment checks I need to perform to check for mod incompatibilities. If those incompatibilities are found I want to move my mod to the "ModState.LoadedState.ERRORED" state.

 

	@PostInit
public void postInit(FMLPostInitializationEvent event)
{
	//if(Tessellator.instance instanceof GhostingTessellator == false) //comment out for testing
	{
		Exception ex = new LoaderException();
		FMLLog.log(Level.SEVERE, ex, "The custom tessellator for Project Builder has been replaced by another mod. The mod will not work without it.");
		FMLCommonHandler.instance().raiseException(ex, "The custom tessellator for Project Builder has been replaced. The mod will not work without it.", false);
	}
}

 

If I set "stopGame" to "true" or just do a simple "throw ex;" instead of calling FMLCommonHandler it stops the entire game from launching, which I do not want. (Also changing the exception from "LoaderExecption" to "Exception" or "Throwable" gives the same results)

 

If I set "stopGame" to "false" I can see my warning in the console log when it launches (so I know the code is executing) but the mod still shows "Mod State: Available" in the list of mods GUI. and the main menu shows "3 mods loaded, 3 mods active"

 

This is with build 4.0.0.204.

 

Here is the console output with "stopGame" set to "false"

 

2012-08-19 23:57:34 [iNFO] [ForgeModLoader] Forge Mod Loader version 3.0.80.291 for Minecraft client:1.3.2, server:1.3.2 loading

2012-08-19 23:57:37 [iNFO] [sTDOUT] 27 achievements

2012-08-19 23:57:38 [iNFO] [sTDOUT] 195 recipes

2012-08-19 23:57:38 [iNFO] [sTDOUT] Setting user: Player953, -

2012-08-19 23:57:38 [iNFO] [sTDERR] Client asked for parameter: server

2012-08-19 23:57:38 [iNFO] [sTDOUT] LWJGL Version: 2.4.2

2012-08-19 23:57:40 [iNFO] [ForgeModLoader] Attempting early MinecraftForge initialization

2012-08-19 23:57:40 [iNFO] [ForgeModLoader] Completed early MinecraftForge initialization

2012-08-19 23:57:40 [iNFO] [ForgeModLoader] Searching C:\Users\Scott\Desktop\mcp72\jars\mods for mods

2012-08-19 23:57:40 [iNFO] [ForgeModLoader] No mcmod.info file found in directory bin

2012-08-19 23:57:41 [iNFO] [ForgeModLoader] The mod container minecraft.jar appears to be missing an mcmod.info file

2012-08-19 23:57:42 [iNFO] [ForgeModLoader] Forge Mod Loader has identified 3 mods to load

2012-08-19 23:57:43 [iNFO] [sTDOUT] Starting up SoundSystem...

2012-08-19 23:57:43 [iNFO] [sTDOUT] Initializing LWJGL OpenAL

2012-08-19 23:57:43 [iNFO] [sTDOUT]    (The LWJGL binding of OpenAL.  For more information, see http://www.lwjgl.org)

2012-08-19 23:57:44 [iNFO] [sTDOUT] OpenAL initialized.

2012-08-19 23:57:45 [sEVERE] [ForgeModLoader] The custom tessellator for Project Builder has been replaced. The mod will not work without it.

2012-08-19 23:57:45 [iNFO] [ForgeModLoader] Forge Mod Loader has successfully loaded 3 mods

 

 

 

Here is the console output when using "throw ex;"

 

2012-08-20 00:01:17 [iNFO] [ForgeModLoader] Forge Mod Loader version 3.0.80.291 for Minecraft client:1.3.2, server:1.3.2 loading

2012-08-20 00:01:21 [iNFO] [sTDOUT] 27 achievements

2012-08-20 00:01:21 [iNFO] [sTDOUT] 195 recipes

2012-08-20 00:01:21 [iNFO] [sTDOUT] Setting user: Player523, -

2012-08-20 00:01:21 [iNFO] [sTDERR] Client asked for parameter: server

2012-08-20 00:01:21 [iNFO] [sTDOUT] LWJGL Version: 2.4.2

2012-08-20 00:01:23 [iNFO] [ForgeModLoader] Attempting early MinecraftForge initialization

2012-08-20 00:01:23 [iNFO] [ForgeModLoader] Completed early MinecraftForge initialization

2012-08-20 00:01:23 [iNFO] [ForgeModLoader] Searching C:\Users\Scott\Desktop\mcp72\jars\mods for mods

2012-08-20 00:01:23 [iNFO] [ForgeModLoader] No mcmod.info file found in directory bin

2012-08-20 00:01:24 [iNFO] [ForgeModLoader] The mod container minecraft.jar appears to be missing an mcmod.info file

2012-08-20 00:01:24 [iNFO] [ForgeModLoader] Forge Mod Loader has identified 3 mods to load

2012-08-20 00:01:26 [iNFO] [sTDOUT] Starting up SoundSystem...

2012-08-20 00:01:26 [iNFO] [sTDOUT] Initializing LWJGL OpenAL

2012-08-20 00:01:26 [iNFO] [sTDOUT]    (The LWJGL binding of OpenAL.  For more information, see http://www.lwjgl.org)

2012-08-20 00:01:26 [iNFO] [sTDOUT] OpenAL initialized.

2012-08-20 00:01:27 [sEVERE] [ForgeModLoader] The custom tessellator for Project Builder has been replaced. The mod will not work without it.

2012-08-20 00:01:27 [sEVERE] [ForgeModLoader] Fatal errors were detected during the transition from POSTINITIALIZATION to AVAILABLE. Loading cannot continue

2012-08-20 00:01:27 [sEVERE] [ForgeModLoader]

Forge Mod Loader (coremods) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized

Minecraft Forge (coremods) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized

Project Builder (bin) Unloaded->Constructed->Pre-initialized->Initialized->Errored

2012-08-20 00:01:27 [sEVERE] [ForgeModLoader] The following problems were captured during this phase

2012-08-20 00:01:27 [sEVERE] [ForgeModLoader] Caught exception from projectbuilder

2012-08-20 00:01:37 [iNFO] [sTDERR] cpw.mods.fml.common.LoaderException: java.lang.reflect.InvocationTargetException

2012-08-20 00:01:37 [iNFO] [sTDERR] at cpw.mods.fml.common.LoadController.transition(LoadController.java:102)

2012-08-20 00:01:37 [iNFO] [sTDERR] at cpw.mods.fml.common.Loader.initializeMods(Loader.java:593)

2012-08-20 00:01:37 [iNFO] [sTDERR] at cpw.mods.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:158)

2012-08-20 00:01:37 [iNFO] [sTDERR] at net.minecraft.client.Minecraft.startGame(Minecraft.java:447)

2012-08-20 00:01:37 [iNFO] [sTDERR] at net.minecraft.client.Minecraft.run(Minecraft.java:734)

2012-08-20 00:01:37 [iNFO] [sTDERR] at java.lang.Thread.run(Unknown Source)

2012-08-20 00:01:37 [iNFO] [sTDERR] Caused by: java.lang.reflect.InvocationTargetException

2012-08-20 00:01:37 [iNFO] [sTDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

2012-08-20 00:01:37 [iNFO] [sTDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

2012-08-20 00:01:37 [iNFO] [sTDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

2012-08-20 00:01:37 [iNFO] [sTDERR] at java.lang.reflect.Method.invoke(Unknown Source)

2012-08-20 00:01:37 [iNFO] [sTDERR] at cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:297)

2012-08-20 00:01:37 [iNFO] [sTDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

2012-08-20 00:01:37 [iNFO] [sTDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

2012-08-20 00:01:37 [iNFO] [sTDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

2012-08-20 00:01:37 [iNFO] [sTDERR] at java.lang.reflect.Method.invoke(Unknown Source)

2012-08-20 00:01:37 [iNFO] [sTDERR] at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:69)

2012-08-20 00:01:37 [iNFO] [sTDERR] at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45)

2012-08-20 00:01:37 [iNFO] [sTDERR] at com.google.common.eventbus.EventBus.dispatch(EventBus.java:317)

2012-08-20 00:01:37 [iNFO] [sTDERR] at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:300)

2012-08-20 00:01:37 [iNFO] [sTDERR] at com.google.common.eventbus.EventBus.post(EventBus.java:268)

2012-08-20 00:01:37 [iNFO] [sTDERR] at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:123)

2012-08-20 00:01:37 [iNFO] [sTDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

2012-08-20 00:01:37 [iNFO] [sTDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

2012-08-20 00:01:37 [iNFO] [sTDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

2012-08-20 00:01:37 [iNFO] [sTDERR] at java.lang.reflect.Method.invoke(Unknown Source)

2012-08-20 00:01:37 [iNFO] [sTDERR] at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:69)

2012-08-20 00:01:37 [iNFO] [sTDERR] at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45)

2012-08-20 00:01:37 [iNFO] [sTDERR] at com.google.common.eventbus.EventBus.dispatch(EventBus.java:317)

2012-08-20 00:01:37 [iNFO] [sTDERR] at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:300)

2012-08-20 00:01:37 [iNFO] [sTDERR] at com.google.common.eventbus.EventBus.post(EventBus.java:268)

2012-08-20 00:01:37 [iNFO] [sTDERR] at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:81)

2012-08-20 00:01:37 [iNFO] [sTDERR] at cpw.mods.fml.common.Loader.initializeMods(Loader.java:592)

2012-08-20 00:01:37 [iNFO] [sTDERR] ... 4 more

2012-08-20 00:01:37 [iNFO] [sTDERR] Caused by: cpw.mods.fml.common.LoaderException

2012-08-20 00:01:37 [iNFO] [sTDERR] at leftler.mods.projectbuilder.ProjectBuilder.postInit(ProjectBuilder.java:43)

2012-08-20 00:01:37 [iNFO] [sTDERR] ... 30 more

2012-08-20 00:01:37 [iNFO] [sTDERR] Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: component argument pData

2012-08-20 00:01:37 [iNFO] [sTDERR] at sun.java2d.windows.GDIWindowSurfaceData.initOps(Native Method)

2012-08-20 00:01:37 [iNFO] [sTDERR] at sun.java2d.windows.GDIWindowSurfaceData.<init>(Unknown Source)

2012-08-20 00:01:37 [iNFO] [sTDERR] at sun.java2d.windows.GDIWindowSurfaceData.createData(Unknown Source)

2012-08-20 00:01:37 [iNFO] [sTDERR] at sun.java2d.d3d.D3DScreenUpdateManager.getGdiSurface(Unknown Source)

2012-08-20 00:01:37 [iNFO] [sTDERR] at sun.java2d.d3d.D3DScreenUpdateManager.createGraphics(Unknown Source)

2012-08-20 00:01:37 [iNFO] [sTDERR] at sun.awt.windows.WComponentPeer.getGraphics(Unknown Source)

2012-08-20 00:01:37 [iNFO] [sTDERR] at java.awt.Component.getGraphics(Unknown Source)

2012-08-20 00:01:37 [iNFO] [sTDERR] at sun.awt.RepaintArea.paint(Unknown Source)

2012-08-20 00:01:37 [iNFO] [sTDERR] at sun.awt.windows.WComponentPeer.handleEvent(Unknown Source)

2012-08-20 00:01:37 [iNFO] [sTDERR] at java.awt.Component.dispatchEventImpl(Unknown Source)

2012-08-20 00:01:37 [iNFO] [sTDERR] at java.awt.Component.dispatchEvent(Unknown Source)

2012-08-20 00:01:37 [iNFO] [sTDERR] at java.awt.EventQueue.dispatchEventImpl(Unknown Source)

2012-08-20 00:01:37 [iNFO] [sTDERR] at java.awt.EventQueue.access$000(Unknown Source)

2012-08-20 00:01:37 [iNFO] [sTDERR] at java.awt.EventQueue$3.run(Unknown Source)

2012-08-20 00:01:37 [iNFO] [sTDERR] at java.awt.EventQueue$3.run(Unknown Source)

2012-08-20 00:01:37 [iNFO] [sTDERR] at java.security.AccessController.doPrivileged(Native Method)

2012-08-20 00:01:37 [iNFO] [sTDERR] at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)

2012-08-20 00:01:37 [iNFO] [sTDERR] at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)

2012-08-20 00:01:37 [iNFO] [sTDERR] at java.awt.EventQueue$4.run(Unknown Source)

2012-08-20 00:01:37 [iNFO] [sTDERR] at java.awt.EventQueue$4.run(Unknown Source)

2012-08-20 00:01:37 [iNFO] [sTDERR] at java.security.AccessController.doPrivileged(Native Method)

2012-08-20 00:01:37 [iNFO] [sTDERR] at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)

2012-08-20 00:01:37 [iNFO] [sTDERR] at java.awt.EventQueue.dispatchEvent(Unknown Source)

2012-08-20 00:01:37 [iNFO] [sTDERR] at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)

2012-08-20 00:01:37 [iNFO] [sTDERR] at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)

2012-08-20 00:01:37 [iNFO] [sTDERR] at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)

2012-08-20 00:01:37 [iNFO] [sTDERR] at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

2012-08-20 00:01:37 [iNFO] [sTDERR] at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

2012-08-20 00:01:37 [iNFO] [sTDERR] at java.awt.EventDispatchThread.run(Unknown Source)

 

 

And here is the crash report that was generated with the above crash.

 

---- Minecraft Crash Report ----

// I let you down. Sorry :(

 

Time: 8/20/12 12:01 AM

Description: Failed to start game

 

cpw.mods.fml.common.LoaderException: java.lang.reflect.InvocationTargetException

at cpw.mods.fml.common.LoadController.transition(LoadController.java:102)

at cpw.mods.fml.common.Loader.initializeMods(Loader.java:593)

at cpw.mods.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:158)

at net.minecraft.client.Minecraft.startGame(Minecraft.java:447)

at net.minecraft.client.Minecraft.run(Minecraft.java:734)

at java.lang.Thread.run(Unknown Source)

Caused by: java.lang.reflect.InvocationTargetException

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:297)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:69)

at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45)

at com.google.common.eventbus.EventBus.dispatch(EventBus.java:317)

at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:300)

at com.google.common.eventbus.EventBus.post(EventBus.java:268)

at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:123)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:69)

at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45)

at com.google.common.eventbus.EventBus.dispatch(EventBus.java:317)

at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:300)

at com.google.common.eventbus.EventBus.post(EventBus.java:268)

at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:81)

at cpw.mods.fml.common.Loader.initializeMods(Loader.java:592)

... 4 more

Caused by: cpw.mods.fml.common.LoaderException

at leftler.mods.projectbuilder.ProjectBuilder.postInit(ProjectBuilder.java:43)

... 30 more

 

Relevant Details:

- Minecraft Version: 1.3.2

- Operating System: Windows 7 (amd64) version 6.1

- Java Version: 1.7.0_03, Oracle Corporation

- Java VM Version: Java HotSpot 64-Bit Server VM (mixed mode), Oracle Corporation

- Memory: 942918040 bytes (899 MB) / 1056309248 bytes (1007 MB) up to 1056309248 bytes (1007 MB)

- JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M

- LWJGL: 2.4.2

- OpenGL: ATI Mobility Radeon X1600 GL version 2.1.8304 Release, ATI Technologies Inc.

- Is Modded: Definitely; 'forge,fml'

- Type: Client

- Texture Pack: Default

- Profiler Position: N/A (disabled)

 

Link to comment
Share on other sites

I am building a mod that lets players see their creations from schematic files in-game and can help them place the blocks in the correct locations to build large complicated projects when access to the raw map files are not available (like in a multiplayer environment). I want to differentiate these "planning blocks" from normal blocks so I am giving them some transparency. I also am making them Entities that just call the renderer the block would have used so I do not need to muck with the chunk's block list and get it out of sync with the server. To be able to use whatever custom renderer the block I am representing I needed to chang the alpha on all calls to the tesselator. To do that I subclassed the tesselator and replaced the SetColorRGBA(int,int,int,int) function.

 

package leftler.mods.projectbuilder;

import net.minecraft.src.Tessellator;

public class GhostingTessellator extends Tessellator {

private float opacity = 1.0F;

public float getOpacity() {
	return opacity;
}

/**
 * Sets the global opacity.
 * @param opacity  A multiplier between 0 and 1. Any number out of that range will be clamped.
 */
public void setOpacity(float opacity) {
	if(opacity > 1)
		opacity = 1.0F;
	if(opacity < 0)
		opacity = 0;
	this.opacity = opacity;
}

@Override
public void setColorRGBA(int par1, int par2, int par3, int par4) {
	super.setColorRGBA(par1, par2, par3, (int)(par4 * opacity));
}

}

 

After that all the custom renderer does for the entity that represents the block is change the global opacity render the block, use the block's renderer, then change it back.

package leftler.mods.projectbuilder;

import net.minecraft.src.Block;
import net.minecraft.src.Entity;
import net.minecraft.src.Render;
import net.minecraft.src.Tessellator;

public class RenderGhostBlock extends Render {

@Override
public void doRender(Entity var1, double x, double y, double z, float yaw, float partialTickTime) {
	if(var1 instanceof EntityGhostBlock)
	{
		Block parentBlock = ((EntityGhostBlock)var1).parentBlock;

		((GhostingTessellator)Tessellator.instance).setOpacity(.25F);
		this.renderBlocks.renderBlockByRenderType(parentBlock, (int)Math.round(x), (int)Math.round(y), (int)Math.round(z));
		((GhostingTessellator)Tessellator.instance).setOpacity(1.0F);
	}

}



}

 

This code is untested, I am still working on getting the EntityBlocks to spawn at normal opacity. but I was planning ahead so I asked this question. I also renamed it from GhostingTessellator to CustomTessellator as I was worried people would scream "OMFG R U making XRAY mod?!?!?" and not help me due to this helping cheaters. I realized that was a stupid worry and changed the name back.

Link to comment
Share on other sites

cpw, I think I will need your help with this.

 

LoadController.errorOccoured is not a static method, I did not find where to get my mod's LoadController from Loader.instance(). The closest I could find was "Loader.instance().activeModContainer().setEnabledState(false);" however that appeared to have no effect. The main menu still said 3 of 3 mods loaded and inside the ModGUI it still lists "ModState: Available"

 

Any help would be greatly appreciated.

Link to comment
Share on other sites

The problem is, that's far too late. Other mods may well have done something depending on your existence..

 

What is the problem you're trying to actually solve by doing this? Turning yourself off is unlikely to help...

Link to comment
Share on other sites

Technical Need: I am replacing the Tessellator as a way to affect the opacity of all objects drawn during a time span even if they use a custom renderer. I am concerned if another mod also replaced the tessellator I will get InvalidCast exceptions when I try to call my "setOpacity" function. I would like my mod not to load, but not crash the game if some other mod has replaced the tessellator.

 

Gameplay Application: I want to make a "Preview" of a structure from a schematic file visable inside a live game world. I need the player to see through the blocks in this preview as they do not really exist and I do not want to obstruct his view or make him thing there is a ledge when there really is not.

 

Other Applications: If someone wanted to make a "Ghost village" mod they could use the same technique I used so villages and the villagers therein would be see-through.

 

I guess I don't need it to gracefully fail and I can crash the game if there is a conflicting mod, I just did not want to do it as there would be no risk of "blocks turned to air" as I do not add any new blocks and any entities I make are not written out to the NBT and are only stored in memory.

 

I think, for now, I will just go with the "Throw a exception and let the game show the crash screen" rout until the "enable/disable" mod functionality is fleshed out in a few major revisions and more mature methods of checking to see if anyone else clobbered your environment and gracefully failing to load is available.

Link to comment
Share on other sites

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.



×
×
  • Create New...

Important Information

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