diff --git a/README.md b/README.md index d12dc66..ca0b8da 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ This mod removes that functionality and allows the player to use NEI's transfer - Allow you to add item blackList and item priority list, if item in them, it will not be transferred / transfer it first.(use /nee RecipeProcessor to get RecipeProcessor and identifier in log) - Allow you to add mod priority list,if the mod's has this item,it will be use first. - You can use the mouse wheel to change the Pattern item input/output amount. +- You can use shift + mouse wheel to choose ingredient. ## Compatible Modslist as followed: diff --git a/READNE_CN.md b/READNE_CN.md index bdde955..8e2727d 100644 --- a/READNE_CN.md +++ b/READNE_CN.md @@ -19,6 +19,7 @@ NotEnoughEnergistics 是[Just Enough Energistics](https://www.curseforge.com/min - 允许你设置转换黑名单和转换优先名单,如对应物品在里面,那么他们将不会被转移/优先被转移 - 允许你设置mod优先级列表,优先使用该mod的物品 - 你可以使用鼠标滚轮来修改样板的输入/输出数量 +- 你可以使用shift + 鼠标滚轮来选择材料 ## 当前支持的Mod列表: diff --git a/gradle.properties b/gradle.properties index fcf8b78..e28913a 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.10 +mod_version=1.2.11 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 682442e..932b18c 100644 --- a/src/main/java/com/github/vfyjxf/nee/NEINeeConfig.java +++ b/src/main/java/com/github/vfyjxf/nee/NEINeeConfig.java @@ -11,7 +11,9 @@ import cpw.mods.fml.common.Loader; import thaumicenergistics.client.gui.GuiKnowledgeInscriber; import wanion.avaritiaddons.block.extremeautocrafter.GuiExtremeAutoCrafter; -import java.util.*; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; public class NEINeeConfig implements IConfigureNEI { diff --git a/src/main/java/com/github/vfyjxf/nee/NotEnoughEnergistics.java b/src/main/java/com/github/vfyjxf/nee/NotEnoughEnergistics.java index 64f5e80..ad944d4 100644 --- a/src/main/java/com/github/vfyjxf/nee/NotEnoughEnergistics.java +++ b/src/main/java/com/github/vfyjxf/nee/NotEnoughEnergistics.java @@ -58,14 +58,19 @@ public class NotEnoughEnergistics { public void onRenderTick(TickEvent.RenderTickEvent event) { if (event.phase == TickEvent.Phase.START) { Minecraft mc = Minecraft.getMinecraft(); - int i = Mouse.getDWheel(); - if (i != 0 && mc.currentScreen instanceof GuiPatternTerm || GuiUtils.isPatternTermExGui(mc.currentScreen)) { + int dWheel = Mouse.getDWheel(); + if (dWheel != 0 && mc.currentScreen instanceof GuiPatternTerm || GuiUtils.isPatternTermExGui(mc.currentScreen)) { int x = Mouse.getEventX() * mc.currentScreen.width / mc.displayWidth; int y = mc.currentScreen.height - Mouse.getEventY() * mc.currentScreen.height / mc.displayHeight - 1; Slot currentSlot = GuiUtils.getSlotUnderMouse((GuiContainer) mc.currentScreen, x, y); if (currentSlot instanceof SlotFake && currentSlot.getHasStack()) { - int changeCount = GuiContainer.isCtrlKeyDown() ? i / 60 : i / 120; - NEENetworkHandler.getInstance().sendToServer(new PacketStackCountChange(currentSlot.slotNumber, changeCount)); + //try to change current itemstack to next ingredient; + if (GuiContainer.isShiftKeyDown() && GuiUtils.isCraftingSlot(currentSlot)) { + GuiUtils.handleRecipeIngredientChange(currentSlot, dWheel); + } else { + int changeCount = GuiContainer.isCtrlKeyDown() ? dWheel / 60 : dWheel / 120; + NEENetworkHandler.getInstance().sendToServer(new PacketStackCountChange(currentSlot.slotNumber, changeCount)); + } } } } 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 8835fa7..fb31ff5 100644 --- a/src/main/java/com/github/vfyjxf/nee/nei/NEECraftingHandler.java +++ b/src/main/java/com/github/vfyjxf/nee/nei/NEECraftingHandler.java @@ -1,25 +1,27 @@ package com.github.vfyjxf.nee.nei; import appeng.client.gui.implementations.GuiPatternTerm; -import appeng.client.gui.implementations.GuiPatternTermEx; -import codechicken.nei.api.IOverlayHandler; -import codechicken.nei.recipe.TemplateRecipeHandler; -import com.github.vfyjxf.nee.network.NEENetworkHandler; import appeng.util.Platform; import codechicken.nei.PositionedStack; +import codechicken.nei.api.IOverlayHandler; import codechicken.nei.recipe.IRecipeHandler; +import codechicken.nei.recipe.TemplateRecipeHandler; +import com.github.vfyjxf.nee.network.NEENetworkHandler; import com.github.vfyjxf.nee.network.packet.PacketArcaneRecipe; import com.github.vfyjxf.nee.network.packet.PacketExtremeRecipe; import com.github.vfyjxf.nee.network.packet.PacketNEIPatternRecipe; import com.github.vfyjxf.nee.processor.IRecipeProcessor; import com.github.vfyjxf.nee.processor.RecipeProcessor; +import com.github.vfyjxf.nee.utils.GuiUtils; 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 java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * @author vfyjxf @@ -27,10 +29,11 @@ import java.util.List; public class NEECraftingHandler implements IOverlayHandler { public static final String OUTPUT_KEY = "Outputs"; + public static Map ingredients = new HashMap<>(); @Override public void overlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean shift) { - if (firstGui instanceof GuiPatternTerm || (hasPatternTermExClz() && firstGui instanceof GuiPatternTermEx)) { + if (firstGui instanceof GuiPatternTerm || GuiUtils.isPatternTermExGui(firstGui)) { NEENetworkHandler.getInstance().sendToServer(packRecipe(recipe, recipeIndex)); } else { knowledgeInscriberHandler(firstGui, recipe, recipeIndex); @@ -95,6 +98,7 @@ public class NEECraftingHandler implements IOverlayHandler { continue; } recipeInputs.setTag("#" + inputIndex, currentStack.writeToNBT(new NBTTagCompound())); + NEECraftingHandler.ingredients.put("input" + inputIndex, positionedStack); inputIndex++; } @@ -133,6 +137,7 @@ public class NEECraftingHandler implements IOverlayHandler { } recipeInputs.setTag("#" + slotIndex, stack.writeToNBT(new NBTTagCompound())); + NEECraftingHandler.ingredients.put("input" + slotIndex, positionedStack); } } return new PacketNEIPatternRecipe(recipeInputs, null); @@ -249,13 +254,4 @@ public class NEECraftingHandler implements IOverlayHandler { return "crafting".equals(overlayIdentifier) || "crafting2x2".equals(overlayIdentifier); } - private boolean hasPatternTermExClz() { - try { - Class.forName("appeng.client.gui.implementations.GuiPatternTermEx"); - } catch (ClassNotFoundException ignored) { - return false; - } - - return true; - } -} \ No newline at end of file +} diff --git a/src/main/java/com/github/vfyjxf/nee/network/NEENetworkHandler.java b/src/main/java/com/github/vfyjxf/nee/network/NEENetworkHandler.java index b55d64c..1457f8b 100644 --- a/src/main/java/com/github/vfyjxf/nee/network/NEENetworkHandler.java +++ b/src/main/java/com/github/vfyjxf/nee/network/NEENetworkHandler.java @@ -1,10 +1,7 @@ package com.github.vfyjxf.nee.network; import com.github.vfyjxf.nee.NotEnoughEnergistics; -import com.github.vfyjxf.nee.network.packet.PacketArcaneRecipe; -import com.github.vfyjxf.nee.network.packet.PacketExtremeRecipe; -import com.github.vfyjxf.nee.network.packet.PacketNEIPatternRecipe; -import com.github.vfyjxf.nee.network.packet.PacketStackCountChange; +import com.github.vfyjxf.nee.network.packet.*; import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper; import cpw.mods.fml.relauncher.Side; @@ -21,6 +18,7 @@ public class NEENetworkHandler { INSTANCE.registerMessage(PacketArcaneRecipe.class, PacketArcaneRecipe.class, 1, Side.SERVER); INSTANCE.registerMessage(PacketExtremeRecipe.class, PacketExtremeRecipe.class, 2, Side.SERVER); INSTANCE.registerMessage(PacketStackCountChange.class, PacketStackCountChange.class, 3, Side.SERVER); + INSTANCE.registerMessage(PacketRecipeItemChange.class, PacketRecipeItemChange.class, 4, Side.SERVER); } } \ No newline at end of file diff --git a/src/main/java/com/github/vfyjxf/nee/network/packet/PacketNEIPatternRecipe.java b/src/main/java/com/github/vfyjxf/nee/network/packet/PacketNEIPatternRecipe.java index 48f34a2..92dfaad 100644 --- a/src/main/java/com/github/vfyjxf/nee/network/packet/PacketNEIPatternRecipe.java +++ b/src/main/java/com/github/vfyjxf/nee/network/packet/PacketNEIPatternRecipe.java @@ -17,10 +17,11 @@ import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import static com.github.vfyjxf.nee.nei.NEECraftingHandler.OUTPUT_KEY; import javax.annotation.Nonnull; +import static com.github.vfyjxf.nee.nei.NEECraftingHandler.OUTPUT_KEY; + public class PacketNEIPatternRecipe implements IMessage, IMessageHandler { diff --git a/src/main/java/com/github/vfyjxf/nee/network/packet/PacketRecipeItemChange.java b/src/main/java/com/github/vfyjxf/nee/network/packet/PacketRecipeItemChange.java new file mode 100644 index 0000000..f427968 --- /dev/null +++ b/src/main/java/com/github/vfyjxf/nee/network/packet/PacketRecipeItemChange.java @@ -0,0 +1,64 @@ +package com.github.vfyjxf.nee.network.packet; + +import appeng.container.implementations.ContainerPatternTerm; +import com.github.vfyjxf.nee.utils.GuiUtils; +import cpw.mods.fml.common.network.ByteBufUtils; +import cpw.mods.fml.common.network.simpleimpl.IMessage; +import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; +import cpw.mods.fml.common.network.simpleimpl.MessageContext; +import io.netty.buffer.ByteBuf; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +/** + * @author vfyjxf + */ +public class PacketRecipeItemChange implements IMessage, IMessageHandler { + + private NBTTagCompound stack; + private int slotNumber; + + public PacketRecipeItemChange(){ + + } + + public PacketRecipeItemChange(NBTTagCompound stack, int slotNumber) { + this.stack = stack; + this.slotNumber = slotNumber; + } + + public NBTTagCompound getStack() { + return stack; + } + + public int getSlotNumber() { + return slotNumber; + } + + @Override + public void fromBytes(ByteBuf buf) { + this.stack = ByteBufUtils.readTag(buf); + this.slotNumber = buf.readInt(); + } + + @Override + public void toBytes(ByteBuf buf) { + ByteBufUtils.writeTag(buf,this.stack); + buf.writeInt(this.slotNumber); + } + + @Override + public IMessage onMessage(PacketRecipeItemChange message, MessageContext ctx) { + Container container = ctx.getServerHandler().playerEntity.openContainer; + if(container instanceof ContainerPatternTerm || GuiUtils.isPatternTermExContainer(container)){ + Slot currentSlot = container.getSlot(message.getSlotNumber()); + ItemStack nextStack = ItemStack.loadItemStackFromNBT(message.getStack()); + if(nextStack != null){ + currentSlot.putStack(nextStack); + } + } + return null; + } +} diff --git a/src/main/java/com/github/vfyjxf/nee/network/packet/PacketStackCountChange.java b/src/main/java/com/github/vfyjxf/nee/network/packet/PacketStackCountChange.java index 069b990..716f537 100644 --- a/src/main/java/com/github/vfyjxf/nee/network/packet/PacketStackCountChange.java +++ b/src/main/java/com/github/vfyjxf/nee/network/packet/PacketStackCountChange.java @@ -54,18 +54,11 @@ public class PacketStackCountChange implements IMessage, IMessageHandler 0) { - if (currentSlot.getStack().stackSize >= currentSlot.getStack().getMaxStackSize()) { - break; - } - currentSlot.getStack().stackSize = (currentSlot.getStack().stackSize + 1); - } else { - if (currentSlot.getStack().stackSize - 1 <= 0) { - break; - } - currentSlot.getStack().stackSize = currentSlot.getStack().stackSize - 1; + int currentStackSize = message.getChangeCount() > 0 ? currentSlot.getStack().stackSize + 1 : currentSlot.getStack().stackSize - 1; + if (currentSlot.getStack().stackSize >= currentSlot.getStack().getMaxStackSize() || currentSlot.getStack().stackSize - 1 <= 0) { + break; } - + currentSlot.getStack().stackSize = currentStackSize; } } return null; 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 278b6fb..02ed992 100644 --- a/src/main/java/com/github/vfyjxf/nee/utils/GuiUtils.java +++ b/src/main/java/com/github/vfyjxf/nee/utils/GuiUtils.java @@ -1,11 +1,22 @@ package com.github.vfyjxf.nee.utils; import appeng.client.gui.AEBaseGui; +import appeng.container.implementations.ContainerPatternTerm; +import appeng.helpers.IContainerCraftingPacket; +import codechicken.nei.PositionedStack; +import com.github.vfyjxf.nee.nei.NEECraftingHandler; +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.GuiScreen; import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.settings.KeyBinding; import net.minecraft.inventory.Container; +import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -14,6 +25,7 @@ import java.lang.reflect.Method; * @author vfyjxf */ public class GuiUtils { + public static Slot getSlotUnderMouse(GuiContainer guiContainer, int mouseX, int mouseY) { Method getSlotMethod = ReflectionHelper.findMethod(AEBaseGui.class, (AEBaseGui) guiContainer, new String[]{"getSlot"}, int.class, int.class); try { @@ -34,7 +46,7 @@ public class GuiUtils { } } - public static boolean isPatternTermExContainer(Container container){ + public static boolean isPatternTermExContainer(Container container) { try { Class patternTermExClz = Class.forName("appeng.container.implementations.ContainerPatternTermEx"); return patternTermExClz.isInstance(container); @@ -43,4 +55,37 @@ public class GuiUtils { } } + public static boolean isCraftingSlot(Slot slot) { + Container container = Minecraft.getMinecraft().thePlayer.openContainer; + if (container instanceof ContainerPatternTerm || GuiUtils.isPatternTermExContainer(container)) { + IContainerCraftingPacket cct = (IContainerCraftingPacket) container; + IInventory craftMatrix = cct.getInventoryByName("crafting"); + return slot.inventory.equals(craftMatrix); + } + return false; + } + + public static void handleRecipeIngredientChange(Slot currentSlot, int dWheel) { + + PositionedStack currentIngredients = NEECraftingHandler.ingredients.get("input" + currentSlot.getSlotIndex()); + if (currentIngredients != null && currentIngredients.items.length > 1) { + int currentStackIndex = ItemUtils.getIngredientIndex(currentSlot.getStack(), currentIngredients); + if (currentStackIndex >= 0) { + int nextStackIndex = dWheel / 120; + for (int i = 0; i < Math.abs(nextStackIndex); i++) { + currentStackIndex = nextStackIndex > 0 ? currentStackIndex + 1 : currentStackIndex - 1; + if (currentStackIndex >= currentIngredients.items.length) { + currentStackIndex = 0; + } else if (currentStackIndex < 0) { + currentStackIndex = currentIngredients.items.length - 1; + } + ItemStack currentStack = currentIngredients.items[currentStackIndex].copy(); + currentStack.stackSize = currentSlot.getStack().stackSize; + NEENetworkHandler.getInstance().sendToServer(new PacketRecipeItemChange(currentStack.writeToNBT(new NBTTagCompound()), currentSlot.slotNumber)); + } + } + } + + } + } diff --git a/src/main/java/com/github/vfyjxf/nee/utils/ItemUtils.java b/src/main/java/com/github/vfyjxf/nee/utils/ItemUtils.java index ce5f16b..451a54e 100644 --- a/src/main/java/com/github/vfyjxf/nee/utils/ItemUtils.java +++ b/src/main/java/com/github/vfyjxf/nee/utils/ItemUtils.java @@ -1,5 +1,6 @@ package com.github.vfyjxf.nee.utils; +import codechicken.nei.PositionedStack; import com.github.vfyjxf.nee.NotEnoughEnergistics; import com.google.gson.Gson; import com.google.gson.JsonSyntaxException; @@ -10,7 +11,6 @@ import net.minecraft.nbt.JsonToNBT; import net.minecraft.nbt.NBTException; import net.minecraft.nbt.NBTTagCompound; - import java.util.ArrayList; import java.util.List; @@ -88,7 +88,6 @@ public final class ItemUtils { return transformItemPriorityList; } - public static boolean isPreferItems(ItemStack itemStack, String recipeProcessor, String identifier) { for (StackProcessor processor : ItemUtils.transformItemPriorityList) { ItemStack copyStack = itemStack.copy(); @@ -149,4 +148,18 @@ public final class ItemUtils { } return null; } + + public static int getIngredientIndex(ItemStack stack, PositionedStack positionedStack){ + ItemStack stackInput = stack.copy(); + stackInput.stackSize = 1; + for(int i = 0; i < positionedStack.items.length; i++){ + ItemStack currentStack = positionedStack.items[i].copy(); + currentStack.stackSize = 1; + if(ItemStack.areItemStacksEqual(currentStack,stackInput)){ + return i; + } + } + return -1; + } + }