Skip to content

Commit

Permalink
Fix creative mode gui handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mezz committed Nov 11, 2015
1 parent 64507ed commit b3f2901
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 17 deletions.
17 changes: 8 additions & 9 deletions src/main/java/mezz/jei/GuiEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/mezz/jei/api/IItemRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ public interface IItemRegistry {

/** Returns a list of all the Items registered. */
@Nonnull
public ImmutableList<ItemStack> getItemList();
ImmutableList<ItemStack> getItemList();

/** Returns a list of all the Items that can be used as fuel in a vanilla furnace. */
@Nonnull
public ImmutableList<ItemStack> getFuels();
ImmutableList<ItemStack> getFuels();

}
6 changes: 3 additions & 3 deletions src/main/java/mezz/jei/api/IModPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ public interface IModPlugin {
/** Returns true if this plugin's mod is loaded. */
boolean isModLoaded();

public Iterable<? extends IRecipeCategory> getRecipeCategories();
Iterable<? extends IRecipeCategory> getRecipeCategories();

public Iterable<? extends IRecipeHandler> getRecipeHandlers();
Iterable<? extends IRecipeHandler> getRecipeHandlers();

public Iterable<Object> getRecipes();
Iterable<Object> getRecipes();

}
14 changes: 14 additions & 0 deletions src/main/java/mezz/jei/gui/RecipesGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/mezz/jei/input/InputHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<ICloseable> objects = new ArrayList<ICloseable>();
objects.add(recipesGui);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/mezz/jei/util/MouseHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b3f2901

Please sign in to comment.