From b3f29015bfe6ef6b0b7a3bf63974d9ef6db19be4 Mon Sep 17 00:00:00 2001 From: mezz Date: Tue, 10 Nov 2015 19:02:21 -0800 Subject: [PATCH] Fix creative mode gui handling --- src/main/java/mezz/jei/GuiEventHandler.java | 17 ++++++++--------- src/main/java/mezz/jei/api/IItemRegistry.java | 4 ++-- src/main/java/mezz/jei/api/IModPlugin.java | 6 +++--- src/main/java/mezz/jei/gui/RecipesGui.java | 14 ++++++++++++++ src/main/java/mezz/jei/input/InputHandler.java | 4 ++-- src/main/java/mezz/jei/util/MouseHelper.java | 3 ++- 6 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/main/java/mezz/jei/GuiEventHandler.java b/src/main/java/mezz/jei/GuiEventHandler.java index c7c827061..206960cd5 100644 --- a/src/main/java/mezz/jei/GuiEventHandler.java +++ b/src/main/java/mezz/jei/GuiEventHandler.java @@ -6,7 +6,6 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.client.gui.inventory.GuiContainerCreative; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; @@ -35,19 +34,19 @@ public GuiEventHandler(@Nonnull ItemListOverlay itemListOverlay) { @SubscribeEvent public void onGuiInit(@Nonnull GuiScreenEvent.InitGuiEvent.Post event) { - GuiContainer guiContainer = asGuiContainer(event.gui); + Minecraft minecraft = Minecraft.getMinecraft(); + GuiContainer guiContainer = asGuiContainer(minecraft.currentScreen); if (guiContainer == null) { return; } - itemListOverlay.initGui(guiContainer); - - Minecraft minecraft = Minecraft.getMinecraft(); + itemListOverlay.initGui(guiContainer); recipesGui.initGui(minecraft); + inputHandler = new InputHandler(recipesGui, itemListOverlay, guiContainer); - inputHandler = new InputHandler(minecraft, recipesGui, itemListOverlay, guiContainer); - - itemListOverlay.open(); + if (!minecraft.thePlayer.capabilities.isCreativeMode) { + itemListOverlay.open(); + } } @SubscribeEvent @@ -132,7 +131,7 @@ public void onGuiMouseEvent(GuiScreenEvent.MouseInputEvent.Pre event) { @Nullable private GuiContainer asGuiContainer(GuiScreen guiScreen) { - if (!(guiScreen instanceof GuiContainer) || (guiScreen instanceof GuiContainerCreative)) { + if (!(guiScreen instanceof GuiContainer)) { return null; } return (GuiContainer) guiScreen; diff --git a/src/main/java/mezz/jei/api/IItemRegistry.java b/src/main/java/mezz/jei/api/IItemRegistry.java index 784eb4733..07b113b02 100644 --- a/src/main/java/mezz/jei/api/IItemRegistry.java +++ b/src/main/java/mezz/jei/api/IItemRegistry.java @@ -10,10 +10,10 @@ public interface IItemRegistry { /** Returns a list of all the Items registered. */ @Nonnull - public ImmutableList getItemList(); + ImmutableList getItemList(); /** Returns a list of all the Items that can be used as fuel in a vanilla furnace. */ @Nonnull - public ImmutableList getFuels(); + ImmutableList getFuels(); } diff --git a/src/main/java/mezz/jei/api/IModPlugin.java b/src/main/java/mezz/jei/api/IModPlugin.java index 41f3ace41..839f12f48 100644 --- a/src/main/java/mezz/jei/api/IModPlugin.java +++ b/src/main/java/mezz/jei/api/IModPlugin.java @@ -12,10 +12,10 @@ public interface IModPlugin { /** Returns true if this plugin's mod is loaded. */ boolean isModLoaded(); - public Iterable getRecipeCategories(); + Iterable getRecipeCategories(); - public Iterable getRecipeHandlers(); + Iterable getRecipeHandlers(); - public Iterable getRecipes(); + Iterable getRecipes(); } diff --git a/src/main/java/mezz/jei/gui/RecipesGui.java b/src/main/java/mezz/jei/gui/RecipesGui.java index 9a71bc534..5333cd034 100644 --- a/src/main/java/mezz/jei/gui/RecipesGui.java +++ b/src/main/java/mezz/jei/gui/RecipesGui.java @@ -15,6 +15,8 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; +import net.minecraftforge.client.event.GuiScreenEvent; +import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.client.FMLClientHandler; import org.lwjgl.opengl.GL11; @@ -120,6 +122,18 @@ public void initGui(@Nonnull Minecraft minecraft) { } } + // don't post GUI events or we end up in an infinite loop handling them + @Override + public void setWorldAndResolution(Minecraft mc, int width, int height) { + this.mc = mc; + this.itemRender = mc.getRenderItem(); + this.fontRendererObj = mc.fontRendererObj; + this.width = width; + this.height = height; + this.buttonList.clear(); + this.initGui(); + } + private void resetLayout() { recipeGuis.clear(); pageIndex = 0; diff --git a/src/main/java/mezz/jei/input/InputHandler.java b/src/main/java/mezz/jei/input/InputHandler.java index 35321e956..50cf84c95 100644 --- a/src/main/java/mezz/jei/input/InputHandler.java +++ b/src/main/java/mezz/jei/input/InputHandler.java @@ -36,11 +36,11 @@ public class InputHandler { private boolean clickHandled = false; private int keyHandled = -1; - public InputHandler(Minecraft minecraft, RecipesGui recipesGui, ItemListOverlay itemListOverlay, GuiContainer guiContainer) { + public InputHandler(RecipesGui recipesGui, ItemListOverlay itemListOverlay, GuiContainer guiContainer) { this.recipesGui = recipesGui; this.itemListOverlay = itemListOverlay; - this.mouseHelper = new MouseHelper(minecraft); + this.mouseHelper = new MouseHelper(); List objects = new ArrayList(); objects.add(recipesGui); diff --git a/src/main/java/mezz/jei/util/MouseHelper.java b/src/main/java/mezz/jei/util/MouseHelper.java index 96d98a5df..f803228dd 100644 --- a/src/main/java/mezz/jei/util/MouseHelper.java +++ b/src/main/java/mezz/jei/util/MouseHelper.java @@ -11,7 +11,8 @@ public class MouseHelper { private final int displayWidth; private final int displayHeight; - public MouseHelper(Minecraft minecraft) { + public MouseHelper() { + Minecraft minecraft = Minecraft.getMinecraft(); displayWidth = minecraft.displayWidth; displayHeight = minecraft.displayHeight; scaledresolution = new ScaledResolution(minecraft, displayWidth, displayHeight);