mirror of
https://github.com/GTNewHorizons/NotEnoughEnergistics.git
synced 2026-11-18 11:19:11 +00:00
Change read recipeIndex from GuiRecipe (#38)
Co-authored-by: slprime <[email protected]>
This commit is contained in:
1 parent
b4ecadff7f
commit
b60727c5f6
2 files changed
+25
-13
No files matched your search
@@ -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;
|
||||
@@ -62,9 +62,9 @@ public class 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;
|
||||
}
|
||||
@@ -201,9 +201,13 @@ public class NEEContainerDrawHandler {
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import net.minecraftforge.oredict.OreDictionary;
|
||||
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;
|
||||
@@ -274,26 +275,33 @@ public class NEECraftingHelper implements IOverlayHandler {
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user