diff --git a/gradle.properties b/gradle.properties index af9c12b..a9247a4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ org.gradle.daemon=false mc_version=1.7.10 nei_version=2.1.6-GTNH ae2_version=rv3-beta-52-GTNH -mod_version=1.3.1 +mod_version=1.3.2 forge_version=10.13.4.1614 mod_group=com.github.vfyjxf.neenergistics mod_id=neenergistics diff --git a/libs/NotEnoughItems-1.7.10-1.0.5.120-universal.jar b/libs/NotEnoughItems-1.7.10-1.0.5.120-universal.jar new file mode 100644 index 0000000..5efa527 Binary files /dev/null and b/libs/NotEnoughItems-1.7.10-1.0.5.120-universal.jar differ diff --git a/src/main/java/com/github/vfyjxf/nee/client/GuiHandler.java b/src/main/java/com/github/vfyjxf/nee/client/GuiHandler.java index 3eceb43..e212eb7 100644 --- a/src/main/java/com/github/vfyjxf/nee/client/GuiHandler.java +++ b/src/main/java/com/github/vfyjxf/nee/client/GuiHandler.java @@ -65,6 +65,9 @@ public class GuiHandler { NEENetworkHandler.getInstance().sendToServer(new PacketCraftingHelper(tracker.getRequireToCraftStacks().get(stackIndex), noPreview)); stackIndex++; } + } else if (!isGuiCraftingTerm && isGuiCraftConfirm && tracker != null) { + //Prevent opening the gui during normal use + tracker = null; } } diff --git a/src/main/java/com/github/vfyjxf/nee/client/NEEContainerDrawHandler.java b/src/main/java/com/github/vfyjxf/nee/client/NEEContainerDrawHandler.java index dc90eee..b943480 100644 --- a/src/main/java/com/github/vfyjxf/nee/client/NEEContainerDrawHandler.java +++ b/src/main/java/com/github/vfyjxf/nee/client/NEEContainerDrawHandler.java @@ -29,6 +29,7 @@ import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; public class NEEContainerDrawHandler implements IContainerDrawHandler { @@ -36,7 +37,6 @@ public class NEEContainerDrawHandler implements IContainerDrawHandler { public static NEEContainerDrawHandler instance = new NEEContainerDrawHandler(); private Field overlayButtonsField; - private Field handlerField; private Method recipesPerPageMethod; private boolean drawRequestTooltip; private boolean drawCraftableTooltip; @@ -65,21 +65,24 @@ public class NEEContainerDrawHandler implements IContainerDrawHandler { } + @SuppressWarnings("ALL") @Override public void renderSlotOverlay(GuiContainer gui, Slot slot) { - if (this.overlayButtonsField == null || this.handlerField == null || this.recipesPerPageMethod == null) { - this.overlayButtonsField = ReflectionHelper.findField(GuiRecipe.class, "overlayButtons"); - this.handlerField = ReflectionHelper.findField(GuiRecipe.class, "handler"); - try { - this.recipesPerPageMethod = GuiRecipe.class.getDeclaredMethod("getRecipesPerPage"); - recipesPerPageMethod.setAccessible(true); - } catch (NoSuchMethodException e) { - e.printStackTrace(); - } - } - if (NEEConfig.drawHighlight && gui instanceof GuiRecipe) { + //gtnh nei support + boolean isGtnhNei = true; + if (this.overlayButtonsField == null || this.recipesPerPageMethod == null) { + try { + this.overlayButtonsField = GuiRecipe.class.getDeclaredField("overlayButtons"); + this.recipesPerPageMethod = GuiRecipe.class.getDeclaredMethod("getRecipesPerPage"); + this.overlayButtonsField.setAccessible(true); + recipesPerPageMethod.setAccessible(true); + } catch (NoSuchMethodException | NoSuchFieldException e) { + isGtnhNei = false; + } + } + Minecraft mc = Minecraft.getMinecraft(); GuiRecipe guiRecipe = (GuiRecipe) gui; GuiContainer firstGui = guiRecipe.firstGui; @@ -91,23 +94,31 @@ public class NEEContainerDrawHandler implements IContainerDrawHandler { int j = scaledresolution.getScaledHeight(); final int mouseX = Mouse.getX() * i / mc.displayWidth; final int mouseY = j - Mouse.getY() * j / mc.displayHeight - 1; - GuiButton[] overlayButtons = null; - try { - overlayButtons = (GuiButton[]) this.overlayButtonsField.get(guiRecipe); - } catch (IllegalAccessException e) { - e.printStackTrace(); + + + List overlayButtons = null; + if (isGtnhNei) { + try { + overlayButtons = new ArrayList<>(Arrays.asList((GuiButton[]) this.overlayButtonsField.get(guiRecipe))); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } else { + overlayButtons = new ArrayList<>(Arrays.asList(guiRecipe.overlay1, guiRecipe.overlay2)); } + if (overlayButtons != null) { for (GuiButton button : overlayButtons) { if (button.visible && button.enabled && GuiUtils.isMouseOverButton(button, mouseX, mouseY)) { final int OVERLAY_BUTTON_ID_START = 4; - IRecipeHandler handler = null; - int recipesPerPage = -1; - try { - recipesPerPage = (int) this.recipesPerPageMethod.invoke(guiRecipe); - handler = (IRecipeHandler) this.handlerField.get(guiRecipe); - } catch (IllegalAccessException | InvocationTargetException e) { - e.printStackTrace(); + IRecipeHandler handler = guiRecipe.currenthandlers.get(guiRecipe.recipetype); + int recipesPerPage = 2; + if (isGtnhNei) { + try { + recipesPerPage = (int) this.recipesPerPageMethod.invoke(guiRecipe); + } catch (IllegalAccessException | InvocationTargetException e) { + e.printStackTrace(); + } } if (recipesPerPage >= 0 && handler != null) { int recipeIndex = guiRecipe.page * recipesPerPage + button.id - OVERLAY_BUTTON_ID_START; diff --git a/src/main/java/com/github/vfyjxf/nee/nei/NEECraftingHandler.java b/src/main/java/com/github/vfyjxf/nee/nei/NEECraftingHandler.java index b5dc357..f053b0c 100644 --- a/src/main/java/com/github/vfyjxf/nee/nei/NEECraftingHandler.java +++ b/src/main/java/com/github/vfyjxf/nee/nei/NEECraftingHandler.java @@ -17,6 +17,7 @@ import com.github.vfyjxf.nee.utils.ItemUtils; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.oredict.OreDictionary; import java.util.ArrayList; import java.util.HashMap; @@ -98,6 +99,12 @@ public class NEECraftingHandler implements IOverlayHandler { if (ItemUtils.isInBlackList(currentStack, recipeProcessorId, identifier)) { continue; } + + //Fix ItemStack with wrong meta + if (currentStack.getItemDamage() == OreDictionary.WILDCARD_VALUE) { + currentStack.setItemDamage(0); + } + recipeInputs.setTag("#" + inputIndex, currentStack.writeToNBT(new NBTTagCompound())); NEECraftingHandler.ingredients.put("input" + inputIndex, positionedStack); inputIndex++; @@ -107,7 +114,14 @@ public class NEECraftingHandler implements IOverlayHandler { if (outputIndex >= 4 || positionedStack == null || positionedStack.item == null) { continue; } - recipeOutputs.setTag(OUTPUT_KEY + outputIndex, positionedStack.item.writeToNBT(new NBTTagCompound())); + + ItemStack outputStack = positionedStack.item.copy(); + //Fix ItemStack with wrong meta(maybe ?) + if (outputStack.getItemDamage() == OreDictionary.WILDCARD_VALUE) { + outputStack.setItemDamage(0); + } + + recipeOutputs.setTag(OUTPUT_KEY + outputIndex, outputStack.writeToNBT(new NBTTagCompound())); outputIndex++; } } @@ -137,6 +151,11 @@ public class NEECraftingHandler implements IOverlayHandler { } } + //Fix ItemStack with wrong meta + if (stack.getItemDamage() == OreDictionary.WILDCARD_VALUE) { + stack.setItemDamage(0); + } + recipeInputs.setTag("#" + slotIndex, stack.writeToNBT(new NBTTagCompound())); NEECraftingHandler.ingredients.put("input" + slotIndex, positionedStack); } diff --git a/src/main/java/com/github/vfyjxf/nee/nei/NEECraftingHelper.java b/src/main/java/com/github/vfyjxf/nee/nei/NEECraftingHelper.java index 18ccbb4..f8d89ff 100644 --- a/src/main/java/com/github/vfyjxf/nee/nei/NEECraftingHelper.java +++ b/src/main/java/com/github/vfyjxf/nee/nei/NEECraftingHelper.java @@ -39,7 +39,10 @@ import org.lwjgl.input.Keyboard; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.IOException; +import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.Arrays; import java.util.LinkedList; import java.util.List; @@ -98,7 +101,7 @@ public class NEECraftingHelper implements IOverlayHandler { } if (packetSize >= 0) { NetworkHandler.instance.sendToServer(packet); - }else { + } else { NotEnoughEnergistics.logger.error("Can't get packet size!"); } } else if (GuiUtils.isGuiWirelessCrafting(firstGui)) { @@ -199,24 +202,31 @@ public class NEECraftingHelper implements IOverlayHandler { //make nei's transfer system doesn't require presses shift if (event.gui instanceof GuiRecipe) { GuiRecipe guiRecipe = (GuiRecipe) event.gui; - GuiButton[] overlayButtons = null; + List overlayButtons = null; final int OVERLAY_BUTTON_ID_START = 4; + boolean isGtnhNei = true; try { - overlayButtons = (GuiButton[]) ReflectionHelper.findField(GuiRecipe.class, "overlayButtons").get(guiRecipe); - } catch (IllegalAccessException e) { - e.printStackTrace(); + Field overlayButtonsField = GuiRecipe.class.getDeclaredField("overlayButtons"); + overlayButtonsField.setAccessible(true); + overlayButtons = new ArrayList<>(Arrays.asList((GuiButton[]) overlayButtonsField.get(guiRecipe))); + } catch (IllegalAccessException | NoSuchFieldException e) { + isGtnhNei = false; } - if (overlayButtons != null && event.button.id >= OVERLAY_BUTTON_ID_START && event.button.id < OVERLAY_BUTTON_ID_START + overlayButtons.length) { + if (!isGtnhNei) { + overlayButtons = new ArrayList<>(Arrays.asList(guiRecipe.overlay1, guiRecipe.overlay2)); + } + if (event.button.id >= OVERLAY_BUTTON_ID_START && event.button.id < OVERLAY_BUTTON_ID_START + overlayButtons.size()) { boolean isPatternTerm = guiRecipe.firstGui instanceof GuiPatternTerm || GuiUtils.isPatternTermExGui(guiRecipe.firstGui); boolean isCraftingTerm = guiRecipe.firstGui instanceof GuiCraftingTerm || GuiUtils.isGuiWirelessCrafting(guiRecipe.firstGui); if (isCraftingTerm || isPatternTerm) { - int recipesPerPage = -1; - IRecipeHandler handler = null; - try { - recipesPerPage = (int) ReflectionHelper.findMethod(GuiRecipe.class, guiRecipe, new String[]{"getRecipesPerPage"}).invoke(guiRecipe); - handler = (IRecipeHandler) ReflectionHelper.findField(GuiRecipe.class, "handler").get(guiRecipe); - } catch (IllegalAccessException | InvocationTargetException e) { - e.printStackTrace(); + int recipesPerPage = 2; + IRecipeHandler handler = guiRecipe.currenthandlers.get(guiRecipe.recipetype); + if (isGtnhNei) { + try { + recipesPerPage = (int) ReflectionHelper.findMethod(GuiRecipe.class, guiRecipe, new String[]{"getRecipesPerPage"}).invoke(guiRecipe); + } catch (IllegalAccessException | InvocationTargetException e) { + e.printStackTrace(); + } } if (recipesPerPage >= 0 && handler != null) { int recipe = guiRecipe.page * recipesPerPage + event.button.id - OVERLAY_BUTTON_ID_START;