Jump to content

[SOLVED] [1.7.10] Game crashes when unregistering instance from FML Event bus


Belpois

Recommended Posts

EDIT: Solved, never register instances to receive events outside of init methods :D

 

This is a rather straightforward problem to explain... I registered an instance to receive events and then when the instance is not being used (not destroyed, may be used again in the future) I am unregistering it.

 

FMLCommonHandler.instance().bus().register(instance);
FMLCommonHandler.instance().bus().unregister(instance);

 

When unregistering the game crashed, below you can find the crash dump.

 

and yes I am registering it first :P

 

 

 

[20:07:05] [Client thread/FATAL]: Reported exception thrown!
net.minecraft.util.ReportedException: Updating screen events
at net.minecraft.client.Minecraft.runTick(Minecraft.java:1642) ~[Minecraft.class:?]
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:961) ~[Minecraft.class:?]
at net.minecraft.client.Minecraft.run(Minecraft.java:887) [Minecraft.class:?]
at net.minecraft.client.main.Main.main(SourceFile:148) [Main.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_72]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[?:1.7.0_72]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.7.0_72]
at java.lang.reflect.Method.invoke(Method.java:606) ~[?:1.7.0_72]
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.11.jar:?]
at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.11.jar:?]
at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:78) [start/:?]
at GradleStart.main(GradleStart.java:45) [start/:?]
Caused by: java.lang.NullPointerException
at cpw.mods.fml.common.eventhandler.EventBus.unregister(EventBus.java:124) ~[EventBus.class:?]
at com.mm.pp.client.gui.GuiInnerScreenContainer.showInnerGui(GuiInnerScreenContainer.java:133) ~[GuiInnerScreenContainer.class:?]
at com.mm.pp.client.gui.GuiColorSelector.actionPerformed(GuiColorSelector.java:108) ~[GuiColorSelector.class:?]
at net.minecraft.client.gui.GuiScreen.mouseClicked(GuiScreen.java:225) ~[GuiScreen.class:?]
at com.mm.pp.client.gui.GuiInnerScreen.mouseClicked(GuiInnerScreen.java:28) ~[GuiInnerScreen.class:?]
at com.mm.pp.client.gui.GuiColorSelector.mouseClicked(GuiColorSelector.java:128) ~[GuiColorSelector.class:?]
at com.mm.pp.client.gui.GuiInnerScreenContainer.mouseClicked(GuiInnerScreenContainer.java:53) ~[GuiInnerScreenContainer.class:?]
at com.mm.pp.client.gui.GuiPPPattern.mouseClicked(GuiPPPattern.java:79) ~[GuiPPPattern.class:?]
at net.minecraft.client.gui.GuiScreen.handleMouseInput(GuiScreen.java:296) ~[GuiScreen.class:?]
at net.minecraft.client.gui.GuiScreen.handleInput(GuiScreen.java:268) ~[GuiScreen.class:?]
at net.minecraft.client.Minecraft.runTick(Minecraft.java:1628) ~[Minecraft.class:?]
... 11 more
[20:07:05] [Client thread/INFO]: [net.minecraft.client.Minecraft:displayCrashReport:349]: ---- Minecraft Crash Report ----
// This doesn't make any sense!

Time: 1/27/15 8:07 PM
Description: Updating screen events

