Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change read recipeIndex from GuiRecipe #38

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class NEEContainerDrawHandler {
private int oldType;

public Field overlayButtonsField;
public Method recipesPerPageMethod;
public Method getRecipeIndicesMethod;
private boolean drawRequestTooltip;
private boolean drawMissingTooltip;
private boolean drawCraftableTooltip;
Expand All @@ -62,9 +62,9 @@ public NEEContainerDrawHandler() {
isGtnhNei = true;
try {
this.overlayButtonsField = GuiRecipe.class.getDeclaredField("overlayButtons");
this.recipesPerPageMethod = GuiRecipe.class.getDeclaredMethod("getRecipesPerPage");
this.getRecipeIndicesMethod = GuiRecipe.class.getDeclaredMethod("getRecipeIndices");
this.overlayButtonsField.setAccessible(true);
this.recipesPerPageMethod.setAccessible(true);
this.getRecipeIndicesMethod.setAccessible(true);
} catch (NoSuchMethodException | NoSuchFieldException e) {
isGtnhNei = false;
}
Expand Down Expand Up @@ -201,9 +201,13 @@ private void initIngredientTracker(GuiRecipe gui) {
int recipeIndex = -1;
if (isGtnhNei) {
try {
int OVERLAY_BUTTON_ID_START = 4;
recipeIndex = gui.page * (int) recipesPerPageMethod.invoke(gui) + overlayButton.id
- OVERLAY_BUTTON_ID_START;
final int OVERLAY_BUTTON_ID_START = 4;
final List<Integer> indices = (List) getRecipeIndicesMethod.invoke(gui);
final int refIndex = overlayButton.id - OVERLAY_BUTTON_ID_START;

if (refIndex >= 0 && refIndex < indices.size()) {
recipeIndex = indices.get(refIndex);
}
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
Expand Down
22 changes: 15 additions & 7 deletions src/main/java/com/github/vfyjxf/nee/nei/NEECraftingHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.lwjgl.input.Keyboard;

import com.github.vfyjxf.nee.NotEnoughEnergistics;
import com.github.vfyjxf.nee.client.NEEContainerDrawHandler;
import com.github.vfyjxf.nee.config.NEEConfig;
import com.github.vfyjxf.nee.network.NEENetworkHandler;
import com.github.vfyjxf.nee.network.packet.PacketOpenCraftAmount;
Expand Down Expand Up @@ -274,26 +275,33 @@ public void onActionPerformedEventPre(GuiScreenEvent.ActionPerformedEvent.Pre ev
boolean isPatternTerm = isPatternTerm(guiRecipe.firstGui);
boolean isCraftingTerm = isGuiCraftingTerm(guiRecipe.firstGui);
if (isCraftingTerm || isPatternTerm) {
int recipesPerPage = 2;
IRecipeHandler handler = (IRecipeHandler) guiRecipe.currenthandlers.get(guiRecipe.recipetype);
int recipeIndex = -1;
if (isGtnhNei) {
try {
recipesPerPage = (int) ReflectionHelper
.findMethod(GuiRecipe.class, guiRecipe, new String[] { "getRecipesPerPage" })
final List<Integer> indices = (List) NEEContainerDrawHandler.instance.getRecipeIndicesMethod
.invoke(guiRecipe);
final int refIndex = event.button.id - OVERLAY_BUTTON_ID_START;

if (refIndex >= 0 && refIndex < indices.size()) {
recipeIndex = indices.get(refIndex);
}
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
} else {
int recipesPerPage = 2;
recipeIndex = guiRecipe.page * recipesPerPage + event.button.id - OVERLAY_BUTTON_ID_START;
}
if (recipesPerPage >= 0 && handler != null) {
int recipe = guiRecipe.page * recipesPerPage + event.button.id - OVERLAY_BUTTON_ID_START;

if (handler != null && recipeIndex >= 0 && recipeIndex < handler.numRecipes()) {
final IOverlayHandler overlayHandler = handler
.getOverlayHandler(guiRecipe.firstGui, recipe);
.getOverlayHandler(guiRecipe.firstGui, recipeIndex);
Minecraft.getMinecraft().displayGuiScreen(guiRecipe.firstGui);
overlayHandler.overlayRecipe(
guiRecipe.firstGui,
(IRecipeHandler) guiRecipe.currenthandlers.get(guiRecipe.recipetype),
recipe,
recipeIndex,
NEIClientUtils.shiftKey());
event.setCanceled(true);
}
Expand Down
Loading