Added GuiOpenEvent

You can use this for a clean way to override guis, without needing an
TickHandler to check if the gui you want to override is open and show
your own gui

Proper close check
This commit is contained in:
jk-5 committed 2013-08-24 09:32:34 +02:00
1 parent b2c1eae652
commit f78eba09fd
2 files changed
+76 -11

No files matched your search

@@ -0,0 +1,22 @@
package net.minecraftforge.client.event;
import net.minecraft.client.gui.GuiScreen;
import net.minecraftforge.event.Cancelable;
import net.minecraftforge.event.Event;
/**
* This event is called before any Gui will open.
* If you don't want this to happen, cancel the event.
* If you want to override this Gui, simply set the gui variable to your own Gui.
*
* @author jk-5
*/
@Cancelable
public class GuiOpenEvent extends Event
{
public GuiScreen gui;
public GuiOpenEvent(GuiScreen gui)
{
this.gui = gui;
}
}
@@ -1,11 +1,12 @@
--- ../src_base/minecraft/net/minecraft/client/Minecraft.java
+++ ../src_work/minecraft/net/minecraft/client/Minecraft.java
@@ -137,6 +137,14 @@
@@ -137,6 +137,15 @@
import com.google.common.collect.MapDifference;
+import net.minecraftforge.client.ForgeHooksClient;
+import net.minecraftforge.client.GuiIngameForge;
+import net.minecraftforge.client.event.GuiOpenEvent;
+import net.minecraftforge.common.ForgeHooks;
+import net.minecraftforge.common.MinecraftForge;
+import net.minecraftforge.event.ForgeEventFactory;
@@ -15,7 +16,7 @@
@SideOnly(Side.CLIENT)
public class Minecraft implements IPlayerUsage
{
@@ -416,7 +424,7 @@
@@ -416,7 +425,7 @@
try
{
@@ -24,7 +25,7 @@
}
catch (LWJGLException lwjglexception)
{
@@ -497,7 +505,7 @@
@@ -497,7 +506,7 @@
this.effectRenderer = new EffectRenderer(this.theWorld, this.renderEngine);
FMLClientHandler.instance().finishMinecraftLoading();
this.checkGLError("Post startup");
@@ -33,7 +34,49 @@
if (this.serverName != null)
{
@@ -1300,7 +1308,7 @@
@@ -679,20 +688,30 @@
*/
public void displayGuiScreen(GuiScreen par1GuiScreen)
{
+ this.statFileWriter.syncStats();
+
+ if (par1GuiScreen == null && this.theWorld == null)
+ {
+ par1GuiScreen = new GuiMainMenu();
+ }
+ else if (par1GuiScreen == null && this.thePlayer.func_110143_aJ() <= 0.0F)
+ {
+ par1GuiScreen = new GuiGameOver();
+ }
+
+ GuiScreen old = this.currentScreen;
+ GuiOpenEvent event = new GuiOpenEvent(par1GuiScreen);
+ boolean canceled = MinecraftForge.EVENT_BUS.post(event);
+ if(old != null && old != this.currentScreen)
+ {
+ old.onGuiClosed();
+ }
+ if(canceled) return;
+ par1GuiScreen = event.gui;
+
if (this.currentScreen != null)
{
this.currentScreen.onGuiClosed();
- }
-
- this.statFileWriter.syncStats();
-
- if (par1GuiScreen == null && this.theWorld == null)
- {
- par1GuiScreen = new GuiMainMenu();
- }
- else if (par1GuiScreen == null && this.thePlayer.func_110143_aJ() <= 0.0F)
- {
- par1GuiScreen = new GuiGameOver();
}
if (par1GuiScreen instanceof GuiMainMenu)
@@ -1300,7 +1319,7 @@
if (this.thePlayer.isCurrentToolAdventureModeExempt(j, k, l))
{
@@ -42,7 +85,7 @@
this.thePlayer.swingItem();
}
}
@@ -1366,7 +1374,8 @@
@@ -1366,7 +1385,8 @@
{
int j1 = itemstack != null ? itemstack.stackSize : 0;
@@ -52,7 +95,7 @@
{
flag = false;
this.thePlayer.swingItem();
@@ -1392,7 +1401,8 @@
@@ -1392,7 +1412,8 @@
{
ItemStack itemstack1 = this.thePlayer.inventory.getCurrentItem();
@@ -62,7 +105,7 @@
{
this.entityRenderer.itemRenderer.resetEquippedProgress2();
}
@@ -2046,6 +2056,11 @@
@@ -2046,6 +2067,11 @@
{
this.statFileWriter.syncStats();
@@ -74,7 +117,7 @@
if (par1WorldClient == null)
{
NetClientHandler netclienthandler = this.getNetHandler();
@@ -2063,6 +2078,18 @@
@@ -2063,6 +2089,18 @@
if (this.theIntegratedServer != null)
{
this.theIntegratedServer.initiateShutdown();
@@ -93,7 +136,7 @@
}
this.theIntegratedServer = null;
@@ -2236,107 +2263,12 @@
@@ -2236,107 +2274,12 @@
if (this.objectMouseOver != null)
{
boolean flag = this.thePlayer.capabilities.isCreativeMode;
@@ -205,7 +248,7 @@
if (flag)
{
@@ -2419,11 +2351,18 @@
@@ -2419,11 +2362,18 @@
par1PlayerUsageSnooper.addData("gl_max_texture_size", Integer.valueOf(getGLMaximumTextureSize()));
}
@@ -224,7 +267,7 @@
for (int i = 16384; i > 0; i >>= 1)
{
GL11.glTexImage2D(GL11.GL_PROXY_TEXTURE_2D, 0, GL11.GL_RGBA, i, i, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, (ByteBuffer)null);
@@ -2431,6 +2370,7 @@
@@ -2431,6 +2381,7 @@
if (j != 0)
{