diff --git a/READNE_CN.md b/READNE_CN.md index e39e234..19bb5ba 100644 --- a/READNE_CN.md +++ b/READNE_CN.md @@ -20,7 +20,7 @@ NotEnoughEnergistics 是[Just Enough Energistics](https://www.curseforge.com/min - 允许你设置mod优先级列表,优先使用该mod的物品 - 你可以使用ctrl + 鼠标滚轮来修改样板的输入/输出数量 - 你可以使用shift + 鼠标滚轮来选择材料 -- 你可以使用shift + 点击[?]按钮来在合成终端中请求有配方的缺失材料(alt + 点击[?]来跳过预览) +- 你可以使用ctrl + 点击[?]按钮来在合成终端中请求有配方的缺失材料(alt + 点击[?]来跳过预览) ## 当前支持的Mod列表: diff --git a/gradle.properties b/gradle.properties index 6df7348..4a4b3bd 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.2.16 +mod_version=1.2.17 forge_version=10.13.4.1614 mod_group=com.github.vfyjxf.neenergistics mod_id=neenergistics diff --git a/src/main/java/com/github/vfyjxf/nee/NEINeeConfig.java b/src/main/java/com/github/vfyjxf/nee/NEINeeConfig.java index 1b18b18..f250b99 100644 --- a/src/main/java/com/github/vfyjxf/nee/NEINeeConfig.java +++ b/src/main/java/com/github/vfyjxf/nee/NEINeeConfig.java @@ -5,6 +5,9 @@ import appeng.client.gui.implementations.GuiPatternTerm; import appeng.client.gui.implementations.GuiPatternTermEx; import codechicken.nei.api.API; import codechicken.nei.api.IConfigureNEI; +import codechicken.nei.guihook.GuiContainerManager; +import com.github.vfyjxf.nee.client.NEEContainerDrawHandler; +import com.github.vfyjxf.nee.config.NEEConfig; import com.github.vfyjxf.nee.nei.NEECraftingHandler; import com.github.vfyjxf.nee.nei.NEECraftingHelper; import com.github.vfyjxf.nee.processor.IRecipeProcessor; @@ -42,6 +45,10 @@ public class NEINeeConfig implements IConfigureNEI { API.registerGuiOverlayHandler(GuiPatternTerm.class, new NEECraftingHandler(), ident); } + if(NEEConfig.drawHighlight){ + GuiContainerManager.addDrawHandler(NEEContainerDrawHandler.instance); + } + installCraftingTermSupport(); installPatternTerminalExSupport(identifiers); diff --git a/src/main/java/com/github/vfyjxf/nee/client/NEEContainerDrawHandler.java b/src/main/java/com/github/vfyjxf/nee/client/NEEContainerDrawHandler.java new file mode 100644 index 0000000..feaeefc --- /dev/null +++ b/src/main/java/com/github/vfyjxf/nee/client/NEEContainerDrawHandler.java @@ -0,0 +1,188 @@ +package com.github.vfyjxf.nee.client; + +import appeng.client.gui.implementations.GuiCraftingTerm; +import appeng.client.gui.implementations.GuiPatternTerm; +import codechicken.nei.NEIClientConfig; +import codechicken.nei.PositionedStack; +import codechicken.nei.guihook.IContainerDrawHandler; +import codechicken.nei.recipe.GuiRecipe; +import codechicken.nei.recipe.IRecipeHandler; +import com.github.vfyjxf.nee.utils.GuiUtils; +import com.github.vfyjxf.nee.utils.Ingredient; +import com.github.vfyjxf.nee.utils.IngredientTracker; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.relauncher.ReflectionHelper; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.*; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.resources.I18n; +import net.minecraft.inventory.Slot; +import net.minecraft.util.EnumChatFormatting; +import net.minecraftforge.client.event.GuiScreenEvent; +import org.lwjgl.input.Keyboard; +import org.lwjgl.input.Mouse; + +import java.awt.*; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; + +public class NEEContainerDrawHandler implements IContainerDrawHandler { + + public static NEEContainerDrawHandler instance = new NEEContainerDrawHandler(); + + private final Field overlayButtonsField; + private final Field handlerField; + private Method recipesPerPageMethod; + + public NEEContainerDrawHandler() { + 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(); + } + } + + @Override + public void onPreDraw(GuiContainer gui) { + + } + + @Override + public void renderObjects(GuiContainer gui, int mouseX, int mouseY) { + + } + + @Override + public void postRenderObjects(GuiContainer gui, int mouseX, int mouseY) { + + } + + @Override + public void renderSlotUnderlay(GuiContainer gui, Slot slot) { + + } + + @Override + public void renderSlotOverlay(GuiContainer gui, Slot slot) { + if (gui instanceof GuiRecipe) { + Minecraft mc = Minecraft.getMinecraft(); + final ScaledResolution scaledresolution = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); + int i = scaledresolution.getScaledWidth(); + int j = scaledresolution.getScaledHeight(); + final int mouseX = Mouse.getX() * i / mc.displayWidth; + final int mouseY = j - Mouse.getY() * j / mc.displayHeight - 1; + GuiRecipe guiRecipe = (GuiRecipe) gui; + GuiButton[] overlayButtons = null; + try { + overlayButtons = (GuiButton[]) this.overlayButtonsField.get(guiRecipe); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + 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(); + } + if (recipesPerPage >= 0 && handler != null) { + int recipeIndex = guiRecipe.page * recipesPerPage + button.id - OVERLAY_BUTTON_ID_START; + List ingredients = handler.getIngredientStacks(recipeIndex); + IngredientTracker tracker = createTracker(guiRecipe.firstGui, ingredients); + + for (int var1 = 0; var1 < ingredients.size(); var1++) { + PositionedStack stack = ingredients.get(var1); + Ingredient ingredient = tracker.getIngredients().get(var1); + Slot stackSlot = guiRecipe.slotcontainer.getSlotWithStack(stack, guiRecipe.getRecipePosition(recipeIndex).x, guiRecipe.getRecipePosition(recipeIndex).y); + if (stackSlot.equals(slot)) { + GuiContainer firstGui = guiRecipe.firstGui; + boolean renderAutoAbleItems = firstGui instanceof GuiCraftingTerm && ingredient.isCraftable() && ingredient.requiresToCraft(); + boolean renderCraftableItems = (firstGui instanceof GuiPatternTerm || GuiUtils.isPatternTermExGui(firstGui)) && ingredient.isCraftable(); + boolean renderMissingItems = firstGui instanceof GuiCraftingTerm && !ingredient.isCraftable() && ingredient.requiresToCraft(); + if (renderAutoAbleItems || renderCraftableItems) { + Gui.drawRect(slot.xDisplayPosition, slot.yDisplayPosition, + slot.xDisplayPosition + 16, slot.yDisplayPosition + 16, + new Color(0.0f, 0.0f, 1.0f, 0.4f).getRGB()); + } else if (renderMissingItems) { + Gui.drawRect(slot.xDisplayPosition, slot.yDisplayPosition, + slot.xDisplayPosition + 16, slot.yDisplayPosition + 16, + new Color(1.0f, 0.0f, 0.0f, 0.4f).getRGB()); + } + } + } + } + } + } + } + } + } + + @SubscribeEvent + public void onDrawScreen(GuiScreenEvent.DrawScreenEvent.Post event) { + if (event.gui instanceof GuiRecipe) { + GuiRecipe guiRecipe = (GuiRecipe) event.gui; + GuiButton[] overlayButtons = null; + try { + overlayButtons = (GuiButton[]) ReflectionHelper.findField(GuiRecipe.class, "overlayButtons").get(guiRecipe); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + if (overlayButtons != null) { + for (GuiButton button : overlayButtons) { + if (button.visible && button.enabled && GuiUtils.isMouseOverButton(button, event.mouseX, event.mouseY)) { + drawCraftingHelperTooltip(guiRecipe, event.mouseX, event.mouseY); + } + } + } + } + + } + + private void drawCraftingHelperTooltip(GuiRecipe guiRecipe, int mouseX, int mouseY) { + List tooltips = new ArrayList<>(); + if (guiRecipe.firstGui instanceof GuiCraftingTerm) { + tooltips.add(String.format("%s" + EnumChatFormatting.GRAY + " + " + + EnumChatFormatting.BLUE + I18n.format("neenergistics.gui.tooltip.helper.crafting"), + EnumChatFormatting.YELLOW + Keyboard.getKeyName(NEIClientConfig.getKeyBinding("nee.preview")))); + } + if (guiRecipe.firstGui instanceof GuiPatternTerm || GuiUtils.isPatternTermExGui(guiRecipe.firstGui)) { + tooltips.add(EnumChatFormatting.BLUE + I18n.format("neenergistics.gui.tooltip.helper.pattern")); + } + try { + ReflectionHelper.findMethod(GuiScreen.class, guiRecipe, + new String[]{"drawHoveringText"}, + List.class, + int.class, + int.class, + FontRenderer.class).invoke(guiRecipe, tooltips, mouseX, mouseY, Minecraft.getMinecraft().fontRenderer); + } catch (IllegalAccessException | InvocationTargetException e) { + e.printStackTrace(); + } + } + + private IngredientTracker createTracker(GuiContainer firstGui, List ingredients) { + IngredientTracker tracker = new IngredientTracker(firstGui, ingredients); + + //check stacks in player's inventory and crafting grid + for (Slot slot : (List) firstGui.inventorySlots.inventorySlots) { + boolean canGetStack = slot != null && slot.getHasStack() && slot.getStack().stackSize > 0 && slot.isItemValid(slot.getStack()) && slot.canTakeStack(Minecraft.getMinecraft().thePlayer); + if (canGetStack) { + tracker.addIngredientStack(slot.getStack()); + } + } + + return tracker; + } + +} diff --git a/src/main/java/com/github/vfyjxf/nee/config/NEEConfig.java b/src/main/java/com/github/vfyjxf/nee/config/NEEConfig.java index 3bba6a1..d1a0ecd 100644 --- a/src/main/java/com/github/vfyjxf/nee/config/NEEConfig.java +++ b/src/main/java/com/github/vfyjxf/nee/config/NEEConfig.java @@ -21,6 +21,7 @@ public class NEEConfig { public static boolean noShift = true; public static boolean matchOtherItems = false; + public static boolean drawHighlight = true; public static void loadConfig(File configFile) { config = new Configuration(configFile); @@ -42,6 +43,9 @@ public class NEEConfig { matchOtherItems = config.get("client", "matchOnCraftableItems", false, "If false, Crafting Helper will not match other items").getBoolean(); + drawHighlight = config.get("client","drawHighlight",true, + "if true,it will draw highlight for missing items and item which can autocraft in nei").getBoolean(); + if (config.hasChanged()) config.save(); } 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 302d871..b003f30 100644 --- a/src/main/java/com/github/vfyjxf/nee/nei/NEECraftingHelper.java +++ b/src/main/java/com/github/vfyjxf/nee/nei/NEECraftingHelper.java @@ -76,6 +76,9 @@ public class NEECraftingHelper implements IOverlayHandler { return tracker; } + /** + * Copied from GTNewHorizons/Applied-Energistics-2-Unofficial + */ private void moveItem(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex) { try { final List ingredients = recipe.getIngredientStacks(recipeIndex); @@ -89,6 +92,9 @@ public class NEECraftingHelper implements IOverlayHandler { } } + /** + * Copied from GTNewHorizons/Applied-Energistics-2-Unofficial + */ private boolean testSize(final NBTTagCompound recipe) throws IOException { final ByteArrayOutputStream bytes = new ByteArrayOutputStream(); final DataOutputStream outputStream = new DataOutputStream(bytes); @@ -96,6 +102,9 @@ public class NEECraftingHelper implements IOverlayHandler { return bytes.size() > 3 * 1024; } + /** + * Copied from GTNewHorizons/Applied-Energistics-2-Unofficial + */ private NBTTagCompound packIngredients(GuiContainer gui, List ingredients, boolean limited) throws IOException { final NBTTagCompound recipe = new NBTTagCompound(); for (final PositionedStack positionedStack : ingredients) { diff --git a/src/main/java/com/github/vfyjxf/nee/proxy/ClientProxy.java b/src/main/java/com/github/vfyjxf/nee/proxy/ClientProxy.java index 3f31e2d..8c06f1e 100644 --- a/src/main/java/com/github/vfyjxf/nee/proxy/ClientProxy.java +++ b/src/main/java/com/github/vfyjxf/nee/proxy/ClientProxy.java @@ -2,6 +2,7 @@ package com.github.vfyjxf.nee.proxy; import com.github.vfyjxf.nee.NEECommands; import com.github.vfyjxf.nee.client.GuiHandler; +import com.github.vfyjxf.nee.client.NEEContainerDrawHandler; import com.github.vfyjxf.nee.config.NEEConfig; import com.github.vfyjxf.nee.nei.NEECraftingHelper; import cpw.mods.fml.common.FMLCommonHandler; @@ -19,5 +20,8 @@ public class ClientProxy extends CommonProxy { if (NEEConfig.noShift) { MinecraftForge.EVENT_BUS.register(new NEECraftingHelper()); } + if(NEEConfig.drawHighlight){ + MinecraftForge.EVENT_BUS.register(NEEContainerDrawHandler.instance); + } } } diff --git a/src/main/java/com/github/vfyjxf/nee/utils/GuiUtils.java b/src/main/java/com/github/vfyjxf/nee/utils/GuiUtils.java index 56917e3..1323792 100644 --- a/src/main/java/com/github/vfyjxf/nee/utils/GuiUtils.java +++ b/src/main/java/com/github/vfyjxf/nee/utils/GuiUtils.java @@ -10,6 +10,7 @@ import com.github.vfyjxf.nee.network.NEENetworkHandler; import com.github.vfyjxf.nee.network.packet.PacketRecipeItemChange; import cpw.mods.fml.relauncher.ReflectionHelper; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.inventory.Container; @@ -89,6 +90,13 @@ public class GuiUtils { return stacks; } + public static boolean isMouseOverButton(GuiButton button, int mouseX, int mouseY) { + return mouseX >= button.xPosition && + mouseY >= button.yPosition && + mouseX < button.xPosition + button.width && + mouseY < button.yPosition + button.height; + } + public static void handleRecipeIngredientChange(Slot currentSlot, int dWheel) { PositionedStack currentIngredients = NEECraftingHandler.ingredients.get("input" + currentSlot.getSlotIndex()); diff --git a/src/main/java/com/github/vfyjxf/nee/utils/Ingredient.java b/src/main/java/com/github/vfyjxf/nee/utils/Ingredient.java index 862327b..ff0dbe9 100644 --- a/src/main/java/com/github/vfyjxf/nee/utils/Ingredient.java +++ b/src/main/java/com/github/vfyjxf/nee/utils/Ingredient.java @@ -5,11 +5,13 @@ import net.minecraft.item.ItemStack; public class Ingredient { + private PositionedStack ingredients; private ItemStack craftableIngredient; - private final int requireCount; - private int currentCount = 0; + private final long requireCount; + private long currentCount = 0; public Ingredient(PositionedStack ingredients) { + this.ingredients = ingredients; this.requireCount = ingredients.items[0].stackSize; } @@ -17,19 +19,31 @@ public class Ingredient { this.craftableIngredient = craftableIngredient; } + public PositionedStack getIngredients() { + return ingredients; + } + public ItemStack getCraftableIngredient() { return craftableIngredient; } - public int getMissingCount(){ + public long getMissingCount(){ return requireCount - currentCount; } + public long getRequireCount() { + return requireCount; + } + + public boolean isCraftable(){ + return this.craftableIngredient != null; + } + public boolean requiresToCraft(){ return this.getMissingCount() > 0; } - public void addCurrentCount(int count){ + public void addCurrentCount(long count){ currentCount += count; } diff --git a/src/main/java/com/github/vfyjxf/nee/utils/IngredientTracker.java b/src/main/java/com/github/vfyjxf/nee/utils/IngredientTracker.java index 77a4738..05bc4e8 100644 --- a/src/main/java/com/github/vfyjxf/nee/utils/IngredientTracker.java +++ b/src/main/java/com/github/vfyjxf/nee/utils/IngredientTracker.java @@ -51,6 +51,29 @@ public class IngredientTracker { } } + public IngredientTracker(GuiContainer gui, List requiredIngredients) { + IItemList aeItemStacks = this.getAEStacks(gui); + for (PositionedStack positionedStack : requiredIngredients) { + this.ingredients.add(new Ingredient(positionedStack)); + } + for (Ingredient ingredient : this.ingredients) { + for (IAEItemStack stack : aeItemStacks) { + if (ingredient.getIngredients().contains(stack.getItemStack())) { + if (ingredient.getCraftableIngredient() == null && stack.isCraftable()) { + ingredient.setCraftableIngredient(stack.getItemStack()); + } + if (stack.getStackSize() > 0) { + ingredient.addCurrentCount(stack.getStackSize()); + if (ingredient.requiresToCraft()) { + stack.setStackSize(0); + } else { + stack.setStackSize(stack.getStackSize() - ingredient.getRequireCount()); + } + } + } + } + } + } private List getCraftableStacks(GuiContainer gui) { List craftableAEItemSafcks = new ArrayList<>(); @@ -64,7 +87,7 @@ public class IngredientTracker { if (list != null) { for (IAEItemStack stack : list) { if (stack.isCraftable()) { - craftableAEItemSafcks.add(stack); + craftableAEItemSafcks.add(stack.copy()); } } } @@ -75,20 +98,26 @@ public class IngredientTracker { IItemList list = AEApi.instance().storage().createItemList(); try { ItemRepo repo = (ItemRepo) ReflectionHelper.findField(GuiMEMonitorable.class, "repo").get(gui); - list = (IItemList) ReflectionHelper.findField(ItemRepo.class, "list").get(repo); + for (IAEItemStack stack : (IItemList) ReflectionHelper.findField(ItemRepo.class, "list").get(repo)) { + list.add(stack.copy()); + } } catch (IllegalAccessException e) { e.printStackTrace(); } return list; } + public List getIngredients() { + return ingredients; + } + public List getRequireToCraftStacks() { List requireToCraftStacks = new ArrayList<>(); for (Ingredient ingredient : this.ingredients) { ItemStack craftableStack = ingredient.getCraftableIngredient(); if (craftableStack != null && ingredient.requiresToCraft()) { ItemStack requireStack = craftableStack.copy(); - requireStack.stackSize = ingredient.getMissingCount(); + requireStack.stackSize = (int) ingredient.getMissingCount(); requireToCraftStacks.add(requireStack); } } diff --git a/src/main/resources/assets/neenergistics/lang/en_US.lang b/src/main/resources/assets/neenergistics/lang/en_US.lang index 0a43805..6c9c9b8 100644 --- a/src/main/resources/assets/neenergistics/lang/en_US.lang +++ b/src/main/resources/assets/neenergistics/lang/en_US.lang @@ -1,3 +1,5 @@ +neenergistics.gui.tooltip.helper.crafting=click to request missing items +neenergistics.gui.tooltip.helper.pattern=Autocrafting available nei.options.keys.nee=NotEnoughEnergistics nei.options.keys.nee.count=Change Item Count nei.options.keys.nee.ingredient=Choose ingredient diff --git a/src/main/resources/assets/neenergistics/lang/zh_CN.lang b/src/main/resources/assets/neenergistics/lang/zh_CN.lang index b8c3598..3ce5867 100644 --- a/src/main/resources/assets/neenergistics/lang/zh_CN.lang +++ b/src/main/resources/assets/neenergistics/lang/zh_CN.lang @@ -1,3 +1,5 @@ +neenergistics.gui.tooltip.helper.crafting=点击以请求缺失的物品 +neenergistics.gui.tooltip.helper.pattern=自动合成已可用 nei.options.keys.nee=NotEnoughEnergistics nei.options.keys.nee.count=修改物品数量 nei.options.keys.nee.ingredient=选择材料