java.lang.NullPointerException: Updating screen events
at cpw.mods.fml.common.eventhandler.EventBus.unregister(EventBus.java:124)
at com.mm.pp.client.gui.GuiInnerScreenContainer.showInnerGui(GuiInnerScreenContainer.java:133)
at com.mm.pp.client.gui.GuiColorSelector.actionPerformed(GuiColorSelector.java:108)
at net.minecraft.client.gui.GuiScreen.mouseClicked(GuiScreen.java:225)
at com.mm.pp.client.gui.GuiInnerScreen.mouseClicked(GuiInnerScreen.java:28)
at com.mm.pp.client.gui.GuiColorSelector.mouseClicked(GuiColorSelector.java:128)
at com.mm.pp.client.gui.GuiInnerScreenContainer.mouseClicked(GuiInnerScreenContainer.java:53)
at com.mm.pp.client.gui.GuiPPPattern.mouseClicked(GuiPPPattern.java:79)
at net.minecraft.client.gui.GuiScreen.handleMouseInput(GuiScreen.java:296)
at net.minecraft.client.gui.GuiScreen.handleInput(GuiScreen.java:268)
at net.minecraft.client.Minecraft.runTick(Minecraft.java:1628)
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:961)
at net.minecraft.client.Minecraft.run(Minecraft.java:887)
at net.minecraft.client.main.Main.main(SourceFile:148)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:78)
at GradleStart.main(GradleStart.java:45)


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Stacktrace:
at cpw.mods.fml.common.eventhandler.EventBus.unregister(EventBus.java:124)
at com.mm.pp.client.gui.GuiInnerScreenContainer.showInnerGui(GuiInnerScreenContainer.java:133)
at com.mm.pp.client.gui.GuiColorSelector.actionPerformed(GuiColorSelector.java:108)
at net.minecraft.client.gui.GuiScreen.mouseClicked(GuiScreen.java:225)
at com.mm.pp.client.gui.GuiInnerScreen.mouseClicked(GuiInnerScreen.java:28)
at com.mm.pp.client.gui.GuiColorSelector.mouseClicked(GuiColorSelector.java:128)
at com.mm.pp.client.gui.GuiInnerScreenContainer.mouseClicked(GuiInnerScreenContainer.java:53)
at com.mm.pp.client.gui.GuiPPPattern.mouseClicked(GuiPPPattern.java:79)
at net.minecraft.client.gui.GuiScreen.handleMouseInput(GuiScreen.java:296)
at net.minecraft.client.gui.GuiScreen.handleInput(GuiScreen.java:268)

-- Affected screen --
Details:
Screen name: com.mm.pp.client.gui.GuiPPPattern

