diff --git a/dependencies.gradle b/dependencies.gradle index 631b3e2..73e5580 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -1,20 +1,22 @@ dependencies { - api("com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-435-GTNH:dev") - api("com.github.GTNewHorizons:NotEnoughItems:2.6.34-GTNH:dev") + api("com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-527-GTNH:dev") + api("com.github.GTNewHorizons:NotEnoughItems:2.7.35-GTNH-pre:dev") + api('com.github.GTNewHorizons:CodeChickenCore:1.4.1:dev') implementation("com.github.GTNewHorizons:Baubles:1.0.4:dev") - implementation("com.github.GTNewHorizons:WirelessCraftingTerminal:1.11.6:dev") + implementation("com.github.GTNewHorizons:WirelessCraftingTerminal:1.11.7:dev") - compileOnly("com.github.GTNewHorizons:GT5-Unofficial:5.09.49.55:dev") { transitive = false } - compileOnly("com.github.GTNewHorizons:AE2FluidCraft-Rework:1.3.26-gtnh:dev") { transitive = false } - compileOnly("com.github.GTNewHorizons:Avaritiaddons:1.7.1-GTNH:dev") { transitive = false } + compileOnly("com.github.GTNewHorizons:GT5-Unofficial:5.09.51.91:dev") { transitive = false } + implementation("com.github.GTNewHorizons:AE2FluidCraft-Rework:1.4.23-gtnh:dev") { transitive = false } + compileOnly("com.github.GTNewHorizons:Avaritia:1.61:dev") { transitive = false } + compileOnly("com.github.GTNewHorizons:Avaritiaddons:1.8.4-GTNH:dev") { transitive = false } compileOnly("com.github.GTNewHorizons:BuildCraftCompat:7.1.17:dev") { transitive = false } - compileOnly('com.github.GTNewHorizons:EnderIO:2.8.17:dev') {transitive=false} - compileOnly("com.github.GTNewHorizons:ForestryMC:4.9.7:dev") { transitive = false } + compileOnly('com.github.GTNewHorizons:EnderIO:2.9.2:dev') {transitive=false} + compileOnly("com.github.GTNewHorizons:ForestryMC:4.10.1:dev") { transitive = false } compileOnly("com.github.GTNewHorizons:GTplusplus:1.12.11:dev") { transitive = false } - compileOnly("com.github.GTNewHorizons:ThaumicEnergistics:1.6.22-GTNH:dev") { transitive = false } - compileOnly("com.github.GTNewHorizons:Botania:1.11.5-GTNH:dev") { transitive = false } + compileOnly("com.github.GTNewHorizons:ThaumicEnergistics:1.7.5-GTNH:dev") { transitive = false } + compileOnly("com.github.GTNewHorizons:Botania:1.12.5-GTNH:dev") { transitive = false } compileOnly("com.gregoriust.gregtech:gregtech_1.7.10:6.14.23:dev") { transitive = false } compileOnly("curse.maven:thaumcraft-nei-plugin-225095:2241913") { transitive = false } compileOnly("curse.maven:thermal-expansion-69163:2388759") { transitive = false } diff --git a/gradle.properties b/gradle.properties index ad06290..d0ff853 100644 --- a/gradle.properties +++ b/gradle.properties @@ -41,11 +41,11 @@ developmentEnvironmentUserName = Developer # Enables using modern Java syntax (up to version 17) via Jabel, while still targeting JVM 8. # See https://github.com/bsideup/jabel for details on how this works. -enableModernJavaSyntax = false +enableModernJavaSyntax = true # Enables injecting missing generics into the decompiled source code for a better coding experience. # Turns most publicly visible List, Map, etc. into proper List, Map types. -enableGenericInjection = false +enableGenericInjection = true # Generate a class with a String field for the mod version named as defined below. # If generateGradleTokenClass is empty or not missing, no such class will be generated. @@ -200,4 +200,3 @@ customArchiveBaseName = NotEnoughEnergistics # Whether IDEA should run spotless checks when pressing the Build button. # This is meant to be set in $HOME/.gradle/gradle.properties. # ideaCheckSpotlessOnBuild = true - diff --git a/src/main/java/com/github/vfyjxf/nee/NEINeeConfig.java b/src/main/java/com/github/vfyjxf/nee/NEINeeConfig.java index 248ad81..e0900eb 100644 --- a/src/main/java/com/github/vfyjxf/nee/NEINeeConfig.java +++ b/src/main/java/com/github/vfyjxf/nee/NEINeeConfig.java @@ -28,6 +28,8 @@ import com.glodblock.github.client.gui.GuiFluidPatternWireless; import appeng.client.gui.implementations.GuiCraftingTerm; import appeng.client.gui.implementations.GuiInterface; +import appeng.client.gui.implementations.GuiMEMonitorable; +import appeng.client.gui.implementations.GuiMEPortableCell; import appeng.client.gui.implementations.GuiPatternTerm; import appeng.client.gui.implementations.GuiPatternTermEx; import codechicken.nei.NEIController; @@ -35,7 +37,10 @@ import codechicken.nei.api.API; import codechicken.nei.api.IConfigureNEI; import codechicken.nei.guihook.GuiContainerManager; import codechicken.nei.guihook.IContainerInputHandler; +import codechicken.nei.recipe.DefaultOverlayHandler; import cpw.mods.fml.common.Loader; +import fox.spiteful.avaritia.gui.GUIExtremeCrafting; +import thaumicenergistics.client.gui.GuiArcaneCraftingTerminal; import thaumicenergistics.client.gui.GuiKnowledgeInscriber; import wanion.avaritiaddons.block.extremeautocrafter.GuiExtremeAutoCrafter; @@ -73,6 +78,8 @@ public class NEINeeConfig implements IConfigureNEI { installThaumicEnergisticsSupport(); + installAvaritiaSupport(); + installAvaritiaddonsSupport(); installPatternTerminalExSupport(new HashSet<>(identifiers)); @@ -118,6 +125,8 @@ public class NEINeeConfig implements IConfigureNEI { API.registerBookmarkContainerHandler(GuiPatternTerm.class, NEETerminalBookmarkContainerHandler.instance); API.registerBookmarkContainerHandler(GuiPatternTermEx.class, NEETerminalBookmarkContainerHandler.instance); API.registerBookmarkContainerHandler(GuiCraftingTerm.class, NEETerminalBookmarkContainerHandler.instance); + API.registerBookmarkContainerHandler(GuiMEMonitorable.class, NEETerminalBookmarkContainerHandler.instance); + API.registerBookmarkContainerHandler(GuiMEPortableCell.class, NEETerminalBookmarkContainerHandler.instance); if (Loader.isModLoaded(ModIDs.FC)) { API.registerBookmarkContainerHandler( @@ -143,6 +152,13 @@ public class NEINeeConfig implements IConfigureNEI { GuiWirelessCraftingTerminal.class, NEETerminalBookmarkContainerHandler.instance); } + + if (Loader.isModLoaded("thaumcraftneiplugin")) { + API.registerBookmarkContainerHandler( + GuiArcaneCraftingTerminal.class, + NEETerminalBookmarkContainerHandler.instance); + } + } @Override @@ -164,6 +180,7 @@ public class NEINeeConfig implements IConfigureNEI { private void registerGuiHandler() { API.registerNEIGuiHandler(GuiEventHandler.instance); + GuiContainerManager.addTooltipHandler(GuiEventHandler.instance); // disable MouseScrollTransfer in some gui replaceNEIController(); } @@ -224,24 +241,28 @@ public class NEINeeConfig implements IConfigureNEI { } private void installThaumicEnergisticsSupport() { - try { - Class.forName("thaumicenergistics.client.gui.GuiKnowledgeInscriber"); - } catch (ClassNotFoundException e) { - return; - } if (Loader.isModLoaded("thaumcraftneiplugin")) { NotEnoughEnergistics.logger.info("Install ThaumicEnergistics support"); - API.registerGuiOverlay(GuiKnowledgeInscriber.class, "arcaneshapedrecipes"); - API.registerGuiOverlay(GuiKnowledgeInscriber.class, "arcaneshapelessrecipes"); - API.registerGuiOverlayHandler( - GuiKnowledgeInscriber.class, - NEEKnowledgeInscriberHandler.instance, - "arcaneshapedrecipes"); - API.registerGuiOverlayHandler( - GuiKnowledgeInscriber.class, - NEEKnowledgeInscriberHandler.instance, - "arcaneshapelessrecipes"); + + try { + Class.forName("thaumicenergistics.client.gui.GuiKnowledgeInscriber"); + + API.registerGuiOverlay(GuiKnowledgeInscriber.class, "arcaneshapedrecipes"); + API.registerGuiOverlay(GuiKnowledgeInscriber.class, "arcaneshapelessSrecipes"); + API.registerGuiOverlayHandler( + GuiKnowledgeInscriber.class, + NEEKnowledgeInscriberHandler.instance, + "arcaneshapedrecipes"); + API.registerGuiOverlayHandler( + GuiKnowledgeInscriber.class, + NEEKnowledgeInscriberHandler.instance, + "arcaneshapelessrecipes"); + + } catch (ClassNotFoundException e) { + + } + } } @@ -264,11 +285,24 @@ public class NEINeeConfig implements IConfigureNEI { if (Loader.isModLoaded("avaritiaddons")) { NotEnoughEnergistics.logger.info("Install Avaritiaddons support"); - API.registerGuiOverlay(GuiExtremeAutoCrafter.class, "extreme"); + API.registerGuiOverlay(GuiExtremeAutoCrafter.class, "extreme", 181, 15); API.registerGuiOverlayHandler( GuiExtremeAutoCrafter.class, NEEExtremeAutoCrafterHandler.instance, "extreme"); } } + + private void installAvaritiaSupport() { + try { + Class.forName("fox.spiteful.avaritia.gui.GUIExtremeCrafting"); + } catch (ClassNotFoundException e) { + return; + } + + if (Loader.isModLoaded("Avaritia")) { + API.registerGuiOverlay(GUIExtremeCrafting.class, "extreme", 9, 5); + API.registerGuiOverlayHandler(GUIExtremeCrafting.class, new DefaultOverlayHandler(9, 5), "extreme"); + } + } } diff --git a/src/main/java/com/github/vfyjxf/nee/client/GuiEventHandler.java b/src/main/java/com/github/vfyjxf/nee/client/GuiEventHandler.java index 0b48abf..d1d7bd9 100644 --- a/src/main/java/com/github/vfyjxf/nee/client/GuiEventHandler.java +++ b/src/main/java/com/github/vfyjxf/nee/client/GuiEventHandler.java @@ -10,17 +10,18 @@ import java.awt.Rectangle; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; 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.client.resources.I18n; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import net.minecraftforge.client.event.GuiScreenEvent; -import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; import com.github.vfyjxf.nee.client.gui.widgets.GuiImgButtonEnableCombination; @@ -42,16 +43,19 @@ import appeng.client.gui.implementations.GuiInterface; import appeng.container.AEBaseContainer; import appeng.container.implementations.ContainerPatternTerm; import appeng.container.slot.SlotFake; +import codechicken.lib.gui.GuiDraw; import codechicken.nei.NEIClientConfig; +import codechicken.nei.NEIServerUtils; import codechicken.nei.PositionedStack; -import codechicken.nei.VisiblityData; -import codechicken.nei.api.INEIGuiHandler; -import codechicken.nei.api.TaggedInventoryArea; +import codechicken.nei.api.INEIGuiAdapter; +import codechicken.nei.guihook.IContainerTooltipHandler; +import codechicken.nei.recipe.AcceptsFollowingTooltipLineHandler; import codechicken.nei.recipe.RecipeInfo; +import codechicken.nei.util.NEIMouseUtils; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.eventhandler.SubscribeEvent; -public class GuiEventHandler implements INEIGuiHandler { +public class GuiEventHandler extends INEIGuiAdapter implements IContainerTooltipHandler { public static final GuiEventHandler instance = new GuiEventHandler(); private final GuiImgButtonEnableCombination buttonCombination = new GuiImgButtonEnableCombination( @@ -59,6 +63,7 @@ public class GuiEventHandler implements INEIGuiHandler { 0, ItemCombination.ENABLED); + private AcceptsFollowingTooltipLineHandler acceptsFollowingTooltipLineHandler; private List buttonList; @SuppressWarnings("unchecked") @@ -150,8 +155,7 @@ public class GuiEventHandler implements INEIGuiHandler { @SubscribeEvent public void onActionPerformed(GuiScreenEvent.ActionPerformedEvent.Pre event) { if (event.button == this.buttonCombination) { - int ordinal = Mouse.getEventButton() != 2 ? this.buttonCombination.getCurrentValue().ordinal() + 1 - : this.buttonCombination.getCurrentValue().ordinal() - 1; + int ordinal = this.buttonCombination.getCurrentValue().ordinal() + (Mouse.getEventButton() == 0 ? 1 : -1); if (ordinal >= ItemCombination.values().length) { ordinal = 0; @@ -176,21 +180,6 @@ public class GuiEventHandler implements INEIGuiHandler { return false; } - @Override - public VisiblityData modifyVisiblity(GuiContainer gui, VisiblityData currentVisibility) { - return null; - } - - @Override - public Iterable getItemSpawnSlots(GuiContainer gui, ItemStack item) { - return null; - } - - @Override - public List getInventoryAreas(GuiContainer gui) { - return null; - } - @Override public boolean handleDragNDrop(GuiContainer gui, int mouseX, int mouseY, ItemStack draggedStack, int button) { // When NEIAddons exist, give them to NEIAddons to handle @@ -207,11 +196,12 @@ public class GuiEventHandler implements INEIGuiHandler { boolean sendPacket = false; int copySize = useStackSizeFromNEI ? copyStack.stackSize : draggedStackDefaultSize; if (button == 0) { - copyStack.stackSize = areStackEqual(slotStack, copyStack) ? slotStack.stackSize + copySize + copyStack.stackSize = NEIServerUtils.areStacksSameTypeCraftingWithNBT(slotStack, copyStack) + ? slotStack.stackSize + copySize : copySize; sendPacket = true; } else if (button == 1) { - if (areStackEqual(slotStack, copyStack)) { + if (NEIServerUtils.areStacksSameTypeCraftingWithNBT(slotStack, copyStack)) { copyStack.stackSize = slotStack.stackSize; } else { copyStack.stackSize = slotStack == null ? 1 : copySize; @@ -237,15 +227,6 @@ public class GuiEventHandler implements INEIGuiHandler { return false; } - private boolean areStackEqual(ItemStack stackA, ItemStack stackB) { - return stackA != null && stackA.isItemEqual(stackB) && ItemStack.areItemStackTagsEqual(stackA, stackB); - } - - @Override - public boolean hideItemPanelSlot(GuiContainer gui, int x, int y, int w, int h) { - return false; - } - /** * Prevent the scroll bar from being triggered when modifying the number of items This method is not intended to be * called by NEE. Do not use this method for any reason. @@ -253,70 +234,118 @@ public class GuiEventHandler implements INEIGuiHandler { @SubscribeEvent public boolean handleMouseWheelInput(GuiScrollEvent event) { Minecraft mc = Minecraft.getMinecraft(); - boolean isPatternTerm = isPatternTerm(mc.currentScreen); - boolean isInterface = event.guiScreen instanceof GuiInterface; - if (isPatternTerm || isInterface) { - Slot currentSlot = event.guiScreen.getSlotAtPosition(event.mouseX, event.mouseY); - if (currentSlot instanceof SlotFake && currentSlot.getHasStack()) { - // try to change current itemstack to next ingredient; - if (Keyboard.isKeyDown(NEIClientConfig.getKeyBinding("nee.ingredient")) - && GuiUtils.isCraftingSlot(currentSlot)) { - handleRecipeIngredientChange(event.guiScreen, currentSlot, event.scrollAmount); - return true; - } else if (Keyboard.isKeyDown(NEIClientConfig.getKeyBinding("nee.count"))) { - NEENetworkHandler.getInstance() - .sendToServer(new PacketStackCountChange(currentSlot.slotNumber, event.scrollAmount)); - return true; - } + Slot currentSlot = getFakeSlotAtPosition((GuiContainer) mc.currentScreen, event.mouseX, event.mouseY); + + if (currentSlot != null) { + // try to change current itemstack to next ingredient; + if (NEIClientConfig.isKeyHashDown("nee.ingredient") && GuiUtils.isCraftingSlot(currentSlot)) { + handleRecipeIngredientChange(event.guiScreen, currentSlot, event.scrollAmount); + return true; + } else if (NEIClientConfig.isKeyHashDown("nee.count")) { + NEENetworkHandler.getInstance() + .sendToServer(new PacketStackCountChange(currentSlot.slotNumber, event.scrollAmount)); + return true; } } + return false; } - private static void handleRecipeIngredientChange(GuiContainer gui, Slot currentSlot, int dWheel) { - List craftingSlots = new ArrayList<>(); - int currentSlotIndex = currentSlot.getSlotIndex(); - PositionedStack currentIngredients = NEEPatternTerminalHandler.ingredients.get(INPUT_KEY + currentSlotIndex); - if (currentIngredients != null && currentIngredients.items.length > 1) { - int currentStackIndex = ItemUtils.getIngredientIndex(currentSlot.getStack(), currentIngredients); - if (currentStackIndex >= 0) { - for (int j = 0; j < Math.abs(dWheel); j++) { - currentStackIndex += (dWheel < 0) ? -1 : 1; + @Override + public List handleItemTooltip(GuiContainer gui, ItemStack itemstack, int mousex, int mousey, + List currenttip) { + final Slot currentSlot = itemstack != null ? getFakeSlotAtPosition(gui, mousex, mousey) : null; - if (currentStackIndex >= currentIngredients.items.length) { - currentStackIndex = 0; - } else if (currentStackIndex < 0) { - currentStackIndex = currentIngredients.items.length - 1; - } + if (currentSlot != null) { + PositionedStack currentIngredients = NEEPatternTerminalHandler.ingredients + .get(INPUT_KEY + currentSlot.getSlotIndex()); + if (currentIngredients != null && currentIngredients.items.length > 1 + && currentIngredients.containsWithNBT(currentSlot.getStack())) { - ItemStack currentStack = currentIngredients.items[currentStackIndex].copy(); - currentStack.stackSize = currentSlot.getStack().stackSize; + if (this.acceptsFollowingTooltipLineHandler == null + || this.acceptsFollowingTooltipLineHandler.tooltipGUID != currentIngredients) { + this.acceptsFollowingTooltipLineHandler = AcceptsFollowingTooltipLineHandler.of( + currentIngredients, + currentIngredients.getFilteredPermutations(), + currentIngredients.item); + } - if (NEEConfig.allowSynchronousSwitchIngredient) { - for (Slot slot : getCraftingSlots(gui)) { - - PositionedStack slotIngredients = NEEPatternTerminalHandler.ingredients - .get(INPUT_KEY + slot.getSlotIndex()); - - boolean areItemStackEqual = currentSlot.getHasStack() && slot.getHasStack() - && currentSlot.getStack().isItemEqual(slot.getStack()) - && ItemStack.areItemStackTagsEqual(currentSlot.getStack(), slot.getStack()); - - boolean areIngredientEqual = slotIngredients != null - && currentIngredients.contains(slotIngredients.items[0]); - - if (areItemStackEqual && areIngredientEqual) { - craftingSlots.add(slot.slotNumber); - } - } - } else { - craftingSlots.add(currentSlot.slotNumber); - } - NEENetworkHandler.getInstance() - .sendToServer(new PacketSlotStackChange(currentStack, craftingSlots)); + if (this.acceptsFollowingTooltipLineHandler != null) { + this.acceptsFollowingTooltipLineHandler.setActiveStack(currentIngredients.item); + currenttip.add( + GuiDraw.TOOLTIP_HANDLER + GuiDraw.getTipLineId(this.acceptsFollowingTooltipLineHandler)); } } } + + return currenttip; + } + + @Override + public Map handleHotkeys(GuiContainer gui, int mousex, int mousey, Map hotkeys) { + final Slot currentSlot = getFakeSlotAtPosition(gui, mousex, mousey); + + if (currentSlot != null) { + + if (this.acceptsFollowingTooltipLineHandler != null) { + hotkeys.put( + NEIClientConfig.getKeyName( + "nee.ingredient", + 0, + NEIMouseUtils.MOUSE_BTN_NONE + NEIMouseUtils.MOUSE_SCROLL), + I18n.format("neenergistics.gui.tooltip.ingredient.permutation")); + } + + hotkeys.put( + NEIClientConfig + .getKeyName("nee.count", 0, NEIMouseUtils.MOUSE_BTN_NONE + NEIMouseUtils.MOUSE_SCROLL), + I18n.format("neenergistics.gui.tooltip.ingredient.count")); + } + + return hotkeys; + } + + private Slot getFakeSlotAtPosition(GuiContainer gui, int mousex, int mousey) { + if (gui instanceof GuiInterface || isPatternTerm(gui)) { + final Slot currentSlot = gui.getSlotAtPosition(mousex, mousey); + if (currentSlot instanceof SlotFake && currentSlot.getHasStack()) { + return currentSlot; + } + } + + return null; + } + + private void handleRecipeIngredientChange(GuiContainer gui, Slot currentSlot, int dWheel) { + final int currentSlotIndex = currentSlot.getSlotIndex(); + final PositionedStack currentIngredients = NEEPatternTerminalHandler.ingredients + .get(INPUT_KEY + currentSlotIndex); + + if (currentIngredients != null && currentIngredients.items.length > 1) { + final List craftingSlots = new ArrayList<>(); + final List items = currentIngredients.getFilteredPermutations(); + final int currentStackIndex = ItemUtils.getPermutationIndex(currentSlot.getStack(), items); + final ItemStack nextStack = items.get((items.size() - dWheel + currentStackIndex) % items.size()); + final ItemStack currentStack = currentIngredients.item; + + if (NEEConfig.allowSynchronousSwitchIngredient) { + for (Slot slot : getCraftingSlots(gui)) { + final PositionedStack slotIngredients = NEEPatternTerminalHandler.ingredients + .get(INPUT_KEY + slot.getSlotIndex()); + + if (slotIngredients != null && slotIngredients.containsWithNBT(nextStack) + && NEIServerUtils.areStacksSameTypeCraftingWithNBT(slotIngredients.item, currentStack)) { + slotIngredients.setPermutationToRender(nextStack); + craftingSlots.add(slot.slotNumber); + } + } + } else { + currentIngredients.setPermutationToRender(nextStack); + craftingSlots.add(currentSlot.slotNumber); + } + + NEENetworkHandler.getInstance().sendToServer(new PacketSlotStackChange(nextStack, craftingSlots)); + } } @SuppressWarnings("unchecked") diff --git a/src/main/java/com/github/vfyjxf/nee/nei/NEECraftingPreviewHandler.java b/src/main/java/com/github/vfyjxf/nee/nei/NEECraftingPreviewHandler.java new file mode 100644 index 0000000..329788b --- /dev/null +++ b/src/main/java/com/github/vfyjxf/nee/nei/NEECraftingPreviewHandler.java @@ -0,0 +1,78 @@ +package com.github.vfyjxf.nee.nei; + +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; +import net.minecraftforge.client.event.GuiOpenEvent; +import net.minecraftforge.client.event.GuiScreenEvent; + +import com.github.vfyjxf.nee.utils.IngredientTracker; + +import appeng.client.gui.implementations.GuiCraftConfirm; +import appeng.container.implementations.ContainerCraftConfirm; +import codechicken.nei.NEIClientConfig; +import codechicken.nei.recipe.IRecipeHandler; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.relauncher.ReflectionHelper; + +public class NEECraftingPreviewHandler { + + public static final NEECraftingPreviewHandler instance = new NEECraftingPreviewHandler(); + + private IngredientTracker tracker = null; + private boolean noPreview = false; + + private NEECraftingPreviewHandler() {} + + public boolean handle(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex) { + this.noPreview = NEIClientConfig.isKeyHashDown("nee.nopreview"); + boolean doCraftingHelp = this.noPreview || NEIClientConfig.isKeyHashDown("nee.preview"); + + if (this.noPreview || NEIClientConfig.isKeyHashDown("nee.preview")) { + this.tracker = new IngredientTracker(firstGui, recipe, recipeIndex); + + if (!this.tracker.getRequireStacks().isEmpty()) { + this.tracker.requestNextIngredient(this.noPreview); + return true; + } + } + + this.tracker = null; + return false; + } + + @SubscribeEvent + public void onGuiCraftConfirmOpen(GuiOpenEvent event) { + final GuiScreen old = Minecraft.getMinecraft().currentScreen; + + if (old != null && this.tracker != null + && old instanceof GuiCraftConfirm guiConfirm + && isContainerCraftConfirm(guiConfirm.inventorySlots)) { + + if (this.tracker.hasNext()) { + this.tracker.requestNextIngredient(this.noPreview); + } else { + this.tracker = null; + } + } + } + + @SubscribeEvent + public void onCraftConfirmActionPerformed(GuiScreenEvent.ActionPerformedEvent.Post event) { + if (this.tracker != null && event.gui instanceof GuiCraftConfirm guiConfirm + && getCancelButton(guiConfirm) == event.button) { + this.tracker = null; + } + } + + private GuiButton getCancelButton(GuiCraftConfirm gui) { + return ReflectionHelper.getPrivateValue(GuiCraftConfirm.class, gui, "cancel"); + } + + private boolean isContainerCraftConfirm(Container container) { + return container instanceof ContainerCraftConfirm; + } + +} diff --git a/src/main/java/com/github/vfyjxf/nee/nei/NEECraftingTerminalHandler.java b/src/main/java/com/github/vfyjxf/nee/nei/NEECraftingTerminalHandler.java index 1677d11..53bf0c7 100644 --- a/src/main/java/com/github/vfyjxf/nee/nei/NEECraftingTerminalHandler.java +++ b/src/main/java/com/github/vfyjxf/nee/nei/NEECraftingTerminalHandler.java @@ -7,31 +7,20 @@ import java.util.ArrayList; import java.util.LinkedList; import java.util.List; -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; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -import net.minecraftforge.client.event.GuiOpenEvent; -import net.minecraftforge.client.event.GuiScreenEvent; - -import org.lwjgl.input.Keyboard; import com.github.vfyjxf.nee.NotEnoughEnergistics; -import com.github.vfyjxf.nee.nei.NEEGuiOverlayButton.NEEItemOverlayState; +import com.github.vfyjxf.nee.nei.NEETerminalOverlayButton.NEEItemOverlayState; import com.github.vfyjxf.nee.utils.GuiUtils; import com.github.vfyjxf.nee.utils.Ingredient; import com.github.vfyjxf.nee.utils.IngredientTracker; import com.github.vfyjxf.nee.utils.ModIDs; -import appeng.client.gui.implementations.GuiCraftConfirm; -import appeng.client.gui.implementations.GuiCraftingTerm; -import appeng.container.implementations.ContainerCraftConfirm; import appeng.container.slot.SlotCraftingMatrix; import appeng.container.slot.SlotFakeCraftingMatrix; import appeng.core.AELog; @@ -39,12 +28,11 @@ import appeng.core.sync.AppEngPacket; import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.PacketNEIRecipe; import appeng.util.Platform; -import codechicken.nei.NEIClientConfig; import codechicken.nei.PositionedStack; import codechicken.nei.api.IOverlayHandler; -import codechicken.nei.recipe.GuiOverlayButton; import codechicken.nei.recipe.GuiOverlayButton.ItemOverlayState; import codechicken.nei.recipe.GuiRecipe; +import codechicken.nei.recipe.GuiRecipeButton; import codechicken.nei.recipe.IRecipeHandler; import cpw.mods.fml.common.Optional; import cpw.mods.fml.common.eventhandler.SubscribeEvent; @@ -56,57 +44,43 @@ public class NEECraftingTerminalHandler implements IOverlayHandler { public static final NEECraftingTerminalHandler instance = new NEECraftingTerminalHandler(); public static final int RECIPE_LENGTH = 9; - private IngredientTracker tracker = null; - private boolean noPreview = false; - private NEECraftingTerminalHandler() {} + /** + * Copied from GTNewHorizons/Applied-Energistics-2-Unofficialr + */ @Override public void overlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean shift) { - this.noPreview = Keyboard.isKeyDown(NEIClientConfig.getKeyBinding("nee.nopreview")); - boolean doCraftingHelp = this.noPreview || Keyboard.isKeyDown(NEIClientConfig.getKeyBinding("nee.preview")); - this.tracker = null; - - if (!doCraftingHelp) { - moveItems(firstGui, recipe, recipeIndex); - } else { - this.tracker = new IngredientTracker(firstGui, recipe, recipeIndex); - - if (!this.tracker.getRequireStacks().isEmpty()) { - this.tracker.requestNextIngredient(this.noPreview); - } else { - moveItems(firstGui, recipe, recipeIndex); - } - } - } - - /** - * Copied from GTNewHorizons/Applied-Energistics-2-Unofficial - */ - private void moveItems(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex) { try { final List ingredients = recipe.getIngredientStacks(recipeIndex); - if (firstGui instanceof GuiCraftingTerm) { - PacketNEIRecipe packet = new PacketNEIRecipe(packIngredients(firstGui, ingredients, false)); + + if (GuiUtils.isGuiWirelessCrafting(firstGui)) { + moveItemsForWirelessCrafting(firstGui, ingredients); + } else { + PacketNEIRecipe packet = new PacketNEIRecipe(packIngredients(firstGui, ingredients, false, 4)); // don't use gtnh ae2's method; int packetSize = getPacketSize(packet); if (packetSize >= 32 * 1024) { AELog.warn( "Recipe for " + recipe.getRecipeName() + " has too many variants, reduced version will be used"); - packet = new PacketNEIRecipe(packIngredients(firstGui, ingredients, true)); + packet = new PacketNEIRecipe(packIngredients(firstGui, ingredients, true, 4)); } + if (packetSize >= 0) { NetworkHandler.instance.sendToServer(packet); } else { NotEnoughEnergistics.logger.error("Can't get packet size!"); } - } else if (GuiUtils.isGuiWirelessCrafting(firstGui)) { - moveItemsForWirelessCrafting(firstGui, ingredients); } } catch (final Exception | Error ignored) {} } + @Override + public boolean canFillCraftingGrid(GuiContainer firstGui, IRecipeHandler handler, int recipeIndex) { + return presenceOverlay(firstGui, handler, recipeIndex).stream().allMatch(state -> state.isPresent()); + } + /** * Copied from GTNewHorizons/Applied-Energistics-2-Unofficial */ @@ -133,9 +107,10 @@ public class NEECraftingTerminalHandler implements IOverlayHandler { * Copied from GTNewHorizons/Applied-Energistics-2-Unofficial */ @SuppressWarnings("unchecked") - private NBTTagCompound packIngredients(GuiContainer gui, List ingredients, boolean limited) - throws IOException { + private NBTTagCompound packIngredients(GuiContainer gui, List ingredients, boolean limited, + int multiplier) throws IOException { final NBTTagCompound recipe = new NBTTagCompound(); + for (final PositionedStack positionedStack : ingredients) { if (positionedStack.items != null && positionedStack.items.length > 0) { final int col = (positionedStack.relx - 25) / 18; @@ -146,18 +121,19 @@ public class NEECraftingTerminalHandler implements IOverlayHandler { final List list = new LinkedList<>(); // prefer pure crystals. - for (int x = 0; x < positionedStack.items.length; x++) { - if (Platform.isRecipePrioritized(positionedStack.items[x])) { - list.add(0, positionedStack.items[x]); + for (ItemStack stack : positionedStack.getFilteredPermutations()) { + stack = stack.copy(); + stack.stackSize *= multiplier; + if (Platform.isRecipePrioritized(stack)) { + list.add(0, stack); } else { - list.add(positionedStack.items[x]); + list.add(stack); } } for (final ItemStack is : list) { - final NBTTagCompound tag = new NBTTagCompound(); - is.writeToNBT(tag); - tags.appendTag(tag); + tags.appendTag(is.writeToNBT(new NBTTagCompound())); + if (limited) { final NBTTagCompound test = new NBTTagCompound(); test.setTag("#" + slot.getSlotIndex(), tags); @@ -173,14 +149,12 @@ public class NEECraftingTerminalHandler implements IOverlayHandler { } } } + return recipe; } - private boolean isCraftingMatrixSlot(GuiContainer gui, Slot slot) {// todo change - if (gui instanceof GuiCraftingTerm || GuiUtils.isGuiWirelessCrafting(gui)) { - return slot instanceof SlotCraftingMatrix || slot instanceof SlotFakeCraftingMatrix; - } - return false; + private boolean isCraftingMatrixSlot(GuiContainer gui, Slot slot) { + return slot instanceof SlotCraftingMatrix || slot instanceof SlotFakeCraftingMatrix; } private int getPacketSize(AppEngPacket packet) { @@ -197,53 +171,19 @@ public class NEECraftingTerminalHandler implements IOverlayHandler { try { net.p455w0rd.wirelesscraftingterminal.core.sync.network.NetworkHandler.instance.sendToServer( new net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketNEIRecipe( - packIngredients(firstGui, ingredients, false))); + packIngredients(firstGui, ingredients, false, 4))); } catch (IOException e) { e.printStackTrace(); } } @SubscribeEvent - public void onActionPerformedEventPre(GuiOverlayButton.UpdateOverlayButtonsEvent.Post event) { - if (event.gui instanceof GuiRecipe && isGuiCraftingTerm((GuiRecipe) event.gui)) { - for (int i = 0; i < event.buttonList.size(); i++) { - event.buttonList.set(i, new NEEGuiOverlayButton(event.buttonList.get(i))); - } + public void onActionPerformedEventPre(GuiRecipeButton.UpdateRecipeButtonsEvent.Post event) { + if (event.gui instanceof GuiRecipe guiRecipe && isGuiCraftingTerm(guiRecipe)) { + NEETerminalOverlayButton.updateRecipeButtons(guiRecipe, event.buttonList); } } - @SubscribeEvent - public void onGuiCraftConfirmOpen(GuiOpenEvent event) { - final GuiScreen old = Minecraft.getMinecraft().currentScreen; - - if (old != null && this.tracker != null - && old instanceof GuiCraftConfirm - && isContainerCraftConfirm(((GuiContainer) old).inventorySlots)) { - - if (this.tracker.hasNext()) { - this.tracker.requestNextIngredient(this.noPreview); - } else { - this.tracker = null; - } - } - } - - @SubscribeEvent - public void onCraftConfirmActionPerformed(GuiScreenEvent.ActionPerformedEvent.Post event) { - if (this.tracker != null && event.gui instanceof GuiCraftConfirm - && getCancelButton((GuiCraftConfirm) event.gui) == event.button) { - this.tracker = null; - } - } - - private boolean isContainerCraftConfirm(Container container) { - return container instanceof ContainerCraftConfirm; - } - - private GuiButton getCancelButton(GuiCraftConfirm gui) { - return ReflectionHelper.getPrivateValue(GuiCraftConfirm.class, gui, "cancel"); - } - private boolean isGuiCraftingTerm(GuiRecipe gui) { return this.getClass().isInstance(gui.getHandler().getOverlayHandler(gui.firstGui, 0)); } diff --git a/src/main/java/com/github/vfyjxf/nee/nei/NEEExtremeAutoCrafterHandler.java b/src/main/java/com/github/vfyjxf/nee/nei/NEEExtremeAutoCrafterHandler.java index 7e6b2b0..ad70710 100644 --- a/src/main/java/com/github/vfyjxf/nee/nei/NEEExtremeAutoCrafterHandler.java +++ b/src/main/java/com/github/vfyjxf/nee/nei/NEEExtremeAutoCrafterHandler.java @@ -6,6 +6,7 @@ import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import com.github.vfyjxf.nee.config.NEEConfig; import com.github.vfyjxf.nee.network.NEENetworkHandler; import com.github.vfyjxf.nee.network.packet.PacketExtremeRecipe; import com.github.vfyjxf.nee.utils.ItemUtils; @@ -14,6 +15,7 @@ import codechicken.nei.PositionedStack; import codechicken.nei.api.IOverlayHandler; import codechicken.nei.recipe.GuiOverlayButton; import codechicken.nei.recipe.GuiRecipe; +import codechicken.nei.recipe.GuiRecipeButton; import codechicken.nei.recipe.IRecipeHandler; import cpw.mods.fml.common.eventhandler.SubscribeEvent; @@ -24,26 +26,11 @@ public class NEEExtremeAutoCrafterHandler implements IOverlayHandler { public static final NEEExtremeAutoCrafterHandler instance = new NEEExtremeAutoCrafterHandler(); - private Class guiExtremeAutoCrafterClz; - - private NEEExtremeAutoCrafterHandler() { - - try { - guiExtremeAutoCrafterClz = Class - .forName("wanion.avaritiaddons.block.extremeautocrafter.GuiExtremeAutoCrafter");// "Dire - // Autocrafting - // Table" - } catch (ClassNotFoundException ignored) {} - - } + private NEEExtremeAutoCrafterHandler() {} @Override public void overlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean shift) { - System.out.println("shift: " + shift); - - if (this.guiExtremeAutoCrafterClz != null && this.guiExtremeAutoCrafterClz.isInstance(firstGui)) { - NEENetworkHandler.getInstance().sendToServer(packetExtremeRecipe(recipe, recipeIndex)); - } + NEENetworkHandler.getInstance().sendToServer(packetExtremeRecipe(recipe, recipeIndex)); } private PacketExtremeRecipe packetExtremeRecipe(IRecipeHandler recipe, int recipeIndex) { @@ -72,22 +59,19 @@ public class NEEExtremeAutoCrafterHandler implements IOverlayHandler { } } - recipeInputs.setTag("#" + slotIndex, ItemUtils.writeItemStackToNBT(currentStack, new NBTTagCompound())); + recipeInputs.setTag("#" + slotIndex, ItemUtils.writeItemStackToNBT(currentStack, currentStack.stackSize)); } return new PacketExtremeRecipe(recipeInputs); } @SubscribeEvent - public void onActionPerformedEventPre(GuiOverlayButton.UpdateOverlayButtonsEvent.Post event) { - - if (event.gui instanceof GuiRecipe) { - - } - - if (event.gui instanceof GuiRecipe && isGuiExtremeTerm((GuiRecipe) event.gui)) { + public void onActionPerformedEventPre(GuiRecipeButton.UpdateRecipeButtonsEvent.Post event) { + if (NEEConfig.noShift && event.gui instanceof GuiRecipe && isGuiExtremeTerm((GuiRecipe) event.gui)) { for (int i = 0; i < event.buttonList.size(); i++) { - event.buttonList.set(i, new NEEGuiOverlayButton(event.buttonList.get(i))); + if (event.buttonList.get(i) instanceof GuiOverlayButton btn) { + btn.setRequireShiftForOverlayRecipe(false); + } } } } diff --git a/src/main/java/com/github/vfyjxf/nee/nei/NEEKnowledgeInscriberHandler.java b/src/main/java/com/github/vfyjxf/nee/nei/NEEKnowledgeInscriberHandler.java index d276e35..efe9dfc 100644 --- a/src/main/java/com/github/vfyjxf/nee/nei/NEEKnowledgeInscriberHandler.java +++ b/src/main/java/com/github/vfyjxf/nee/nei/NEEKnowledgeInscriberHandler.java @@ -6,6 +6,7 @@ import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import com.github.vfyjxf.nee.config.NEEConfig; import com.github.vfyjxf.nee.network.NEENetworkHandler; import com.github.vfyjxf.nee.network.packet.PacketArcaneRecipe; import com.github.vfyjxf.nee.utils.ItemUtils; @@ -15,6 +16,7 @@ import codechicken.nei.PositionedStack; import codechicken.nei.api.IOverlayHandler; import codechicken.nei.recipe.GuiOverlayButton; import codechicken.nei.recipe.GuiRecipe; +import codechicken.nei.recipe.GuiRecipeButton; import codechicken.nei.recipe.IRecipeHandler; import cpw.mods.fml.common.eventhandler.SubscribeEvent; @@ -31,8 +33,8 @@ public class NEEKnowledgeInscriberHandler implements IOverlayHandler { private NEEKnowledgeInscriberHandler() { try { - knowledgeInscriberClz = Class.forName("thaumicenergistics.client.gui.GuiKnowledgeInscriber");// "Knowledge - // Inscriber" + // "Knowledge Inscriber" + knowledgeInscriberClz = Class.forName("thaumicenergistics.client.gui.GuiKnowledgeInscriber"); } catch (ClassNotFoundException ignored) {} try { @@ -50,7 +52,7 @@ public class NEEKnowledgeInscriberHandler implements IOverlayHandler { private PacketArcaneRecipe packetArcaneRecipe(IRecipeHandler recipe, int recipeIndex) { final NBTTagCompound recipeInputs = new NBTTagCompound(); - List ingredients = recipe.getIngredientStacks(recipeIndex); + final List ingredients = recipe.getIngredientStacks(recipeIndex); if (itemAspectClz != null) { ingredients.removeIf(positionedStack -> itemAspectClz.isInstance(positionedStack.item.getItem())); @@ -58,7 +60,7 @@ public class NEEKnowledgeInscriberHandler implements IOverlayHandler { for (PositionedStack positionedStack : ingredients) { if (positionedStack.items != null && positionedStack.items.length > 0) { - int slotIndex = getSlotIndex(positionedStack.relx * 100 + positionedStack.rely); + final int slotIndex = getSlotIndex(positionedStack.relx * 100 + positionedStack.rely); final ItemStack[] currentStackList = positionedStack.items; ItemStack stack = positionedStack.item; @@ -68,7 +70,7 @@ public class NEEKnowledgeInscriberHandler implements IOverlayHandler { } } - recipeInputs.setTag("#" + slotIndex, ItemUtils.writeItemStackToNBT(stack, new NBTTagCompound())); + recipeInputs.setTag("#" + slotIndex, ItemUtils.writeItemStackToNBT(stack, stack.stackSize)); } } @@ -100,16 +102,25 @@ public class NEEKnowledgeInscriberHandler implements IOverlayHandler { } @SubscribeEvent - public void onActionPerformedEventPre(GuiOverlayButton.UpdateOverlayButtonsEvent.Post event) { - if (event.gui instanceof GuiRecipe && isGuiPatternTerm((GuiRecipe) event.gui)) { + public void onActionPerformedEventPre(GuiRecipeButton.UpdateRecipeButtonsEvent.Post event) { + + if (NEEConfig.noShift && event.gui instanceof GuiRecipe guiRecipe + && (isGuiKnowledgeInscriber(guiRecipe) || isGuiArcaneCraftingTerm(guiRecipe))) { for (int i = 0; i < event.buttonList.size(); i++) { - event.buttonList.set(i, new NEEGuiOverlayButton(event.buttonList.get(i))); + if (event.buttonList.get(i) instanceof GuiOverlayButton btn) { + btn.setRequireShiftForOverlayRecipe(false); + } } } + } - private boolean isGuiPatternTerm(GuiRecipe gui) { + private boolean isGuiKnowledgeInscriber(GuiRecipe gui) { return this.getClass().isInstance(gui.getHandler().getOverlayHandler(gui.firstGui, 0)); } + private boolean isGuiArcaneCraftingTerm(GuiRecipe gui) { + return gui.firstGui instanceof thaumicenergistics.client.gui.GuiArcaneCraftingTerminal; + } + } diff --git a/src/main/java/com/github/vfyjxf/nee/nei/NEEPatternTerminalHandler.java b/src/main/java/com/github/vfyjxf/nee/nei/NEEPatternTerminalHandler.java index 96da585..0dc1a4d 100644 --- a/src/main/java/com/github/vfyjxf/nee/nei/NEEPatternTerminalHandler.java +++ b/src/main/java/com/github/vfyjxf/nee/nei/NEEPatternTerminalHandler.java @@ -15,11 +15,12 @@ import net.minecraftforge.oredict.OreDictionary; import com.github.vfyjxf.nee.config.ItemCombination; import com.github.vfyjxf.nee.config.NEEConfig; -import com.github.vfyjxf.nee.nei.NEEGuiOverlayButton.NEEItemOverlayState; +import com.github.vfyjxf.nee.nei.NEETerminalOverlayButton.NEEItemOverlayState; import com.github.vfyjxf.nee.network.NEENetworkHandler; 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.Ingredient; import com.github.vfyjxf.nee.utils.IngredientTracker; import com.github.vfyjxf.nee.utils.ItemUtils; @@ -27,11 +28,12 @@ import com.github.vfyjxf.nee.utils.ModIDs; import com.glodblock.github.nei.FluidPatternTerminalRecipeTransferHandler; import appeng.util.Platform; +import codechicken.nei.NEIServerUtils; import codechicken.nei.PositionedStack; import codechicken.nei.api.IOverlayHandler; -import codechicken.nei.recipe.GuiOverlayButton; import codechicken.nei.recipe.GuiOverlayButton.ItemOverlayState; import codechicken.nei.recipe.GuiRecipe; +import codechicken.nei.recipe.GuiRecipeButton; import codechicken.nei.recipe.IRecipeHandler; import codechicken.nei.recipe.TemplateRecipeHandler; import cpw.mods.fml.common.Loader; @@ -45,20 +47,30 @@ public class NEEPatternTerminalHandler implements IOverlayHandler { public static final String INPUT_KEY = "#"; public static final String OUTPUT_KEY = "Outputs"; - public static Map ingredients = new HashMap<>();// Add the function of mouse wheel to - // switch materials + + // Add the function of mouse wheel to switch materials + public static Map ingredients = new HashMap<>(); public static final NEEPatternTerminalHandler instance = new NEEPatternTerminalHandler(); private NEEPatternTerminalHandler() {} @Override - public void overlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean shift) { - NEENetworkHandler.getInstance().sendToServer(packRecipe(recipe, recipeIndex)); + public void overlayRecipe(GuiContainer gui, IRecipeHandler handler, int recipeIndex, boolean shift) { + transferRecipe(gui, handler, recipeIndex, 1); + } - if (Loader.isModLoaded(ModIDs.FC)) { - fluidCraftOverlayRecipe(firstGui, recipe, recipeIndex, shift); + @Override + public int transferRecipe(GuiContainer gui, IRecipeHandler handler, int recipeIndex, int multiplier) { + multiplier = Math.max(1, multiplier); + + NEENetworkHandler.getInstance().sendToServer(packRecipe(handler, recipeIndex, multiplier)); + + if (Loader.isModLoaded(ModIDs.FC) && GuiUtils.isFluidCraftPatternTermEx(gui)) { + fluidCraftOverlayRecipe(gui, handler, recipeIndex, multiplier); } + + return 0; } @Override @@ -74,21 +86,21 @@ public class NEEPatternTerminalHandler implements IOverlayHandler { } @Optional.Method(modid = ModIDs.FC) - private void fluidCraftOverlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean shift) { - FluidPatternTerminalRecipeTransferHandler.INSTANCE.overlayRecipe(firstGui, recipe, recipeIndex, shift); + private void fluidCraftOverlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, + int multiplier) { + FluidPatternTerminalRecipeTransferHandler.INSTANCE.transferRecipe(firstGui, recipe, recipeIndex, multiplier); } - private PacketNEIPatternRecipe packRecipe(IRecipeHandler recipe, int recipeIndex) { + private PacketNEIPatternRecipe packRecipe(IRecipeHandler recipe, int recipeIndex, int multiplier) { if (isCraftingTableRecipe(recipe)) { return packCraftingTableRecipe(recipe, recipeIndex); } else { - return packProcessRecipe(recipe, recipeIndex); + return packProcessRecipe(recipe, recipeIndex, (int) multiplier); } } private boolean isCraftingTableRecipe(IRecipeHandler recipe) { - if (recipe instanceof TemplateRecipeHandler) { - TemplateRecipeHandler templateRecipeHandler = (TemplateRecipeHandler) recipe; + if (recipe instanceof TemplateRecipeHandler templateRecipeHandler) { String overlayIdentifier = templateRecipeHandler.getOverlayIdentifier(); return "crafting".equals(overlayIdentifier) || "crafting2x2".equals(overlayIdentifier); } else { @@ -96,7 +108,7 @@ public class NEEPatternTerminalHandler implements IOverlayHandler { } } - private PacketNEIPatternRecipe packProcessRecipe(IRecipeHandler recipe, int recipeIndex) { + private PacketNEIPatternRecipe packProcessRecipe(IRecipeHandler recipe, int recipeIndex, int multiplier) { final NBTTagCompound recipeInputs = new NBTTagCompound(); final NBTTagCompound recipeOutputs = new NBTTagCompound(); String identifier = recipe instanceof TemplateRecipeHandler ? recipe.getOverlayIdentifier() : NULL_IDENTIFIER; @@ -120,22 +132,24 @@ public class NEEPatternTerminalHandler implements IOverlayHandler { recipe, recipeIndex, identifier); + NEEPatternTerminalHandler.ingredients.clear(); for (PositionedStack positionedStack : mergedInputs) { - ItemStack currentStack = positionedStack.items[0]; + ItemStack currentStack = positionedStack.getFilteredPermutations().get(0); ItemStack preferModItem = ItemUtils.getPreferModItem(positionedStack.items); + int stackSize = currentStack.stackSize; if (preferModItem != null) { currentStack = preferModItem; - currentStack.stackSize = positionedStack.items[0].stackSize; + currentStack.stackSize = stackSize; } for (ItemStack stack : positionedStack.items) { if (Platform.isRecipePrioritized(stack) || ItemUtils.isPreferItems(stack, recipeProcessorId, identifier)) { currentStack = stack.copy(); - currentStack.stackSize = positionedStack.items[0].stackSize; + currentStack.stackSize = stackSize; break; } } @@ -154,7 +168,7 @@ public class NEEPatternTerminalHandler implements IOverlayHandler { recipeInputs.setTag( INPUT_KEY + inputIndex, - ItemUtils.writeItemStackToNBT(currentStack, new NBTTagCompound())); + ItemUtils.writeItemStackToNBT(currentStack, currentStack.stackSize * multiplier)); NEEPatternTerminalHandler.ingredients.put(INPUT_KEY + inputIndex, positionedStack); inputIndex++; } @@ -176,7 +190,7 @@ public class NEEPatternTerminalHandler implements IOverlayHandler { recipeOutputs.setTag( OUTPUT_KEY + outputIndex, - ItemUtils.writeItemStackToNBT(outputStack, new NBTTagCompound())); + ItemUtils.writeItemStackToNBT(outputStack, outputStack.stackSize * multiplier)); outputIndex++; } @@ -193,7 +207,7 @@ public class NEEPatternTerminalHandler implements IOverlayHandler { List mergedInputs = new ArrayList<>(); for (PositionedStack positionedStack : inputs) { - ItemStack currentStack = positionedStack.item; + ItemStack currentStack = positionedStack.getFilteredPermutations().get(0); ItemCombination currentValue = ItemCombination.valueOf(NEEConfig.itemCombinationMode); boolean find = false; @@ -203,9 +217,10 @@ public class NEEPatternTerminalHandler implements IOverlayHandler { if (currentValue == ItemCombination.ENABLED || isWhitelist) { for (PositionedStack storedStack : mergedInputs) { - ItemStack firstStack = storedStack.items[0]; - boolean areItemStackEqual = firstStack.isItemEqual(currentStack) - && ItemStack.areItemStackTagsEqual(firstStack, currentStack); + + ItemStack firstStack = storedStack.getFilteredPermutations().get(0); + boolean areItemStackEqual = NEIServerUtils + .areStacksSameTypeCraftingWithNBT(firstStack, currentStack); if (areItemStackEqual && (firstStack.stackSize + currentStack.stackSize) <= firstStack.getMaxStackSize()) { @@ -225,25 +240,25 @@ public class NEEPatternTerminalHandler implements IOverlayHandler { } private PacketNEIPatternRecipe packCraftingTableRecipe(IRecipeHandler recipe, int recipeIndex) { - final NBTTagCompound recipeInputs = new NBTTagCompound(); final List ingredients = recipe.getIngredientStacks(recipeIndex); + final NBTTagCompound recipeInputs = new NBTTagCompound(); NEEPatternTerminalHandler.ingredients.clear(); - for (final PositionedStack positionedStack : ingredients) { + for (PositionedStack positionedStack : ingredients) { final int col = (positionedStack.relx - 25) / 18; final int row = (positionedStack.rely - 6) / 18; int slotIndex = col + row * 3; if (positionedStack.items != null && positionedStack.items.length > 0) { - final ItemStack[] currentStackList = positionedStack.items; - ItemStack stack = positionedStack.item; + positionedStack = positionedStack.copy(); + ItemStack stack = positionedStack.getFilteredPermutations().get(0); ItemStack preferModItem = ItemUtils.getPreferModItem(positionedStack.items); if (preferModItem != null) { stack = preferModItem; } - for (ItemStack currentStack : currentStackList) { + for (ItemStack currentStack : positionedStack.items) { if (Platform.isRecipePrioritized(currentStack) || ItemUtils.isPreferItems(currentStack)) { stack = currentStack.copy(); } @@ -255,7 +270,8 @@ public class NEEPatternTerminalHandler implements IOverlayHandler { stack.setItemDamage(0); } - recipeInputs.setTag(INPUT_KEY + slotIndex, ItemUtils.writeItemStackToNBT(stack, new NBTTagCompound())); + positionedStack.item = stack; + recipeInputs.setTag(INPUT_KEY + slotIndex, ItemUtils.writeItemStackToNBT(stack, stack.stackSize)); NEEPatternTerminalHandler.ingredients.put(INPUT_KEY + slotIndex, positionedStack); } @@ -265,11 +281,9 @@ public class NEEPatternTerminalHandler implements IOverlayHandler { } @SubscribeEvent - public void onActionPerformedEventPre(GuiOverlayButton.UpdateOverlayButtonsEvent.Post event) { - if (event.gui instanceof GuiRecipe && isGuiPatternTerm((GuiRecipe) event.gui)) { - for (int i = 0; i < event.buttonList.size(); i++) { - event.buttonList.set(i, new NEEGuiOverlayButton(event.buttonList.get(i))); - } + public void onActionPerformedEventPre(GuiRecipeButton.UpdateRecipeButtonsEvent.Post event) { + if (event.gui instanceof GuiRecipe guiRecipe && isGuiPatternTerm(guiRecipe)) { + NEETerminalOverlayButton.updateRecipeButtons(guiRecipe, event.buttonList); } } diff --git a/src/main/java/com/github/vfyjxf/nee/nei/NEETerminalBookmarkContainerHandler.java b/src/main/java/com/github/vfyjxf/nee/nei/NEETerminalBookmarkContainerHandler.java index 9556084..574a8fe 100644 --- a/src/main/java/com/github/vfyjxf/nee/nei/NEETerminalBookmarkContainerHandler.java +++ b/src/main/java/com/github/vfyjxf/nee/nei/NEETerminalBookmarkContainerHandler.java @@ -1,6 +1,8 @@ package com.github.vfyjxf.nee.nei; import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.item.ItemStack; @@ -8,6 +10,7 @@ import net.minecraft.nbt.NBTTagCompound; import com.github.vfyjxf.nee.network.NEENetworkHandler; import com.github.vfyjxf.nee.network.packet.PacketNEIBookmark; +import com.github.vfyjxf.nee.utils.GuiUtils; import codechicken.nei.api.IBookmarkContainerHandler; @@ -17,9 +20,15 @@ public class NEETerminalBookmarkContainerHandler implements IBookmarkContainerHa private NEETerminalBookmarkContainerHandler() {} + @Override + public List getStorageStacks(GuiContainer guiContainer) { + return GuiUtils.getStorageStacks(guiContainer, stack -> stack.getStackSize() > 0).stream() + .map(stack -> stack.getItemStack().copy()).collect(Collectors.toList()); + } + @Override public void pullBookmarkItemsFromContainer(GuiContainer guiContainer, ArrayList bookmarkItems) { - NBTTagCompound nbtBookmarkItems = new NBTTagCompound(); + final NBTTagCompound nbtBookmarkItems = new NBTTagCompound(); for (int i = 0; i < bookmarkItems.size(); i++) { nbtBookmarkItems.setTag("#" + i, packBookmarkItem(bookmarkItems.get(i))); @@ -31,5 +40,4 @@ public class NEETerminalBookmarkContainerHandler implements IBookmarkContainerHa private NBTTagCompound packBookmarkItem(ItemStack bookmarkItem) { return bookmarkItem.writeToNBT(new NBTTagCompound()); } - } diff --git a/src/main/java/com/github/vfyjxf/nee/nei/NEEGuiOverlayButton.java b/src/main/java/com/github/vfyjxf/nee/nei/NEETerminalOverlayButton.java similarity index 60% rename from src/main/java/com/github/vfyjxf/nee/nei/NEEGuiOverlayButton.java rename to src/main/java/com/github/vfyjxf/nee/nei/NEETerminalOverlayButton.java index ce2f24e..296bcbd 100644 --- a/src/main/java/com/github/vfyjxf/nee/nei/NEEGuiOverlayButton.java +++ b/src/main/java/com/github/vfyjxf/nee/nei/NEETerminalOverlayButton.java @@ -1,14 +1,15 @@ package com.github.vfyjxf.nee.nei; +import java.util.List; import java.util.Map; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.resources.I18n; -import org.lwjgl.input.Keyboard; import org.lwjgl.opengl.GL11; import com.github.vfyjxf.nee.config.NEEConfig; +import com.github.vfyjxf.nee.nei.NEETerminalOverlayButton.NEEItemOverlayState; import com.github.vfyjxf.nee.utils.Ingredient; import codechicken.lib.gui.GuiDraw; @@ -19,9 +20,12 @@ import codechicken.nei.drawable.DrawableBuilder; import codechicken.nei.recipe.GuiOverlayButton; import codechicken.nei.recipe.GuiOverlayButton.ItemOverlayFormat; import codechicken.nei.recipe.GuiOverlayButton.ItemOverlayState; -import codechicken.nei.recipe.IRecipeHandler; +import codechicken.nei.recipe.GuiRecipe; +import codechicken.nei.recipe.GuiRecipeButton; +import codechicken.nei.recipe.RecipeHandlerRef; +import codechicken.nei.util.NEIMouseUtils; -public class NEEGuiOverlayButton extends GuiOverlayButton { +public class NEETerminalOverlayButton extends GuiOverlayButton { public static class NEEItemOverlayState extends ItemOverlayState { @@ -61,8 +65,8 @@ public class NEEGuiOverlayButton extends GuiOverlayButton { } public void draw(ItemOverlayFormat format) { - boolean doCraftingHelp = Keyboard.isKeyDown(NEIClientConfig.getKeyBinding("nee.nopreview")) - || Keyboard.isKeyDown(NEIClientConfig.getKeyBinding("nee.preview")); + boolean doCraftingHelp = NEIClientConfig.isKeyHashDown("nee.nopreview") + || NEIClientConfig.isKeyHashDown("nee.preview"); if (this.ingredient.isCraftable() && (!this.isCraftingTerm || doCraftingHelp && this.ingredient.requiresToCraft())) { @@ -84,50 +88,52 @@ public class NEEGuiOverlayButton extends GuiOverlayButton { } } - public NEEGuiOverlayButton(GuiContainer firstGui, IRecipeHandler handler, int recipeIndex, int xPosition, - int yPosition, int width, int height) { - super(firstGui, handler, recipeIndex, xPosition, yPosition, width, height); + public NEETerminalOverlayButton(GuiContainer firstGui, RecipeHandlerRef handlerRef, int xPosition, int yPosition) { + super(firstGui, handlerRef, xPosition, yPosition); if (NEEConfig.noShift) { setRequireShiftForOverlayRecipe(false); } } - public NEEGuiOverlayButton(GuiOverlayButton button) { - this( - button.firstGui, - button.handler, - button.recipeIndex, - button.xPosition, - button.yPosition, - button.width, - button.height); + public NEETerminalOverlayButton(GuiOverlayButton button) { + this(button.firstGui, button.handlerRef, button.xPosition, button.yPosition); + } + + @Override + public void mouseReleased(int mousex, int mousey) { + if (this.firstGui != null && !NEECraftingPreviewHandler.instance + .handle(this.firstGui, this.handlerRef.handler, this.handlerRef.recipeIndex)) { + super.mouseReleased(mousex, mousey); + } } @Override public Map handleHotkeys(GuiContainer gui, int mousex, int mousey, Map hotkeys) { hotkeys = super.handleHotkeys(gui, mousex, mousey, hotkeys); - if (ingredientsOverlay().stream().anyMatch( - btn -> btn instanceof NEEItemOverlayState && showCraftingHotkeys((NEEItemOverlayState) btn))) { - final String previewKeyName = NEIClientConfig.getKeyName("nee.preview"); - - if (previewKeyName != null) { - hotkeys.put(previewKeyName + " + Click", I18n.format("neenergistics.gui.tooltip.crafting.preview")); - } - - final String noPreviewKeyName = NEIClientConfig.getKeyName("nee.nopreview"); - - if (noPreviewKeyName != null) { - hotkeys.put(noPreviewKeyName + " + Click", I18n.format("neenergistics.gui.tooltip.crafting.nopreview")); - } + if (ingredientsOverlay().stream().allMatch( + state -> state instanceof NEEItemOverlayState overlayState && showCraftingHotkeys(overlayState))) { + hotkeys.put( + NEIClientConfig.getKeyName("nee.preview", 0, NEIMouseUtils.MOUSE_BTN_LMB), + I18n.format("neenergistics.gui.tooltip.crafting.preview")); + hotkeys.put( + NEIClientConfig.getKeyName("nee.nopreview", 0, NEIMouseUtils.MOUSE_BTN_LMB), + I18n.format("neenergistics.gui.tooltip.crafting.nopreview")); } return hotkeys; } private static boolean showCraftingHotkeys(NEEItemOverlayState button) { - return button.isCraftingTerm() && button.getIngredient().isCraftable() - && button.getIngredient().requiresToCraft(); + return button.getIngredient().isCraftable() || !button.getIngredient().requiresToCraft(); + } + + public static void updateRecipeButtons(GuiRecipe guiRecipe, List buttonList) { + for (int i = 0; i < buttonList.size(); i++) { + if (buttonList.get(i) instanceof GuiOverlayButton btn) { + buttonList.set(i, new NEETerminalOverlayButton(btn)); + } + } } } diff --git a/src/main/java/com/github/vfyjxf/nee/network/packet/PacketArcaneRecipe.java b/src/main/java/com/github/vfyjxf/nee/network/packet/PacketArcaneRecipe.java index 7393455..41eef67 100644 --- a/src/main/java/com/github/vfyjxf/nee/network/packet/PacketArcaneRecipe.java +++ b/src/main/java/com/github/vfyjxf/nee/network/packet/PacketArcaneRecipe.java @@ -16,6 +16,7 @@ import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; import cpw.mods.fml.common.network.simpleimpl.MessageContext; import cpw.mods.fml.relauncher.ReflectionHelper; import io.netty.buffer.ByteBuf; +import thaumicenergistics.client.gui.GuiArcaneCraftingTerminal; import thaumicenergistics.common.container.ContainerKnowledgeInscriber; /** @@ -68,7 +69,30 @@ public class PacketArcaneRecipe implements IMessage { } container.onCraftMatrixChanged(craftMatrix[0].inventory); } + } else if (container.inventorySlots instanceof GuiArcaneCraftingTerminal) { + ItemStack[] recipeInput = new ItemStack[9]; + NBTTagCompound currentStack; + for (int i = 0; i < recipeInput.length; i++) { + currentStack = (NBTTagCompound) message.input.getTag("#" + i); + recipeInput[i] = currentStack == null ? null : ItemUtils.loadItemStackFromNBT(currentStack); + } + Field craftingSlots = ReflectionHelper.findField(GuiArcaneCraftingTerminal.class, "craftingSlots"); + SlotFakeCraftingMatrix[] craftMatrix = this + .getCraftingSlots(craftingSlots, (GuiArcaneCraftingTerminal) container.inventorySlots); + + if (craftMatrix != null && message.input != null) { + for (int i = 0; i < recipeInput.length; i++) { + ItemStack currentItem = null; + if (recipeInput[i] != null) { + currentItem = recipeInput[i].copy(); + } + craftMatrix[i].putStack(currentItem); + } + container.onCraftMatrixChanged(craftMatrix[0].inventory); + } + } + return null; } @@ -80,5 +104,14 @@ public class PacketArcaneRecipe implements IMessage { } return null; } + + private SlotFakeCraftingMatrix[] getCraftingSlots(Field field, GuiArcaneCraftingTerminal container) { + try { + return (SlotFakeCraftingMatrix[]) field.get(container); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + return null; + } } } diff --git a/src/main/java/com/github/vfyjxf/nee/network/packet/PacketNEIBookmark.java b/src/main/java/com/github/vfyjxf/nee/network/packet/PacketNEIBookmark.java index fd4a36c..587762d 100644 --- a/src/main/java/com/github/vfyjxf/nee/network/packet/PacketNEIBookmark.java +++ b/src/main/java/com/github/vfyjxf/nee/network/packet/PacketNEIBookmark.java @@ -1,26 +1,38 @@ package com.github.vfyjxf.nee.network.packet; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.inventory.Container; +import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.util.ForgeDirection; import com.github.vfyjxf.nee.utils.ItemUtils; +import appeng.api.networking.IGrid; +import appeng.api.networking.energy.IEnergyGrid; +import appeng.api.networking.energy.IEnergySource; +import appeng.api.networking.security.BaseActionSource; +import appeng.api.networking.security.PlayerSource; +import appeng.api.storage.IMEMonitor; import appeng.api.storage.data.IAEItemStack; -import appeng.container.AEBaseContainer; +import appeng.container.implementations.ContainerMEMonitorable; import appeng.util.InventoryAdaptor; import appeng.util.Platform; import appeng.util.item.AEItemStack; +import cpw.mods.fml.common.Loader; 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 cpw.mods.fml.relauncher.ReflectionHelper; +import cpw.mods.fml.relauncher.ReflectionHelper.UnableToFindFieldException; import io.netty.buffer.ByteBuf; +import thaumicenergistics.common.container.ContainerPartArcaneCraftingTerminal; public class PacketNEIBookmark implements IMessage { - NBTTagCompound bookmarkItems; + private NBTTagCompound bookmarkItems; public PacketNEIBookmark() {} @@ -42,27 +54,84 @@ public class PacketNEIBookmark implements IMessage { @Override public IMessage onMessage(PacketNEIBookmark message, MessageContext ctx) { - EntityPlayerMP player = ctx.getServerHandler().playerEntity; - Container container = player.openContainer; + final EntityPlayerMP player = ctx.getServerHandler().playerEntity; + final Container container = player.openContainer; - if (container instanceof AEBaseContainer && message.bookmarkItems != null) { - AEBaseContainer baseContainer = (AEBaseContainer) container; + if (container instanceof ContainerMEMonitorable monitorable && message.bookmarkItems != null) { + final IMEMonitor monitor = monitorable.getMonitor(); + if (monitor != null) { + final IEnergySource energy = monitorable.getPowerSource(); + final BaseActionSource actionSource = monitorable.getActionSource(); - for (Object key : message.bookmarkItems.func_150296_c()) { - final IAEItemStack request = AEItemStack - .create(ItemUtils.loadItemStackFromNBT(message.bookmarkItems.getCompoundTag((String) key))); - final IAEItemStack extracted = Platform.poweredExtraction( - baseContainer.getPowerSource(), - baseContainer.getCellInventory(), - request, - baseContainer.getActionSource()); + for (Object key : message.bookmarkItems.func_150296_c()) { + final ItemStack bookmarkItem = ItemUtils + .loadItemStackFromNBT(message.bookmarkItems.getCompoundTag((String) key)); + bookmarkItem.stackSize = getFreeStackSize(player, bookmarkItem); - if (extracted != null) { - InventoryAdaptor.getAdaptor(player, ForgeDirection.UNKNOWN).addItems(extracted.getItemStack()); + if (bookmarkItem.stackSize > 0) { + final AEItemStack requestStack = AEItemStack.create(bookmarkItem); + final IAEItemStack extractedStack = Platform + .poweredExtraction(energy, monitor, requestStack, actionSource); + + if (extractedStack != null) { + InventoryAdaptor.getAdaptor(player, ForgeDirection.UNKNOWN) + .addItems(extractedStack.getItemStack()); + } + } } } + + } else if (Loader.isModLoaded("thaumcraftneiplugin") + && container instanceof ContainerPartArcaneCraftingTerminal act) { + final IMEMonitor monitor = getMonitor(container); + final IGrid grid = act.getHostGrid(); + if (grid == null || monitor == null) return null; + final IEnergyGrid energy = grid.getCache(IEnergyGrid.class); + final BaseActionSource actionSource = new PlayerSource(player, act.terminal); + + for (Object key : message.bookmarkItems.func_150296_c()) { + final ItemStack bookmarkItem = ItemUtils + .loadItemStackFromNBT(message.bookmarkItems.getCompoundTag((String) key)); + bookmarkItem.stackSize = getFreeStackSize(player, bookmarkItem); + + if (bookmarkItem.stackSize > 0) { + final AEItemStack requestStack = AEItemStack.create(bookmarkItem); + final IAEItemStack extractedStack = Platform + .poweredExtraction(energy, monitor, requestStack, actionSource); + + if (extractedStack != null) { + InventoryAdaptor.getAdaptor(player, ForgeDirection.UNKNOWN) + .addItems(extractedStack.getItemStack()); + } + } + } + + } + + return null; + } + + private int getFreeStackSize(EntityPlayer player, ItemStack itemStack) { + int freeStackSize = 0; + + for (ItemStack slotStack : player.inventory.mainInventory) { + if (slotStack == null) { // Empty slot, stack fits completely + freeStackSize += itemStack.getMaxStackSize(); + } else if (slotStack.isItemEqual(itemStack)) { + freeStackSize += itemStack.getMaxStackSize() - slotStack.stackSize; + } } + return Math.min(itemStack.stackSize, freeStackSize); + } + + private IMEMonitor getMonitor(Container container) { + + try { + return (IMEMonitor) ReflectionHelper.findField(container.getClass(), "monitor") + .get(container); + } catch (UnableToFindFieldException | IllegalAccessException e) {} + return null; } } diff --git a/src/main/java/com/github/vfyjxf/nee/network/packet/PacketSlotStackChange.java b/src/main/java/com/github/vfyjxf/nee/network/packet/PacketSlotStackChange.java index c0888f0..bc3da7b 100644 --- a/src/main/java/com/github/vfyjxf/nee/network/packet/PacketSlotStackChange.java +++ b/src/main/java/com/github/vfyjxf/nee/network/packet/PacketSlotStackChange.java @@ -6,10 +6,12 @@ import java.util.List; import net.minecraft.inventory.Container; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; +import com.github.vfyjxf.nee.utils.GuiUtils; import com.github.vfyjxf.nee.utils.ItemUtils; +import com.glodblock.github.common.item.ItemFluidPacket; +import codechicken.nei.recipe.StackInfo; import cpw.mods.fml.common.network.ByteBufUtils; import cpw.mods.fml.common.network.simpleimpl.IMessage; import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; @@ -52,7 +54,7 @@ public class PacketSlotStackChange implements IMessage { @Override public void toBytes(ByteBuf buf) { - ByteBufUtils.writeTag(buf, ItemUtils.writeItemStackToNBT(this.stack, new NBTTagCompound())); + ByteBufUtils.writeTag(buf, ItemUtils.writeItemStackToNBT(this.stack, this.stack.stackSize)); buf.writeInt(this.craftingSlots.size()); for (Integer craftingSlot : this.craftingSlots) { buf.writeInt(craftingSlot); @@ -66,6 +68,12 @@ public class PacketSlotStackChange implements IMessage { Container container = ctx.getServerHandler().playerEntity.openContainer; ItemStack nextStack = message.getStack(); if (nextStack != null) { + + if (GuiUtils.isFluidCraftPatternContainer(container) + && StackInfo.itemStackToNBT(nextStack).hasKey("gtFluidName")) { + nextStack = ItemFluidPacket.newStack(StackInfo.getFluid(nextStack)); + } + for (Integer craftingSlot : message.getCraftingSlots()) { Slot currentSlot = container.getSlot(craftingSlot); if (currentSlot != 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 0a4c839..f41a53b 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 @@ -4,9 +4,14 @@ import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.inventory.Container; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +import com.github.vfyjxf.nee.utils.GuiUtils; +import com.glodblock.github.common.item.ItemFluidPacket; import appeng.container.AEBaseContainer; import appeng.container.implementations.ContainerPatternTerm; +import codechicken.nei.recipe.StackInfo; import cpw.mods.fml.common.network.simpleimpl.IMessage; import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; import cpw.mods.fml.common.network.simpleimpl.MessageContext; @@ -66,15 +71,19 @@ public class PacketStackCountChange implements IMessage { } Slot currentSlot = container.getSlot(message.getSlotIndex()); - for (int i = 0; i < Math.abs(message.getChangeCount()); i++) { - int currentStackSize = message.getChangeCount() > 0 ? currentSlot.getStack().stackSize + 1 - : currentSlot.getStack().stackSize - 1; - if (currentStackSize > 0) { - ItemStack nextStack = currentSlot.getStack().copy(); - nextStack.stackSize = currentStackSize; - currentSlot.putStack(nextStack); + + if (currentSlot.getHasStack()) { + ItemStack stack = currentSlot.getStack(); + + if (GuiUtils.isFluidCraftPatternContainer(container) + && StackInfo.itemStackToNBT(stack).hasKey("gtFluidName")) { + FluidStack fluid = StackInfo.getFluid(stack); + fluid.amount = Math.max(1, fluid.amount + message.getChangeCount()); + currentSlot.putStack(ItemFluidPacket.newStack(fluid)); } else { - break; + stack = stack.copy(); + stack.stackSize = Math.max(1, stack.stackSize + message.getChangeCount()); + currentSlot.putStack(stack); } } } 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 5529d23..673e2a1 100644 --- a/src/main/java/com/github/vfyjxf/nee/proxy/ClientProxy.java +++ b/src/main/java/com/github/vfyjxf/nee/proxy/ClientProxy.java @@ -5,6 +5,7 @@ import net.minecraftforge.common.MinecraftForge; import com.github.vfyjxf.nee.NEECommands; import com.github.vfyjxf.nee.client.GuiEventHandler; +import com.github.vfyjxf.nee.nei.NEECraftingPreviewHandler; import com.github.vfyjxf.nee.nei.NEECraftingTerminalHandler; import com.github.vfyjxf.nee.nei.NEEExtremeAutoCrafterHandler; import com.github.vfyjxf.nee.nei.NEEKnowledgeInscriberHandler; @@ -25,5 +26,6 @@ public class ClientProxy extends CommonProxy { MinecraftForge.EVENT_BUS.register(NEEPatternTerminalHandler.instance); MinecraftForge.EVENT_BUS.register(NEEExtremeAutoCrafterHandler.instance); MinecraftForge.EVENT_BUS.register(NEEKnowledgeInscriberHandler.instance); + MinecraftForge.EVENT_BUS.register(NEECraftingPreviewHandler.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 dbccf0d..90cd0d3 100644 --- a/src/main/java/com/github/vfyjxf/nee/utils/GuiUtils.java +++ b/src/main/java/com/github/vfyjxf/nee/utils/GuiUtils.java @@ -1,7 +1,12 @@ package com.github.vfyjxf.nee.utils; +import java.util.ArrayList; +import java.util.List; +import java.util.function.Predicate; + import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; @@ -11,12 +16,17 @@ import com.glodblock.github.client.gui.GuiFluidPatternTerminalEx; import com.glodblock.github.client.gui.container.ContainerFluidPatternTerminal; import com.glodblock.github.client.gui.container.ContainerFluidPatternTerminalEx; +import appeng.api.storage.data.IAEItemStack; +import appeng.api.storage.data.IItemList; import appeng.client.gui.implementations.GuiPatternTerm; import appeng.client.gui.implementations.GuiPatternTermEx; +import appeng.client.me.ItemRepo; import appeng.container.implementations.ContainerPatternTerm; import appeng.container.implementations.ContainerPatternTermEx; import appeng.helpers.IContainerCraftingPacket; import cpw.mods.fml.common.Loader; +import cpw.mods.fml.relauncher.ReflectionHelper; +import cpw.mods.fml.relauncher.ReflectionHelper.UnableToFindFieldException; /** * @author vfyjxf @@ -44,14 +54,14 @@ public class GuiUtils { return craftMatrix.equals(slot.inventory); } + public static boolean isFluidCraftPatternContainer(Container container) { + return isFluidCraftModloaded && (container instanceof ContainerFluidPatternTerminal + || container instanceof ContainerFluidPatternTerminalEx); + } + public static boolean isPatternContainer(Container container) { - if (isFluidCraftModloaded) { - return container instanceof ContainerPatternTerm || container instanceof ContainerPatternTermEx - || container instanceof ContainerFluidPatternTerminal - || container instanceof ContainerFluidPatternTerminalEx; - } else { - return container instanceof ContainerPatternTerm || container instanceof ContainerPatternTermEx; - } + return container instanceof ContainerPatternTerm || container instanceof ContainerPatternTermEx + || isFluidCraftPatternContainer(container); } public static boolean isFluidCraftPatternTermEx(GuiScreen guiScreen) { @@ -59,13 +69,51 @@ public class GuiUtils { } public static boolean isPatternTerm(GuiScreen guiScreen) { - if (isFluidCraftModloaded) { - return guiScreen instanceof GuiPatternTerm || guiScreen instanceof GuiPatternTermEx - || guiScreen instanceof GuiFluidPatternTerminal - || guiScreen instanceof GuiFluidPatternTerminalEx; - } else { - return guiScreen instanceof GuiPatternTerm || guiScreen instanceof GuiPatternTermEx; + return guiScreen instanceof GuiPatternTerm || guiScreen instanceof GuiPatternTermEx + || isFluidCraftModloaded && (guiScreen instanceof GuiFluidPatternTerminal + || guiScreen instanceof GuiFluidPatternTerminalEx); + } + + public static ItemRepo getItemRepo(GuiContainer termGui) { + Class clazz = termGui.getClass(); + ItemRepo repo = null; + + while (repo == null && clazz != null) { + try { + repo = (ItemRepo) ReflectionHelper.findField(clazz, "repo").get(termGui); + } catch (UnableToFindFieldException | IllegalAccessException e) { + clazz = clazz.getSuperclass(); + } } + + return repo; + } + + public static List getStorageStacks(GuiContainer termGui, Predicate predicate) { + final List storageStacks = new ArrayList<>(); + + if (termGui != null) { + final ItemRepo repo = GuiUtils.getItemRepo(termGui); + + if (repo != null) { + try { + @SuppressWarnings("unchecked") + final IItemList list = (IItemList) ReflectionHelper + .findField(ItemRepo.class, "list").get(repo); + + for (IAEItemStack stack : list) { + if (predicate.test(stack)) { + storageStacks.add(stack.copy()); + } + } + + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } + } + + return storageStacks; } } 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 a7e63d9..8a3abcd 100644 --- a/src/main/java/com/github/vfyjxf/nee/utils/IngredientTracker.java +++ b/src/main/java/com/github/vfyjxf/nee/utils/IngredientTracker.java @@ -2,7 +2,6 @@ package com.github.vfyjxf.nee.utils; import java.util.ArrayList; import java.util.List; -import java.util.function.Predicate; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.inventory.GuiContainer; @@ -14,13 +13,9 @@ import com.github.vfyjxf.nee.network.NEENetworkHandler; import com.github.vfyjxf.nee.network.packet.PacketCraftingRequest; import appeng.api.storage.data.IAEItemStack; -import appeng.api.storage.data.IItemList; -import appeng.client.me.ItemRepo; import appeng.util.item.AEItemStack; import codechicken.nei.PositionedStack; import codechicken.nei.recipe.IRecipeHandler; -import cpw.mods.fml.relauncher.ReflectionHelper; -import cpw.mods.fml.relauncher.ReflectionHelper.UnableToFindFieldException; public class IngredientTracker { @@ -39,7 +34,7 @@ public class IngredientTracker { } for (Ingredient ingredient : this.ingredients) { - for (IAEItemStack stack : getStorageStacks(IAEItemStack::isCraftable)) { + for (IAEItemStack stack : GuiUtils.getStorageStacks(this.termGui, IAEItemStack::isCraftable)) { if (ingredient.getIngredient().contains(stack.getItemStack())) { ingredient.setCraftableIngredient(stack.getItemStack()); } @@ -49,48 +44,6 @@ public class IngredientTracker { this.calculateIngredients(); } - private List getStorageStacks(Predicate predicate) { - List storageStacks = new ArrayList<>(); - - if (termGui != null) { - ItemRepo repo = getItemRepo(termGui); - - if (repo != null) { - try { - @SuppressWarnings("unchecked") - IItemList list = (IItemList) ReflectionHelper - .findField(ItemRepo.class, "list").get(repo); - - for (IAEItemStack stack : list) { - if (predicate.test(stack)) { - storageStacks.add(stack.copy()); - } - } - - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - } - } - - return storageStacks; - } - - private ItemRepo getItemRepo(GuiContainer termGui) { - Class clazz = termGui.getClass(); - ItemRepo repo = null; - - while (repo == null && clazz != null) { - try { - repo = (ItemRepo) ReflectionHelper.findField(clazz, "repo").get(termGui); - } catch (UnableToFindFieldException | IllegalAccessException e) { - clazz = clazz.getSuperclass(); - } - } - - return repo; - } - public List getIngredients() { return ingredients; } @@ -178,7 +131,8 @@ public class IngredientTracker { @SuppressWarnings("unchecked") public void calculateIngredients() { - List stacks = getStorageStacks(stack -> NEEConfig.matchOtherItems || stack.isCraftable()); + final List stacks = GuiUtils + .getStorageStacks(this.termGui, stack -> NEEConfig.matchOtherItems || stack.isCraftable()); for (Ingredient ingredient : this.ingredients) { for (IAEItemStack stack : stacks) { @@ -193,10 +147,10 @@ public class IngredientTracker { } } - List inventoryStacks = new ArrayList<>(); + final List inventoryStacks = new ArrayList<>(); for (Slot slot : (List) termGui.inventorySlots.inventorySlots) { - boolean canGetStack = slot != null && slot.getHasStack() + final boolean canGetStack = slot != null && slot.getHasStack() && slot.getStack().stackSize > 0 && slot.isItemValid(slot.getStack()) && slot.canTakeStack(Minecraft.getMinecraft().thePlayer); 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 7aad6c3..751438c 100644 --- a/src/main/java/com/github/vfyjxf/nee/utils/ItemUtils.java +++ b/src/main/java/com/github/vfyjxf/nee/utils/ItemUtils.java @@ -19,7 +19,7 @@ import com.github.vfyjxf.nee.processor.RecipeProcessor; import com.google.gson.Gson; import com.google.gson.JsonSyntaxException; -import codechicken.nei.PositionedStack; +import codechicken.nei.NEIServerUtils; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.registry.GameRegistry; @@ -183,14 +183,11 @@ 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; + public static int getPermutationIndex(ItemStack stack, List items) { + + for (int index = 0; index < items.size(); index++) { + if (NEIServerUtils.areStacksSameTypeCraftingWithNBT(items.get(index), stack)) { + return index; } } return -1; @@ -212,9 +209,9 @@ public final class ItemUtils { + "}"; } - public static NBTTagCompound writeItemStackToNBT(ItemStack itemStack, NBTTagCompound tag) { - itemStack.writeToNBT(tag); - tag.setInteger("Count", itemStack.stackSize); + public static NBTTagCompound writeItemStackToNBT(ItemStack itemStack, int stackSize) { + NBTTagCompound tag = itemStack.writeToNBT(new NBTTagCompound()); + tag.setInteger("Count", stackSize); return tag; } diff --git a/src/main/resources/assets/neenergistics/lang/en_US.lang b/src/main/resources/assets/neenergistics/lang/en_US.lang index 27d2f94..b5705d4 100644 --- a/src/main/resources/assets/neenergistics/lang/en_US.lang +++ b/src/main/resources/assets/neenergistics/lang/en_US.lang @@ -1,6 +1,9 @@ neenergistics.gui.tooltip.crafting.preview=Request missing items neenergistics.gui.tooltip.crafting.nopreview=Request missing items (No Preview) +neenergistics.gui.tooltip.ingredient.permutation=Change Item +neenergistics.gui.tooltip.ingredient.count=Change Count + nei.options.keys.nee=NotEnoughEnergistics nei.options.keys.nee.count=Change Item Count nei.options.keys.nee.ingredient=Choose ingredient