diff --git a/src/main/java/com/raoulvdberge/refinedstorage/integration/jei/AdvancedGuiHandler.java b/src/main/java/com/raoulvdberge/refinedstorage/integration/jei/AdvancedGuiHandler.java deleted file mode 100644 index d1af1ba268..0000000000 --- a/src/main/java/com/raoulvdberge/refinedstorage/integration/jei/AdvancedGuiHandler.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.raoulvdberge.refinedstorage.integration.jei; -/* -import com.raoulvdberge.refinedstorage.container.ContainerBase; -import com.raoulvdberge.refinedstorage.container.slot.filter.SlotFilterFluid; -import com.raoulvdberge.refinedstorage.gui.GuiBase; -import com.raoulvdberge.refinedstorage.gui.grid.GuiGrid; -import mezz.jei.api.gui.IAdvancedGuiHandler; -import net.minecraftforge.fluids.FluidStack; - -import javax.annotation.Nullable; -import java.awt.*; -import java.util.List; - -public class AdvancedGuiHandler implements IAdvancedGuiHandler { - @Override - public Class getGuiContainerClass() { - return GuiBase.class; - } - - @Nullable - @Override - public List getGuiExtraAreas(GuiBase gui) { - return null; - } - - @Nullable - @Override - public Object getIngredientUnderMouse(GuiBase gui, int mouseX, int mouseY) { - mouseX -= gui.getGuiLeft(); - mouseY -= gui.getGuiTop(); - - if (gui instanceof GuiGrid) { - GuiGrid grid = (GuiGrid) gui; - - if (grid.getScrollbar() != null && !grid.getSearchField().isFocused() && grid.isOverSlotArea(mouseX, mouseY)) { - return grid.getSlotNumber() >= 0 && grid.getSlotNumber() < grid.getView().getStacks().size() ? grid.getView().getStacks().get(grid.getSlotNumber()).getIngredient() : null; - } - } - - if (gui.inventorySlots instanceof ContainerBase) { - for (SlotFilterFluid slot : ((ContainerBase) gui.inventorySlots).getFluidSlots()) { - FluidStack fluidInSlot = slot.getFluidInventory().getFluid(slot.getSlotIndex()); - - if (fluidInSlot != null && gui.isMouseOverSlotPublic(slot, mouseX + gui.getGuiLeft(), mouseY + gui.getGuiTop())) { - return fluidInSlot; - } - } - } - - return null; - } -} -*/ \ No newline at end of file diff --git a/src/main/java/com/raoulvdberge/refinedstorage/integration/jei/GuiContainerHandler.java b/src/main/java/com/raoulvdberge/refinedstorage/integration/jei/GuiContainerHandler.java new file mode 100644 index 0000000000..c84f662cd6 --- /dev/null +++ b/src/main/java/com/raoulvdberge/refinedstorage/integration/jei/GuiContainerHandler.java @@ -0,0 +1,40 @@ +package com.raoulvdberge.refinedstorage.integration.jei; + +import com.raoulvdberge.refinedstorage.container.BaseContainer; +import com.raoulvdberge.refinedstorage.container.slot.filter.FluidFilterSlot; +import com.raoulvdberge.refinedstorage.screen.BaseScreen; +import com.raoulvdberge.refinedstorage.screen.grid.GridScreen; +import com.raoulvdberge.refinedstorage.util.RenderUtils; +import mezz.jei.api.gui.handlers.IGuiContainerHandler; +import net.minecraftforge.fluids.FluidStack; + +import javax.annotation.Nullable; + +public class GuiContainerHandler implements IGuiContainerHandler { + @Nullable + @Override + public Object getIngredientUnderMouse(BaseScreen screen, double mouseX, double mouseY) { + mouseX -= screen.getGuiLeft(); + mouseY -= screen.getGuiTop(); + + if (screen instanceof GridScreen) { + GridScreen grid = (GridScreen) screen; + + if (!grid.getSearchField().isFocused() && grid.isOverSlotArea(mouseX, mouseY)) { + return grid.getSlotNumber() >= 0 && grid.getSlotNumber() < grid.getView().getStacks().size() ? grid.getView().getStacks().get(grid.getSlotNumber()).getIngredient() : null; + } + } + + if (screen.getContainer() instanceof BaseContainer) { + for (FluidFilterSlot slot : ((BaseContainer) screen.getContainer()).getFluidSlots()) { + FluidStack fluidInSlot = slot.getFluidInventory().getFluid(slot.getSlotIndex()); + + if (!fluidInSlot.isEmpty() && RenderUtils.inBounds(slot.xPos, slot.yPos, 18, 18, mouseX, mouseY)) { + return fluidInSlot; + } + } + } + + return null; + } +} diff --git a/src/main/java/com/raoulvdberge/refinedstorage/integration/jei/IntegrationJEI.java b/src/main/java/com/raoulvdberge/refinedstorage/integration/jei/IntegrationJEI.java deleted file mode 100755 index 7f22e5af9c..0000000000 --- a/src/main/java/com/raoulvdberge/refinedstorage/integration/jei/IntegrationJEI.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.raoulvdberge.refinedstorage.integration.jei; -/* -import net.minecraftforge.fml.common.Loader; - -public final class IntegrationJEI { - public static boolean isLoaded() { - return Loader.isModLoaded("jei"); - } -} - */ diff --git a/src/main/java/com/raoulvdberge/refinedstorage/integration/jei/JeiIntegration.java b/src/main/java/com/raoulvdberge/refinedstorage/integration/jei/JeiIntegration.java new file mode 100644 index 0000000000..22193557c2 --- /dev/null +++ b/src/main/java/com/raoulvdberge/refinedstorage/integration/jei/JeiIntegration.java @@ -0,0 +1,10 @@ +package com.raoulvdberge.refinedstorage.integration.jei; + +import net.minecraftforge.fml.ModList; + +public final class JeiIntegration { + public static boolean isLoaded() { + return ModList.get().isLoaded("jei"); + } +} + diff --git a/src/main/java/com/raoulvdberge/refinedstorage/integration/jei/RSJEIPlugin.java b/src/main/java/com/raoulvdberge/refinedstorage/integration/jei/RSJEIPlugin.java deleted file mode 100755 index 143f17baaa..0000000000 --- a/src/main/java/com/raoulvdberge/refinedstorage/integration/jei/RSJEIPlugin.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.raoulvdberge.refinedstorage.integration.jei; -/* -import mezz.jei.api.IJeiRuntime; -import mezz.jei.api.IModPlugin; -import mezz.jei.api.IModRegistry; -import mezz.jei.api.JEIPlugin; - -@JEIPlugin -public class RSJEIPlugin implements IModPlugin { - public static RSJEIPlugin INSTANCE; - - private IJeiRuntime runtime; - - @Override - public void register(IModRegistry registry) { - INSTANCE = this; - - registry.getRecipeTransferRegistry().addUniversalRecipeTransferHandler(new RecipeTransferHandlerGrid()); - - registry.addAdvancedGuiHandlers(new AdvancedGuiHandler()); - - registry.addRecipeRegistryPlugin(new RecipeRegistryPluginCover()); - registry.addRecipeRegistryPlugin(new RecipeRegistryPluginHollowCover()); - - // TODO: https://github.com/mezz/JustEnoughItems/issues/1307 - // registry.addGhostIngredientHandler(GuiBase.class, new GhostIngredientHandler()); - } - - @Override - public void onRuntimeAvailable(IJeiRuntime runtime) { - this.runtime = runtime; - } - - public IJeiRuntime getRuntime() { - return runtime; - } -} -*/ \ No newline at end of file diff --git a/src/main/java/com/raoulvdberge/refinedstorage/integration/jei/RSJeiPlugin.java b/src/main/java/com/raoulvdberge/refinedstorage/integration/jei/RSJeiPlugin.java new file mode 100755 index 0000000000..5b65f1a144 --- /dev/null +++ b/src/main/java/com/raoulvdberge/refinedstorage/integration/jei/RSJeiPlugin.java @@ -0,0 +1,39 @@ +package com.raoulvdberge.refinedstorage.integration.jei; + +import com.raoulvdberge.refinedstorage.RS; +import com.raoulvdberge.refinedstorage.screen.BaseScreen; +import mezz.jei.api.IModPlugin; +import mezz.jei.api.JeiPlugin; +import mezz.jei.api.registration.IGuiHandlerRegistration; +import mezz.jei.api.runtime.IJeiRuntime; +import net.minecraft.util.ResourceLocation; + +@JeiPlugin +public class RSJeiPlugin implements IModPlugin { + private static final ResourceLocation ID = new ResourceLocation(RS.ID, "plugin"); + + public static IJeiRuntime RUNTIME; + + // TODO registry.getRecipeTransferRegistry().addUniversalRecipeTransferHandler(new RecipeTransferHandlerGrid()); + + // TODO registry.addRecipeRegistryPlugin(new RecipeRegistryPluginCover()); + // TODO registry.addRecipeRegistryPlugin(new RecipeRegistryPluginHollowCover()); + + // TODO: https://github.com/mezz/JustEnoughItems/issues/1307 + // registry.addGhostIngredientHandler(GuiBase.class, new GhostIngredientHandler()); + + @Override + public ResourceLocation getPluginUid() { + return ID; + } + + @Override + public void registerGuiHandlers(IGuiHandlerRegistration registration) { + registration.addGuiContainerHandler(BaseScreen.class, new GuiContainerHandler()); + } + + @Override + public void onRuntimeAvailable(IJeiRuntime runtime) { + RUNTIME = runtime; + } +} diff --git a/src/main/java/com/raoulvdberge/refinedstorage/screen/GuiCrafterManager.java b/src/main/java/com/raoulvdberge/refinedstorage/screen/GuiCrafterManager.java index 4ff3016bc7..0c9b657ae9 100644 --- a/src/main/java/com/raoulvdberge/refinedstorage/screen/GuiCrafterManager.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/screen/GuiCrafterManager.java @@ -115,7 +115,11 @@ public void onPostInit(int x, int y) { if (searchField == null) { searchField = new SearchWidget(font, sx, sy, 88 - 6); - searchField.func_212954_a(value -> container.initSlots(null)); + searchField.func_212954_a(value -> { + searchField.updateJei(); + + container.initSlots(null); + }); searchField.setMode(crafterManager.getSearchBoxMode()); } else { searchField.x = sx; diff --git a/src/main/java/com/raoulvdberge/refinedstorage/screen/grid/GridScreen.java b/src/main/java/com/raoulvdberge/refinedstorage/screen/grid/GridScreen.java index 63c2d31264..2ee6794858 100644 --- a/src/main/java/com/raoulvdberge/refinedstorage/screen/grid/GridScreen.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/screen/grid/GridScreen.java @@ -104,7 +104,9 @@ public void onPostInit(int x, int y) { if (searchField == null) { searchField = new SearchWidget(font, sx, sy, 88 - 6); searchField.func_212954_a(value -> { - this.getView().sort(); // Use getter since this view can be replaced. + searchField.updateJei(); + + getView().sort(); // Use getter since this view can be replaced. }); searchField.setMode(grid.getSearchBoxMode()); } else { diff --git a/src/main/java/com/raoulvdberge/refinedstorage/screen/widget/SearchWidget.java b/src/main/java/com/raoulvdberge/refinedstorage/screen/widget/SearchWidget.java index 51c2c9e630..e74e8d2920 100644 --- a/src/main/java/com/raoulvdberge/refinedstorage/screen/widget/SearchWidget.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/screen/widget/SearchWidget.java @@ -2,6 +2,8 @@ import com.raoulvdberge.refinedstorage.RSKeyBindings; import com.raoulvdberge.refinedstorage.api.network.grid.IGrid; +import com.raoulvdberge.refinedstorage.integration.jei.JeiIntegration; +import com.raoulvdberge.refinedstorage.integration.jei.RSJeiPlugin; import com.raoulvdberge.refinedstorage.screen.BaseScreen; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.widget.TextFieldWidget; @@ -22,12 +24,12 @@ public SearchWidget(FontRenderer fontRenderer, int x, int y, int width) { this.setEnableBackgroundDrawing(false); this.setVisible(true); this.setTextColor(16777215); + } - /* TODO this.listeners.add(() -> { - if (IntegrationJEI.isLoaded() && (mode == IGrid.SEARCH_BOX_MODE_JEI_SYNCHRONIZED || mode == IGrid.SEARCH_BOX_MODE_JEI_SYNCHRONIZED_AUTOSELECTED)) { - RSJEIPlugin.INSTANCE.getRuntime().getIngredientFilter().setFilterText(getText()); - } - });*/ + public void updateJei() { + if (JeiIntegration.isLoaded() && (mode == IGrid.SEARCH_BOX_MODE_JEI_SYNCHRONIZED || mode == IGrid.SEARCH_BOX_MODE_JEI_SYNCHRONIZED_AUTOSELECTED)) { + RSJeiPlugin.RUNTIME.getIngredientFilter().setFilterText(getText()); + } } @Override diff --git a/src/main/java/com/raoulvdberge/refinedstorage/screen/widget/sidebutton/GridSearchBoxModeSideButton.java b/src/main/java/com/raoulvdberge/refinedstorage/screen/widget/sidebutton/GridSearchBoxModeSideButton.java index 58d47b80f0..bfb267f926 100644 --- a/src/main/java/com/raoulvdberge/refinedstorage/screen/widget/sidebutton/GridSearchBoxModeSideButton.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/screen/widget/sidebutton/GridSearchBoxModeSideButton.java @@ -1,6 +1,7 @@ package com.raoulvdberge.refinedstorage.screen.widget.sidebutton; import com.raoulvdberge.refinedstorage.api.network.grid.IGrid; +import com.raoulvdberge.refinedstorage.integration.jei.JeiIntegration; import com.raoulvdberge.refinedstorage.screen.grid.GridScreen; import net.minecraft.client.resources.I18n; import net.minecraft.util.text.TextFormatting; @@ -29,11 +30,11 @@ public void onPress() { if (mode == IGrid.SEARCH_BOX_MODE_NORMAL) { mode = IGrid.SEARCH_BOX_MODE_NORMAL_AUTOSELECTED; } else if (mode == IGrid.SEARCH_BOX_MODE_NORMAL_AUTOSELECTED) { - //TODO if (IntegrationJEI.isLoaded()) { - // mode = IGrid.SEARCH_BOX_MODE_JEI_SYNCHRONIZED; - //} else { + if (JeiIntegration.isLoaded()) { + mode = IGrid.SEARCH_BOX_MODE_JEI_SYNCHRONIZED; + } else { mode = IGrid.SEARCH_BOX_MODE_NORMAL; - //} + } } else if (mode == IGrid.SEARCH_BOX_MODE_JEI_SYNCHRONIZED) { mode = IGrid.SEARCH_BOX_MODE_JEI_SYNCHRONIZED_AUTOSELECTED; } else if (mode == IGrid.SEARCH_BOX_MODE_JEI_SYNCHRONIZED_AUTOSELECTED) {