-- Affected level --
Details:
Level name: MpServer
All players: 1 total; [EntityClientPlayerMP['Player171'/194, l='MpServer', x=151.50, y=80.62, z=219.65]]
Chunk stats: MultiplayerChunkCache: 170, 170
Level seed: 0
Level generator: ID 00 - default, ver 1. Features enabled: false
Level generator options: 
Level spawn location: World: (140,64,256), Chunk: (at 12,4,0 in 8,16; contains blocks 128,0,256 to 143,255,271), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)
Level time: 10885 game time, 10885 day time
Level dimension: 0
Level storage version: 0x00000 - Unknown?
Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false)
Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false
Forced entities: 83 total; [EntitySkeleton['Skeleton'/137, l='MpServer', x=215.47, y=42.00, z=265.22], EntitySkeleton['Skeleton'/136, l='MpServer', x=223.34, y=49.00, z=251.94], EntityZombie['Zombie'/139, l='MpServer', x=219.97, y=54.00, z=291.53], EntitySkeleton['Skeleton'/138, l='MpServer', x=215.88, y=42.00, z=264.41], EntityZombie['Zombie'/129, l='MpServer', x=205.50, y=16.00, z=206.50], EntityZombie['Zombie'/128, l='MpServer', x=206.50, y=16.00, z=204.50], EntityBat['Bat'/131, l='MpServer', x=196.34, y=24.10, z=274.75], EntityCreeper['Creeper'/130, l='MpServer', x=205.97, y=26.00, z=266.50], EntityZombie['Zombie'/132, l='MpServer', x=200.34, y=27.00, z=296.69], EntitySkeleton['Skeleton'/135, l='MpServer', x=220.94, y=49.00, z=249.53], EntitySpider['Spider'/134, l='MpServer', x=222.78, y=38.00, z=152.44], EntityBat['Bat'/153, l='MpServer', x=227.93, y=38.45, z=160.67], EntityBat['Bat'/154, l='MpServer', x=224.00, y=36.54, z=160.37], EntitySkeleton['Skeleton'/155, l='MpServer', x=231.50, y=34.00, z=192.50], EntityCreeper['Creeper'/156, l='MpServer', x=226.00, y=14.00, z=266.53], EntityZombie['Zombie'/157, l='MpServer', x=224.09, y=43.00, z=265.50], EntityZombie['Zombie'/47, l='MpServer', x=77.69, y=26.00, z=239.50], EntitySpider['Spider'/44, l='MpServer', x=73.34, y=30.00, z=188.00], EntityZombie['Zombie'/45, l='MpServer', x=78.50, y=11.00, z=208.50], EntityCreeper['Creeper'/51, l='MpServer', x=89.28, y=11.00, z=198.53], EntityZombie['Zombie'/50, l='MpServer', x=88.84, y=11.00, z=200.69], EntitySkeleton['Skeleton'/49, l='MpServer', x=73.91, y=63.00, z=258.47], EntityZombie['Zombie'/48, l='MpServer', x=74.50, y=24.00, z=250.50], EntityZombie['Zombie'/55, l='MpServer', x=82.38, y=19.00, z=220.84], EntityCreeper['Creeper'/54, l='MpServer', x=87.38, y=13.00, z=204.69], EntityCreeper['Creeper'/53, l='MpServer', x=89.72, y=11.00, z=199.94], EntityCreeper['Creeper'/52, l='MpServer', x=91.25, y=11.00, z=199.78], EntitySpider['Spider'/59, l='MpServer', x=107.72, y=20.00, z=220.63], EntityZombie['Zombie'/58, l='MpServer', x=83.03, y=26.00, z=251.53], EntityCreeper['Creeper'/57, l='MpServer', x=85.50, y=26.00, z=255.50], EntityZombie['Zombie'/56, l='MpServer', x=84.50, y=21.00, z=222.50], EntityZombie['Zombie'/63, l='MpServer', x=103.00, y=18.00, z=224.31], EntityCreeper['Creeper'/62, l='MpServer', x=104.97, y=25.00, z=234.44], EntityCreeper['Creeper'/61, l='MpServer', x=97.50, y=17.00, z=233.50], EntityZombie['Zombie'/60, l='MpServer', x=106.16, y=18.00, z=221.84], EntitySkeleton['Skeleton'/68, l='MpServer', x=109.50, y=23.00, z=270.50], EntityCreeper['Creeper'/69, l='MpServer', x=97.03, y=42.00, z=282.59], EntityBat['Bat'/70, l='MpServer', x=102.84, y=42.05, z=288.09], EntitySkeleton['Skeleton'/71, l='MpServer', x=103.59, y=42.00, z=290.53], EntityBat['Bat'/64, l='MpServer', x=107.56, y=45.04, z=226.91], EntityZombie['Zombie'/65, l='MpServer', x=106.50, y=13.00, z=250.78], EntityZombie['Zombie'/66, l='MpServer', x=105.88, y=15.00, z=243.66], EntityCreeper['Creeper'/67, l='MpServer', x=105.22, y=16.00, z=244.69], EntitySkeleton['Skeleton'/76, l='MpServer', x=115.50, y=27.00, z=261.50], EntitySkeleton['Skeleton'/77, l='MpServer', x=113.94, y=23.00, z=271.25], EntitySkeleton['Skeleton'/78, l='MpServer', x=112.50, y=23.00, z=272.50], EntitySkeleton['Skeleton'/79, l='MpServer', x=126.50, y=23.00, z=296.00], EntityBat['Bat'/72, l='MpServer', x=106.51, y=44.82, z=295.41], EntityCreeper['Creeper'/73, l='MpServer', x=114.50, y=27.00, z=160.50], EntityZombie['Zombie'/74, l='MpServer', x=120.50, y=26.00, z=247.50], EntityCreeper['Creeper'/75, l='MpServer', x=115.50, y=27.00, z=260.50], EntitySpider['Spider'/85, l='MpServer', x=139.13, y=29.00, z=152.97], EntityZombie['Zombie'/87, l='MpServer', x=140.50, y=29.00, z=158.59], EntityZombie['Zombie'/86, l='MpServer', x=141.69, y=29.00, z=153.16], EntitySkeleton['Skeleton'/93, l='MpServer', x=138.50, y=31.00, z=267.84], EntitySpider['Spider'/92, l='MpServer', x=136.28, y=27.00, z=269.53], EntitySkeleton['Skeleton'/95, l='MpServer', x=135.25, y=30.00, z=290.69], EntityBat['Bat'/94, l='MpServer', x=134.88, y=32.10, z=281.28], EntityBat['Bat'/89, l='MpServer', x=148.09, y=13.48, z=244.78], EntityWolf['Wolf'/88, l='MpServer', x=137.32, y=79.75, z=184.64], EntityCreeper['Creeper'/91, l='MpServer', x=128.31, y=27.00, z=249.66], EntityCreeper['Creeper'/90, l='MpServer', x=129.00, y=27.00, z=250.53], EntitySkeleton['Skeleton'/96, l='MpServer', x=128.50, y=23.00, z=295.50], EntityBat['Bat'/97, l='MpServer', x=131.25, y=35.10, z=288.25], EntityClientPlayerMP['Player171'/194, l='MpServer', x=151.50, y=80.62, z=219.65], EntityCreeper['Creeper'/110, l='MpServer', x=162.69, y=24.00, z=196.69], EntityCreeper['Creeper'/111, l='MpServer', x=161.91, y=24.00, z=196.56], EntityXPOrb['Experience Orb'/104, l='MpServer', x=155.75, y=76.25, z=217.91], EntityBat['Bat'/105, l='MpServer', x=156.75, y=12.10, z=287.75], EntityChicken['Chicken'/119, l='MpServer', x=180.03, y=78.00, z=201.75], EntityCreeper['Creeper'/118, l='MpServer', x=190.53, y=26.00, z=207.34], EntityBat['Bat'/117, l='MpServer', x=170.75, y=31.10, z=290.75], EntityCreeper['Creeper'/116, l='MpServer', x=165.56, y=12.00, z=280.06], EntityChicken['Chicken'/115, l='MpServer', x=167.19, y=80.00, z=209.06], EntitySkeleton['Skeleton'/114, l='MpServer', x=162.69, y=38.00, z=217.75], EntitySkeleton['Skeleton'/113, l='MpServer', x=161.02, y=26.00, z=219.06], EntityCreeper['Creeper'/112, l='MpServer', x=165.00, y=23.00, z=194.44], EntityCreeper['Creeper'/125, l='MpServer', x=180.69, y=35.00, z=214.25], EntityZombie['Zombie'/124, l='MpServer', x=187.53, y=30.00, z=209.69], EntityItem['item.item.egg'/123, l='MpServer', x=177.13, y=73.13, z=199.66], EntityItem['item.item.egg'/122, l='MpServer', x=178.00, y=78.13, z=200.81], EntityChicken['Chicken'/121, l='MpServer', x=178.47, y=73.00, z=199.53], EntityChicken['Chicken'/120, l='MpServer', x=180.31, y=78.00, z=203.56]]
Retry entities: 0 total; []
Server brand: fml,forge
Server type: Integrated singleplayer server
Stacktrace:
at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:373)
at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2432)
at net.minecraft.client.Minecraft.run(Minecraft.java:909)
at net.minecraft.client.main.Main.main(SourceFile:148)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:78)
at GradleStart.main(GradleStart.java:45)

 

 

 

