mirror of
https://github.com/GTNewHorizons/NotEnoughEnergistics.git
synced 2026-11-18 03:15:03 +00:00
1 parent
c211c1e1e4
commit
ee5cd4568f
6 files changed
+82
-39
No files matched your search
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<GuiButton> 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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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<GuiButton> 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;
|
||||
|
||||
Reference in new issue
Block a user