Skip to content

Commit

Permalink
Re-add JEI sync in Grid + JEI ingredient under mouse handler
Browse files Browse the repository at this point in the history
  • Loading branch information
raoulvdberge committed Oct 15, 2019
1 parent 7859ca4 commit f46ac1e
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 112 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<BaseScreen> {
@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;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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");
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit f46ac1e

Please sign in to comment.