Any ideas?

 

All the code, with comments ;)

public class GuiInnerScreenContainer extends GuiScreen
{
// A list with all the inner screens
protected ArrayList<GuiInnerScreen> innerScreenList;

// The current visible inner screen
protected GuiInnerScreen visibleGuiInnerScreen;

public GuiInnerScreenContainer()
{
	this.innerScreenList = new ArrayList<GuiInnerScreen>();
	this.visibleGuiInnerScreen = null;
}

@Override
public void initGui()
{
	// Calling the gui update method, this will update the sub gui's
	this.updateInnerGui();
}

@Override
public void mouseClickMove(int mouseX, int mouseY, int buttonClicked, long timeSinceLastClick)
{
	super.mouseClickMove(mouseX, mouseY, buttonClicked, timeSinceLastClick);

	if (this.visibleGuiInnerScreen == null)
	{
		return;
	}

	this.visibleGuiInnerScreen.mouseClickMove(mouseX, mouseY, buttonClicked, timeSinceLastClick);
}

@Override
protected void mouseClicked(int mouseX, int mouseY, int buttonClicked)
{
	super.mouseClicked(mouseX, mouseY, buttonClicked);

	if (this.visibleGuiInnerScreen == null)
	{
		return;
	}

	this.visibleGuiInnerScreen.mouseClicked(mouseX, mouseY, buttonClicked);
}

@Override
protected void mouseMovedOrUp(int mouseX, int mouseY, int buttonClicked)
{
	super.mouseMovedOrUp(mouseX, mouseY, buttonClicked);

	if (this.visibleGuiInnerScreen == null)
	{
		return;
	}

	this.visibleGuiInnerScreen.mouseMovedOrUp(mouseX, mouseY, buttonClicked);
}

@Override
public void drawScreen(int p_73863_1_, int p_73863_2_, float p_73863_3_)
{
	this.drawDefaultBackground();

	if (this.visibleGuiInnerScreen == null)
	{
		return;
	}

	this.visibleGuiInnerScreen.drawScreen(p_73863_1_, p_73863_2_, p_73863_3_);
}

@Override
public void onGuiClosed()
{
	super.onGuiClosed();

	if (this.visibleGuiInnerScreen == null)
	{
		return;
	}

	this.visibleGuiInnerScreen.onGuiClosed();
}

public void updateInnerGui()
{
	// Check if the current gui is available, if not this is the first time we entered this method.
	if (this.visibleGuiInnerScreen == null)
	{
		// Show the first gui.
		this.showInnerGui(0);

		// Return as we already initialized it.
		return;
	}

	// Setting the GUI's inner reference values.
	this.visibleGuiInnerScreen.mc = this.mc;
	this.visibleGuiInnerScreen.width = this.width;
	this.visibleGuiInnerScreen.height = this.height;
	this.visibleGuiInnerScreen.allowUserInput = this.allowUserInput;

	// Initializing the GUI's
	this.visibleGuiInnerScreen.initGui();
}

/*
 * Selects which inner gui to show (Code in question)
 */
public void showInnerGui(int guiId)
{
	GuiInnerScreen newVisibleGuiScreen = null;
	for (GuiInnerScreen guiInnerScreen : this.innerScreenList)
	{
		// Fetch the requested gui by id.
		if (guiInnerScreen.guiId != guiId)
		{
			// If not found we continue.
			continue;
		}

		// When found we set the gui and break.
		newVisibleGuiScreen = guiInnerScreen;
		break;
	}

	// This is a check in the case we did not find the GUI.
	if (newVisibleGuiScreen == null)
	{
		return;
	}

	// If the a gui is already visible.
	if (this.visibleGuiInnerScreen != null)
	{
		// Call the onHidden
		this.visibleGuiInnerScreen.onHidden();

		// and unregister the instance.
		FMLCommonHandler.instance().bus().unregister(this.visibleGuiInnerScreen);
	}

	// Set up some references.
	this.visibleGuiInnerScreen = newVisibleGuiScreen;
	this.visibleGuiInnerScreen.mc = this.mc;
	this.visibleGuiInnerScreen.width = this.width;
	this.visibleGuiInnerScreen.height = this.height;
	this.visibleGuiInnerScreen.allowUserInput = this.allowUserInput;

	// Usual init
	this.visibleGuiInnerScreen.initGui();

	// Register the gui with the bus.
	FMLCommonHandler.instance().bus().register(this.visibleGuiInnerScreen);

	// Call the on visible.
	this.visibleGuiInnerScreen.onVisible();
}
}

I require Java, both the coffee and the code :)

Link to comment
Share on other sites

Show your code.

 

I Commented it, the code in question is marked with a comment "(Code in Question)" :)

 

public class GuiInnerScreenContainer extends GuiScreen
{
// A list with all the inner screens
protected ArrayList<GuiInnerScreen> innerScreenList;

// The current visible inner screen
protected GuiInnerScreen visibleGuiInnerScreen;

public GuiInnerScreenContainer()
{
	this.innerScreenList = new ArrayList<GuiInnerScreen>();
	this.visibleGuiInnerScreen = null;
}

@Override
public void initGui()
{
	// Calling the gui update method, this will update the sub gui's
	this.updateInnerGui();
}

@Override
public void mouseClickMove(int mouseX, int mouseY, int buttonClicked, long timeSinceLastClick)
{
	super.mouseClickMove(mouseX, mouseY, buttonClicked, timeSinceLastClick);

	if (this.visibleGuiInnerScreen == null)
	{
		return;
	}

	this.visibleGuiInnerScreen.mouseClickMove(mouseX, mouseY, buttonClicked, timeSinceLastClick);
}

@Override
protected void mouseClicked(int mouseX, int mouseY, int buttonClicked)
{
	super.mouseClicked(mouseX, mouseY, buttonClicked);

	if (this.visibleGuiInnerScreen == null)
	{
		return;
	}

	this.visibleGuiInnerScreen.mouseClicked(mouseX, mouseY, buttonClicked);
}

@Override
protected void mouseMovedOrUp(int mouseX, int mouseY, int buttonClicked)
{
	super.mouseMovedOrUp(mouseX, mouseY, buttonClicked);

	if (this.visibleGuiInnerScreen == null)
	{
		return;
	}

	this.visibleGuiInnerScreen.mouseMovedOrUp(mouseX, mouseY, buttonClicked);
}

@Override
public void drawScreen(int p_73863_1_, int p_73863_2_, float p_73863_3_)
{
	this.drawDefaultBackground();

	if (this.visibleGuiInnerScreen == null)
	{
		return;
	}

	this.visibleGuiInnerScreen.drawScreen(p_73863_1_, p_73863_2_, p_73863_3_);
}

@Override
public void onGuiClosed()
{
	super.onGuiClosed();

	if (this.visibleGuiInnerScreen == null)
	{
		return;
	}

	this.visibleGuiInnerScreen.onGuiClosed();
}

public void updateInnerGui()
{
	// Check if the current gui is available, if not this is the first time we entered this method.
	if (this.visibleGuiInnerScreen == null)
	{
		// Show the first gui.
		this.showInnerGui(0);

		// Return as we already initialized it.
		return;
	}

	// Setting the GUI's inner reference values.
	this.visibleGuiInnerScreen.mc = this.mc;
	this.visibleGuiInnerScreen.width = this.width;
	this.visibleGuiInnerScreen.height = this.height;
	this.visibleGuiInnerScreen.allowUserInput = this.allowUserInput;

	// Initializing the GUI's
	this.visibleGuiInnerScreen.initGui();
}
        
/*
 * Selects which inner gui to show (Code in question)
 */
public void showInnerGui(int guiId)
{
	GuiInnerScreen newVisibleGuiScreen = null;
	for (GuiInnerScreen guiInnerScreen : this.innerScreenList)
	{
		// Fetch the requested gui by id.
		if (guiInnerScreen.guiId != guiId)
		{
			// If not found we continue.
			continue;
		}

		// When found we set the gui and break.
		newVisibleGuiScreen = guiInnerScreen;
		break;
	}

	// This is a check in the case we did not find the GUI.
	if (newVisibleGuiScreen == null)
	{
		return;
	}

	// If the a gui is already visible.
	if (this.visibleGuiInnerScreen != null)
	{
		// Call the onHidden
		this.visibleGuiInnerScreen.onHidden();

		// and unregister the instance.
		FMLCommonHandler.instance().bus().unregister(this.visibleGuiInnerScreen);
	}

	// Set up some references.
	this.visibleGuiInnerScreen = newVisibleGuiScreen;
	this.visibleGuiInnerScreen.mc = this.mc;
	this.visibleGuiInnerScreen.width = this.width;
	this.visibleGuiInnerScreen.height = this.height;
	this.visibleGuiInnerScreen.allowUserInput = this.allowUserInput;

	// Usual init
	this.visibleGuiInnerScreen.initGui();

	// Register the gui with the bus.
	FMLCommonHandler.instance().bus().register(this.visibleGuiInnerScreen);

	// Call the on visible.
	this.visibleGuiInnerScreen.onVisible();
}
}

I require Java, both the coffee and the code :)

Link to comment
Share on other sites

That won't work, FML does not allow registering of event handlers outside the state events (preInit, init, etc.).

 

Ahh crud, thats why then... Thanks

 

Strangely enough tough the register still works, as each time I register the method is called. Any idea about that?

I require Java, both the coffee and the code :)

Link to comment
Share on other sites

Yes, the register works, but it should print out a huge mess of error in the console :P

 

Thanks man but strangely enough it doesn't print out the errors when registering... must be on a log level that the logger is not printing (Time to mess with the log4j's configs :P)

I require Java, both the coffee and the code :)

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.