diff --git a/CODEOWNERS b/CODEOWNERS deleted file mode 100644 index a6b5f68..0000000 --- a/CODEOWNERS +++ /dev/null @@ -1,3 +0,0 @@ -# Any Github changes require admin approval -/.github/** @GTNewHorizons/admin - diff --git a/build.gradle b/build.gradle index b647108..29b7be1 100644 --- a/build.gradle +++ b/build.gradle @@ -63,7 +63,7 @@ idea { } } -if(JavaVersion.current() != JavaVersion.VERSION_1_8) { +if (JavaVersion.current() != JavaVersion.VERSION_1_8) { throw new GradleException("This project requires Java 8, but it's running on " + JavaVersion.current()) } @@ -95,49 +95,49 @@ String scalaSourceDir = "src/main/scala/" String targetPackageJava = javaSourceDir + modGroup.toString().replaceAll("\\.", "/") String targetPackageScala = scalaSourceDir + modGroup.toString().replaceAll("\\.", "/") -if((getFile(targetPackageJava).exists() || getFile(targetPackageScala).exists()) == false) { +if (!(getFile(targetPackageJava).exists() || getFile(targetPackageScala).exists())) { throw new GradleException("Could not resolve \"modGroup\"! Could not find " + targetPackageJava + " or " + targetPackageScala) } -if(apiPackage) { +if (apiPackage) { targetPackageJava = javaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + apiPackage.toString().replaceAll("\\.", "/") targetPackageScala = scalaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + apiPackage.toString().replaceAll("\\.", "/") - if((getFile(targetPackageJava).exists() || getFile(targetPackageScala).exists()) == false) { + if (!(getFile(targetPackageJava).exists() || getFile(targetPackageScala).exists())) { throw new GradleException("Could not resolve \"apiPackage\"! Could not find " + targetPackageJava + " or " + targetPackageScala) } } -if(accessTransformersFile) { +if (accessTransformersFile) { String targetFile = "src/main/resources/META-INF/" + accessTransformersFile - if(getFile(targetFile).exists() == false) { + if (!getFile(targetFile).exists()) { throw new GradleException("Could not resolve \"accessTransformersFile\"! Could not find " + targetFile) } } -if(usesMixins.toBoolean()) { - if(mixinsPackage.isEmpty() || mixinPlugin.isEmpty()) { +if (usesMixins.toBoolean()) { + if (mixinsPackage.isEmpty() || mixinPlugin.isEmpty()) { throw new GradleException("\"mixinPlugin\" requires \"mixinsPackage\" and \"mixinPlugin\" to be set!") } targetPackageJava = javaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + mixinsPackage.toString().replaceAll("\\.", "/") targetPackageScala = scalaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + mixinsPackage.toString().replaceAll("\\.", "/") - if((getFile(targetPackageJava).exists() || getFile(targetPackageScala).exists()) == false) { + if (!(getFile(targetPackageJava).exists() || getFile(targetPackageScala).exists())) { throw new GradleException("Could not resolve \"mixinsPackage\"! Could not find " + targetPackageJava + " or " + targetPackageScala) } String targetFileJava = javaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + mixinPlugin.toString().replaceAll("\\.", "/") + ".java" String targetFileScala = scalaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + mixinPlugin.toString().replaceAll("\\.", "/") + ".scala" String targetFileScalaJava = scalaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + mixinPlugin.toString().replaceAll("\\.", "/") + ".java" - if((getFile(targetFileJava).exists() || getFile(targetFileScala).exists() || getFile(targetFileScalaJava).exists()) == false) { + if (!(getFile(targetFileJava).exists() || getFile(targetFileScala).exists() || getFile(targetFileScalaJava).exists())) { throw new GradleException("Could not resolve \"mixinPlugin\"! Could not find " + targetFileJava + " or " + targetFileScala + " or " + targetFileScalaJava) } } -if(coreModClass) { +if (coreModClass) { String targetFileJava = javaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + coreModClass.toString().replaceAll("\\.", "/") + ".java" String targetFileScala = scalaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + coreModClass.toString().replaceAll("\\.", "/") + ".scala" String targetFileScalaJava = scalaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + coreModClass.toString().replaceAll("\\.", "/") + ".java" - if((getFile(targetFileJava).exists() || getFile(targetFileScala).exists() || getFile(targetFileScalaJava).exists()) == false) { + if (!(getFile(targetFileJava).exists() || getFile(targetFileScala).exists() || getFile(targetFileScalaJava).exists())) { throw new GradleException("Could not resolve \"coreModClass\"! Could not find " + targetFileJava + " or " + targetFileScala + " or " + targetFileScalaJava) } } @@ -150,25 +150,12 @@ configurations.all { System.setProperty("org.gradle.internal.http.socketTimeout", 120000 as String) } -// Fix Jenkins' Git: chmod a file should not be detected as a change and append a '.dirty' to the version -'git config core.fileMode false'.execute() - -// Pulls version first from the VERSION env and then git tag -String identifiedVersion -try { - String versionOverride = System.getenv("VERSION") ?: null - identifiedVersion = versionOverride == null ? gitVersion() : versionOverride - version = minecraftVersion + "-" + identifiedVersion -} -catch (Exception e) { - throw new IllegalStateException("This mod must be version controlled by Git AND the repository must provide at least one tag, or the VERSION override must be set!"); -} +version = minecraftVersion + "-" + modVersion group = modGroup -if(project.hasProperty("customArchiveBaseName") && customArchiveBaseName) { +if (project.hasProperty("customArchiveBaseName") && customArchiveBaseName) { archivesBaseName = customArchiveBaseName -} -else { +} else { archivesBaseName = modId } @@ -178,22 +165,22 @@ minecraft { if (replaceGradleTokenInFile) { replaceIn replaceGradleTokenInFile - if(gradleTokenModId) { + if (gradleTokenModId) { replace gradleTokenModId, modId } - if(gradleTokenModName) { + if (gradleTokenModName) { replace gradleTokenModName, modName } - if(gradleTokenVersion) { - replace gradleTokenVersion, versionDetails().lastTag + if (gradleTokenVersion) { + replace gradleTokenVersion, modVersion } - if(gradleTokenGroupName) { + if (gradleTokenGroupName) { replace gradleTokenGroupName, modGroup } } } -if(file("addon.gradle").exists()) { +if (file("addon.gradle").exists()) { apply from: "addon.gradle" } @@ -210,7 +197,7 @@ repositories { name = "Overmind forge repo mirror" url = "https://gregtech.overminddl1.com/" } - if(usesMixins.toBoolean()) { + if (usesMixins.toBoolean()) { maven { name = "sponge" url = "https://repo.spongepowered.org/repository/maven-public" @@ -222,7 +209,7 @@ repositories { } dependencies { - if(usesMixins.toBoolean()) { + if (usesMixins.toBoolean()) { annotationProcessor("org.ow2.asm:asm-debug-all:5.0.3") annotationProcessor("com.google.guava:guava:24.1.1-jre") annotationProcessor("com.google.code.gson:gson:2.8.6") @@ -247,7 +234,7 @@ def refMap = "${tasks.compileJava.temporaryDir}" + File.separator + mixingConfig def mixinSrg = "${tasks.reobf.temporaryDir}" + File.separator + "mixins.srg" task generateAssets { - if(usesMixins.toBoolean()) { + if (usesMixins.toBoolean()) { getFile("/src/main/resources/mixins." + modId + ".json").text = """{ "required": true, "minVersion": "0.7.11", @@ -294,20 +281,20 @@ jar { attributes(getManifestAttributes()) } - if(usesShadowedDependencies.toBoolean()) { + if (usesShadowedDependencies.toBoolean()) { dependsOn(shadowJar) enabled = false } } reobf { - if(usesMixins.toBoolean()) { + if (usesMixins.toBoolean()) { addExtraSrgFile mixinSrg } } afterEvaluate { - if(usesMixins.toBoolean()) { + if (usesMixins.toBoolean()) { tasks.compileJava { options.compilerArgs += [ "-AreobfSrgFile=${tasks.reobf.srg}", @@ -324,14 +311,14 @@ afterEvaluate { runClient { def arguments = [] - if(usesMixins.toBoolean()) { + if (usesMixins.toBoolean()) { arguments += [ "--mods=../build/libs/$modId-${version}.jar", "--tweakClass org.spongepowered.asm.launch.MixinTweaker" ] } - if(developmentEnvironmentUserName) { + if (developmentEnvironmentUserName) { arguments += [ "--username", developmentEnvironmentUserName @@ -363,59 +350,59 @@ tasks.withType(JavaExec).configureEach { } processResources -{ - // this will ensure that this task is redone when the versions change. - inputs.property "version", project.version - inputs.property "mcversion", project.minecraft.version + { + // this will ensure that this task is redone when the versions change. + inputs.property "version", version + inputs.property "mcversion", project.minecraft.version - // replace stuff in mcmod.info, nothing else - from(sourceSets.main.resources.srcDirs) { - include 'mcmod.info' + // replace stuff in mcmod.info, nothing else + from(sourceSets.main.resources.srcDirs) { + include 'mcmod.info' - // replace version and mcversion - expand "minecraftVersion": project.minecraft.version, - "modVersion": versionDetails().lastTag, - "modId": modId, - "modName": modName - } + // replace version and mcversion + expand "minecraftVersion": project.minecraft.version, + "modVersion": version, + "modId": modId, + "modName": modName + } - if(usesMixins.toBoolean()) { - from refMap - } + if (usesMixins.toBoolean()) { + from refMap + } - // copy everything else, thats not the mcmod.info - from(sourceSets.main.resources.srcDirs) { - exclude 'mcmod.info' - } -} + // copy everything else, thats not the mcmod.info + from(sourceSets.main.resources.srcDirs) { + exclude 'mcmod.info' + } + } def getManifestAttributes() { def manifestAttributes = [:] - if(containsMixinsAndOrCoreModOnly.toBoolean() == false && (usesMixins.toBoolean() || coreModClass)) { + if (!containsMixinsAndOrCoreModOnly.toBoolean() && (usesMixins.toBoolean() || coreModClass)) { manifestAttributes += ["FMLCorePluginContainsFMLMod": true] } - if(accessTransformersFile) { - manifestAttributes += ["FMLAT" : accessTransformersFile.toString()] + if (accessTransformersFile) { + manifestAttributes += ["FMLAT": accessTransformersFile.toString()] } - if(coreModClass) { + if (coreModClass) { manifestAttributes += ["FMLCorePlugin": modGroup + "." + coreModClass] } - if(usesMixins.toBoolean()) { + if (usesMixins.toBoolean()) { manifestAttributes += [ - "TweakClass" : "org.spongepowered.asm.launch.MixinTweaker", - "MixinConfigs" : "mixins." + modId + ".json", - "ForceLoadAsMod" : containsMixinsAndOrCoreModOnly.toBoolean() == false + "TweakClass" : "org.spongepowered.asm.launch.MixinTweaker", + "MixinConfigs" : "mixins." + modId + ".json", + "ForceLoadAsMod": !containsMixinsAndOrCoreModOnly.toBoolean() ] } return manifestAttributes } task sourcesJar(type: Jar) { - from (sourceSets.main.allJava) - from (file("$projectDir/LICENSE")) + from(sourceSets.main.allJava) + from(file("$projectDir/LICENSE")) getArchiveClassifier().set('sources') } @@ -462,22 +449,22 @@ task devJar(type: Jar) { attributes(getManifestAttributes()) } - if(usesShadowedDependencies.toBoolean()) { + if (usesShadowedDependencies.toBoolean()) { dependsOn(circularResolverJar) enabled = false } } task apiJar(type: Jar) { - from (sourceSets.main.allJava) { + from(sourceSets.main.allJava) { include modGroup.toString().replaceAll("\\.", "/") + "/" + apiPackage.toString().replaceAll("\\.", "/") + '/**' } - from (sourceSets.main.output) { + from(sourceSets.main.output) { include modGroup.toString().replaceAll("\\.", "/") + "/" + apiPackage.toString().replaceAll("\\.", "/") + '/**' } - from (sourceSets.main.resources.srcDirs) { + from(sourceSets.main.resources.srcDirs) { include("LICENSE") } @@ -485,16 +472,17 @@ task apiJar(type: Jar) { } artifacts { - if(!noPublishedSources) { + if (!noPublishedSources) { archives sourcesJar } archives devJar - if(apiPackage) { + if (apiPackage) { archives apiJar } } // publishing +/* publishing { publications { maven(MavenPublication) { @@ -525,7 +513,10 @@ publishing { } } + */ + // Updating +/* task updateBuildScript { doLast { if (performBuildScriptUpdate(projectDir.toString())) return @@ -581,10 +572,12 @@ configure(updateBuildScript) { description = 'Updates the build script to the latest version' } + */ + // Helper methods def checkPropertyExists(String propertyName) { - if (project.hasProperty(propertyName) == false) { + if (!project.hasProperty(propertyName)) { throw new GradleException("This project requires a property \"" + propertyName + "\"! Please add it your \"gradle.properties\". You can find all properties and their description here: https://github.com/GTNewHorizons/ExampleMod1.7.10/blob/main/gradle.properties") } } diff --git a/dependencies.gradle b/dependencies.gradle index 94477e0..bf4a753 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -1,8 +1,12 @@ dependencies { compile("com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-70-GTNH:dev") compile("com.github.GTNewHorizons:CodeChickenLib:1.1.5.1:dev") + compile("com.github.GTNewHorizons:CodeChickenCore:1.1.3:dev") compile("com.github.GTNewHorizons:NotEnoughItems:2.1.22-GTNH:dev") + runtime(files("libs/BetterCrashes-1.0.0-dev.jar")) + runtime(files("libs/Grimoire-mc1.7.10-dev-3.2.7.jar")) + compileOnly("com.github.GTNewHorizons:Avaritiaddons:1.5.2-GTNH:dev") {transitive = false} compileOnly("com.github.GTNewHorizons:BuildCraftCompat:7.1.9:dev") {transitive = false} compileOnly("com.github.GTNewHorizons:EnderIO:2.3.1.27:dev") {transitive = false} diff --git a/gradle.properties b/gradle.properties index e8a1aa7..70f72c0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,6 +3,8 @@ modName = NotEnoughEnergistics # This is a case-sensitive string to identify your mod. Convention is to use lower case. modId = neenergistics +modVersion=1.3.8 + modGroup = com.github.vfyjxf.nee # WHY is there no version field? diff --git a/jitpack.yml b/jitpack.yml deleted file mode 100644 index 09bbb51..0000000 --- a/jitpack.yml +++ /dev/null @@ -1,2 +0,0 @@ -before_install: - - ./gradlew setupCIWorkspace \ No newline at end of file diff --git a/libs/BetterCrashes-1.0.0-dev.jar b/libs/BetterCrashes-1.0.0-dev.jar new file mode 100644 index 0000000..e575138 Binary files /dev/null and b/libs/BetterCrashes-1.0.0-dev.jar differ diff --git a/libs/Grimoire-mc1.7.10-dev-3.2.7.jar b/libs/Grimoire-mc1.7.10-dev-3.2.7.jar new file mode 100644 index 0000000..943ab93 Binary files /dev/null and b/libs/Grimoire-mc1.7.10-dev-3.2.7.jar differ diff --git a/src/main/java/com/github/vfyjxf/nee/NEECommands.java b/src/main/java/com/github/vfyjxf/nee/NEECommands.java index fd5e4a3..5539583 100644 --- a/src/main/java/com/github/vfyjxf/nee/NEECommands.java +++ b/src/main/java/com/github/vfyjxf/nee/NEECommands.java @@ -28,13 +28,17 @@ public class NEECommands extends CommandBase { @Override public String getCommandUsage(ICommandSender sender) { - return ""; + return "See /nee help"; } @Override public void processCommand(ICommandSender sender, String[] args) { if (args.length != 0) { - if ("processor".equalsIgnoreCase(args[0])) { + if ("help".equalsIgnoreCase(args[0])) { + sender.addChatMessage(new ChatComponentText("Usage:")); + sender.addChatMessage(new ChatComponentText("/nee add blacklist/priorityItem processor_id identifier")); + sender.addChatMessage(new ChatComponentText("/nee add blacklist/priorityItem/itemCombination identifier")); + } else if ("processor".equalsIgnoreCase(args[0])) { for (IRecipeProcessor processor : RecipeProcessor.recipeProcessors) { logger.info("RecipeProcessor:" + processor.getRecipeProcessorId() + " identifier:"); for (String ident : processor.getAllOverlayIdentifier()) { @@ -47,10 +51,14 @@ public class NEECommands extends CommandBase { if (currentStack != null) { String currentItemJsonString = ItemUtils.toItemJsonString(currentStack); JsonObject itemJsonObject = new JsonParser().parse(currentItemJsonString).getAsJsonObject(); - if (args.length == 3) { + if (args.length >= 3) { boolean hasRecipeProcessor = ItemUtils.hasRecipeProcessor(args[2]); boolean hasOverlayIdentifier = ItemUtils.hasOverlayIdentifier(args[2]); + if (args.length == 4) { + hasOverlayIdentifier = ItemUtils.hasOverlayIdentifier(args[3]); + } + if (hasRecipeProcessor) { itemJsonObject.addProperty("recipeProcessor", args[2]); } else if (!hasOverlayIdentifier) { @@ -58,7 +66,7 @@ public class NEECommands extends CommandBase { } if (hasOverlayIdentifier) { - itemJsonObject.addProperty("identifier", args[2]); + itemJsonObject.addProperty("identifier", args.length == 4 ? args[3] : args[2]); } else if (!hasRecipeProcessor) { sender.addChatMessage(new ChatComponentText("Can't find identifier: " + args[2])); } @@ -66,7 +74,6 @@ public class NEECommands extends CommandBase { } String newJsonString = new Gson().toJson(itemJsonObject); String[] oldList = "blacklist".equalsIgnoreCase(args[1]) ? NEEConfig.transformBlacklist : NEEConfig.transformPriorityList; - String key = "blacklist".equalsIgnoreCase(args[1]) ? "transformItemBlacklist" : "transformItemPriorityList"; List newList = new ArrayList<>(Arrays.asList(oldList)); for (String currentJsonString : oldList) { if (currentJsonString.equals(newJsonString)) { @@ -74,18 +81,29 @@ public class NEECommands extends CommandBase { } } newList.add(newJsonString); - NEEConfig.config.getCategory("client").get(key).set(newList.toArray(new String[0])); - NEEConfig.config.save(); - NEEConfig.reload(); + if ("blacklist".equalsIgnoreCase(args[1])) { + NEEConfig.setTransformBlacklist(newList.toArray(new String[0])); + } else { + NEEConfig.setTransformPriorityList(newList.toArray(new String[0])); + } } } else if ("priorityMod".equalsIgnoreCase(args[1]) && args.length == 3) { String modid = args[2]; if (!ItemUtils.hasModId(modid)) { List newList = new ArrayList<>(Arrays.asList(NEEConfig.transformPriorityModList)); newList.add(modid); - NEEConfig.config.getCategory("client").get("transformPriorityModList").set(newList.toArray(new String[0])); - NEEConfig.config.save(); - NEEConfig.reload(); + NEEConfig.setTransformPriorityModList(newList.toArray(new String[0])); + } + } else if ("itemCombination".equalsIgnoreCase(args[1]) && args.length == 3) { + String identifier = args[2]; + if (!Arrays.asList(NEEConfig.itemCombinationWhitelist).contains(identifier)) { + if (ItemUtils.hasOverlayIdentifier(args[2])) { + List newLists = new ArrayList<>(Arrays.asList(NEEConfig.itemCombinationWhitelist)); + newLists.add(identifier); + NEEConfig.setItemCombinationWhitelist(newLists.toArray(new String[0])); + } else { + sender.addChatMessage(new ChatComponentText("Can't find identifier: " + args[2])); + } } } } else if ("reload".equalsIgnoreCase(args[0])) { @@ -98,8 +116,8 @@ public class NEECommands extends CommandBase { @Override public List addTabCompletionOptions(ICommandSender sender, String[] args) { - return args.length <= 1 ? CommandBase.getListOfStringsMatchingLastWord(args, "reload", "add", "processor") : - args.length == 2 ? CommandBase.getListOfStringsMatchingLastWord(args, "blacklist", "priorityItem", "priorityMod") : null; + return args.length <= 1 ? CommandBase.getListOfStringsMatchingLastWord(args, "help", "reload", "add", "processor") : + args.length == 2 ? CommandBase.getListOfStringsMatchingLastWord(args, "blacklist", "priorityItem", "priorityMod", "itemCombination") : null; } @Override diff --git a/src/main/java/com/github/vfyjxf/nee/NEINeeConfig.java b/src/main/java/com/github/vfyjxf/nee/NEINeeConfig.java index edc40fe..4006d4c 100644 --- a/src/main/java/com/github/vfyjxf/nee/NEINeeConfig.java +++ b/src/main/java/com/github/vfyjxf/nee/NEINeeConfig.java @@ -9,7 +9,7 @@ import codechicken.nei.api.API; import codechicken.nei.api.IConfigureNEI; import codechicken.nei.guihook.GuiContainerManager; import codechicken.nei.guihook.IContainerInputHandler; -import com.github.vfyjxf.nee.client.GuiHandler; +import com.github.vfyjxf.nee.client.GuiEventHandler; import com.github.vfyjxf.nee.client.NEEContainerDrawHandler; import com.github.vfyjxf.nee.config.NEEConfig; import com.github.vfyjxf.nee.nei.NEECraftingHandler; @@ -89,7 +89,7 @@ public class NEINeeConfig implements IConfigureNEI { } private void registerGuiHandler() { - API.registerNEIGuiHandler(GuiHandler.instance); + API.registerNEIGuiHandler(GuiEventHandler.instance); //disable MouseScrollTransfer in some gui replaceNEIController(); } diff --git a/src/main/java/com/github/vfyjxf/nee/asm/AppengHelper.java b/src/main/java/com/github/vfyjxf/nee/asm/AppengHelper.java new file mode 100644 index 0000000..3ccb0c7 --- /dev/null +++ b/src/main/java/com/github/vfyjxf/nee/asm/AppengHelper.java @@ -0,0 +1,114 @@ +package com.github.vfyjxf.nee.asm; + +import appeng.client.gui.implementations.GuiInterface; +import appeng.client.gui.implementations.GuiPatternTerm; +import appeng.container.slot.SlotFake; +import codechicken.nei.NEIClientConfig; +import codechicken.nei.PositionedStack; +import com.github.vfyjxf.nee.config.NEEConfig; +import com.github.vfyjxf.nee.nei.NEECraftingHandler; +import com.github.vfyjxf.nee.network.NEENetworkHandler; +import com.github.vfyjxf.nee.network.packet.PacketSlotStackChange; +import com.github.vfyjxf.nee.network.packet.PacketStackCountChange; +import com.github.vfyjxf.nee.utils.GuiUtils; +import com.github.vfyjxf.nee.utils.ItemUtils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; +import org.lwjgl.input.Keyboard; +import org.lwjgl.input.Mouse; + +import java.util.ArrayList; +import java.util.List; + +public class AppengHelper { + + /** + * 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. + */ + public static boolean handleMouseWheelInput(int dWheel) { + Minecraft mc = Minecraft.getMinecraft(); + boolean isPatternTerm = mc.currentScreen instanceof GuiPatternTerm || GuiUtils.isPatternTermExGui(mc.currentScreen); + boolean isInterface = mc.currentScreen instanceof GuiInterface; + if (isPatternTerm || isInterface) { + if (dWheel != 0) { + int x = Mouse.getEventX() * mc.currentScreen.width / mc.displayWidth; + int y = mc.currentScreen.height - Mouse.getEventY() * mc.currentScreen.height / mc.displayHeight - 1; + Slot currentSlot = ((GuiContainer) mc.currentScreen).getSlotAtPosition(x, y); + 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((GuiContainer) mc.currentScreen, currentSlot, dWheel); + return true; + } else if (Keyboard.isKeyDown(NEIClientConfig.getKeyBinding("nee.count"))) { + int changeCount = dWheel / 120; + NEENetworkHandler.getInstance().sendToServer(new PacketStackCountChange(currentSlot.slotNumber, changeCount)); + return true; + } + } + } + } + return false; + } + + private static void handleRecipeIngredientChange(GuiContainer gui, Slot currentSlot, int dWheel) { + List craftingSlots = new ArrayList<>(); + int currentSlotIndex = currentSlot.getSlotIndex(); + PositionedStack currentIngredients = NEECraftingHandler.ingredients.get("input" + currentSlotIndex); + if (currentIngredients != null && currentIngredients.items.length > 1) { + int currentStackIndex = ItemUtils.getIngredientIndex(currentSlot.getStack(), currentIngredients); + if (currentStackIndex >= 0) { + int nextStackIndex = dWheel / 120; + for (int j = 0; j < Math.abs(nextStackIndex); j++) { + 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; + + if (NEEConfig.allowSynchronousSwitchIngredient) { + for (Slot slot : getCraftingSlots(gui)) { + + PositionedStack slotIngredients = NEECraftingHandler.ingredients.get("input" + 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)); + } + } + } + + } + + @SuppressWarnings("unchecked") + private static List getCraftingSlots(GuiContainer gui) { + List craftingSlots = new ArrayList<>(); + for (Slot slot : (List) gui.inventorySlots.inventorySlots) { + if (GuiUtils.isCraftingSlot(slot)) { + craftingSlots.add(slot); + } + } + return craftingSlots; + } + +} diff --git a/src/main/java/com/github/vfyjxf/nee/asm/NEEClassTransformer.java b/src/main/java/com/github/vfyjxf/nee/asm/NEEClassTransformer.java index 3ad8a72..27dcc5e 100644 --- a/src/main/java/com/github/vfyjxf/nee/asm/NEEClassTransformer.java +++ b/src/main/java/com/github/vfyjxf/nee/asm/NEEClassTransformer.java @@ -1,5 +1,7 @@ package com.github.vfyjxf.nee.asm; +import codechicken.lib.asm.ASMInit; +import codechicken.lib.asm.ObfMapping; import com.github.vfyjxf.nee.NotEnoughEnergistics; import net.minecraft.launchwrapper.IClassTransformer; import org.objectweb.asm.ClassReader; @@ -13,11 +15,19 @@ import static org.objectweb.asm.Opcodes.*; public class NEEClassTransformer implements IClassTransformer { + static { + ASMInit.init(); + } + private static final List transformedClassNames = Arrays.asList( "appeng/integration/modules/NEIHelpers/NEIInscriberRecipeHandler", "appeng/integration/modules/NEIHelpers/NEIGrinderRecipeHandler" ); + private static final String TARGET_CLASS_NAME = "appeng/client/gui/AEBaseGui"; + + private static final ObfMapping TARGET_METHOD_MAPPING = new ObfMapping(TARGET_CLASS_NAME, "func_146274_d", "()V").toClassloading(); + private static final String METHOD_OWNER = "codechicken/nei/recipe/TemplateRecipeHandler"; private static final String METHOD_NAME_1 = "getOverlayHandler"; @@ -34,9 +44,7 @@ public class NEEClassTransformer implements IClassTransformer { //rewrite ae2's methods to support recipe transfer. if (transformedClassNames.contains(internalName)) { - ClassNode classNode = new ClassNode(); - ClassReader classReader = new ClassReader(basicClass); - classReader.accept(classNode, 0); + ClassNode classNode = createClassNode(basicClass); for (MethodNode methodNode : classNode.methods) { if (METHOD_NAME_1.equals(methodNode.name) && METHOD_TARGET_1.equals(methodNode.desc)) { NotEnoughEnergistics.logger.info("Transforming : " + internalName + methodNode.name + methodNode.desc); @@ -81,9 +89,45 @@ public class NEEClassTransformer implements IClassTransformer { classNode.accept(classWriter); return classWriter.toByteArray(); } + + + if (TARGET_CLASS_NAME.equals(internalName)) { + ClassNode classNode = createClassNode(basicClass); + for (MethodNode methodNode : classNode.methods) { + if (TARGET_METHOD_MAPPING.matches(methodNode)) { + NotEnoughEnergistics.logger.info("Transforming : " + internalName + methodNode.name + methodNode.desc); + AbstractInsnNode aLoad = methodNode.instructions.getLast().getPrevious(); + while (aLoad.getOpcode() != ALOAD) { + aLoad = aLoad.getPrevious(); + } + InsnList insnList = new InsnList(); + insnList.add(new VarInsnNode(ILOAD, 1)); + insnList.add(new MethodInsnNode(INVOKESTATIC, + "com/github/vfyjxf/nee/asm/AppengHelper", + "handleMouseWheelInput", + "(I)Z", false)); + LabelNode label = new LabelNode(); + insnList.add(new JumpInsnNode(IFEQ, label)); + insnList.add(new InsnNode(RETURN)); + insnList.add(label); + methodNode.instructions.insertBefore(aLoad, insnList); + } + } + ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES); + classNode.accept(classWriter); + return classWriter.toByteArray(); + } + return basicClass; } + private ClassNode createClassNode(byte[] basicClass) { + ClassNode classNode = new ClassNode(); + ClassReader classReader = new ClassReader(basicClass); + classReader.accept(classNode, 0); + return classNode; + } + } diff --git a/src/main/java/com/github/vfyjxf/nee/client/GuiHandler.java b/src/main/java/com/github/vfyjxf/nee/client/GuiEventHandler.java similarity index 62% rename from src/main/java/com/github/vfyjxf/nee/client/GuiHandler.java rename to src/main/java/com/github/vfyjxf/nee/client/GuiEventHandler.java index 93e1975..1ad9e5c 100644 --- a/src/main/java/com/github/vfyjxf/nee/client/GuiHandler.java +++ b/src/main/java/com/github/vfyjxf/nee/client/GuiEventHandler.java @@ -1,35 +1,26 @@ package com.github.vfyjxf.nee.client; -import appeng.api.storage.data.IAEItemStack; import appeng.client.gui.AEBaseGui; -import appeng.client.gui.implementations.GuiCraftConfirm; -import appeng.client.gui.implementations.GuiCraftingTerm; -import appeng.client.gui.implementations.GuiInterface; import appeng.client.gui.implementations.GuiPatternTerm; +import appeng.container.implementations.ContainerPatternTerm; import appeng.container.slot.SlotFake; -import appeng.util.item.AEItemStack; -import codechicken.nei.NEIClientConfig; import codechicken.nei.PositionedStack; import codechicken.nei.VisiblityData; import codechicken.nei.api.INEIGuiHandler; import codechicken.nei.api.TaggedInventoryArea; +import com.github.vfyjxf.nee.config.ItemCombination; import com.github.vfyjxf.nee.config.NEEConfig; +import com.github.vfyjxf.nee.gui.widgets.GuiImgButtonEnableCombination; import com.github.vfyjxf.nee.nei.NEECraftingHandler; import com.github.vfyjxf.nee.network.NEENetworkHandler; -import com.github.vfyjxf.nee.network.packet.PacketCraftingRequest; import com.github.vfyjxf.nee.network.packet.PacketSlotStackChange; -import com.github.vfyjxf.nee.network.packet.PacketStackCountChange; import com.github.vfyjxf.nee.utils.GuiUtils; import com.github.vfyjxf.nee.utils.ItemUtils; import cpw.mods.fml.common.eventhandler.SubscribeEvent; -import cpw.mods.fml.common.gameevent.TickEvent; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; -import net.minecraftforge.client.event.GuiOpenEvent; -import org.lwjgl.input.Keyboard; +import net.minecraftforge.client.event.GuiScreenEvent; import org.lwjgl.input.Mouse; import java.util.ArrayList; @@ -37,52 +28,62 @@ import java.util.List; import static com.github.vfyjxf.nee.config.NEEConfig.draggedStackDefaultSize; import static com.github.vfyjxf.nee.config.NEEConfig.useStackSizeFromNEI; -import static com.github.vfyjxf.nee.nei.NEECraftingHelper.*; -public class GuiHandler implements INEIGuiHandler { +public class GuiEventHandler implements INEIGuiHandler { - public static GuiHandler instance = new GuiHandler(); + public static GuiEventHandler instance = new GuiEventHandler(); + private GuiImgButtonEnableCombination buttonCombination; + private boolean hasDoubleBtn = true; + + @SuppressWarnings("unchecked") @SubscribeEvent - public void onRenderTick(TickEvent.RenderTickEvent event) { - if (event.phase == TickEvent.Phase.START) { - Minecraft mc = Minecraft.getMinecraft(); - boolean isPatternTerm = mc.currentScreen instanceof GuiPatternTerm || GuiUtils.isPatternTermExGui(mc.currentScreen); - boolean isInterface = mc.currentScreen instanceof GuiInterface; - if (isPatternTerm || isInterface) { - int dWheel = Mouse.getDWheel(); - if (dWheel != 0) { - int x = Mouse.getEventX() * mc.currentScreen.width / mc.displayWidth; - int y = mc.currentScreen.height - Mouse.getEventY() * mc.currentScreen.height / mc.displayHeight - 1; - Slot currentSlot = ((GuiContainer) mc.currentScreen).getSlotAtPosition(x, y); - 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((GuiContainer) mc.currentScreen, currentSlot, dWheel); - } else if (Keyboard.isKeyDown(NEIClientConfig.getKeyBinding("nee.count"))) { - int changeCount = dWheel / 120; - NEENetworkHandler.getInstance().sendToServer(new PacketStackCountChange(currentSlot.slotNumber, changeCount)); - } - } - } + public void onInitGui(GuiScreenEvent.InitGuiEvent.Post event) { + if (event.gui instanceof GuiPatternTerm) { + GuiPatternTerm gui = (GuiPatternTerm) event.gui; + try { + GuiPatternTerm.class.getDeclaredField("doubleBtn"); + } catch (NoSuchFieldException e) { + hasDoubleBtn = false; } + if (hasDoubleBtn) { + buttonCombination = new GuiImgButtonEnableCombination(gui.guiLeft + 84, gui.guiTop + gui.ySize - 153, ItemCombination.valueOf(NEEConfig.itemCombinationMode)); + } else { + buttonCombination = new GuiImgButtonEnableCombination(gui.guiLeft + 74, gui.guiTop + gui.ySize - 153, ItemCombination.valueOf(NEEConfig.itemCombinationMode)); + + } + event.buttonList.add(buttonCombination); } } @SubscribeEvent - public void onGuiOpen(GuiOpenEvent event) { - GuiScreen currentScreen = Minecraft.getMinecraft().currentScreen; - boolean isGuiCraftingTerm = event.gui instanceof GuiCraftingTerm || GuiUtils.isGuiWirelessCrafting(event.gui); - boolean isGuiCraftConfirm = currentScreen instanceof GuiCraftConfirm || GuiUtils.isWirelessGuiCraftConfirm(currentScreen); - if (isGuiCraftingTerm && isGuiCraftConfirm && tracker != null) { - if (!tracker.getRequireStacks().isEmpty() && stackIndex < tracker.getRequireStacks().size()) { - IAEItemStack stack = AEItemStack.create(tracker.getRequireStacks().get(stackIndex)); - NEENetworkHandler.getInstance().sendToServer(new PacketCraftingRequest(stack, noPreview)); - stackIndex++; + public void onActionPerformed(GuiScreenEvent.ActionPerformedEvent.Pre event) { + if (event.button == this.buttonCombination) { + GuiImgButtonEnableCombination button = (GuiImgButtonEnableCombination) event.button; + int ordinal = Mouse.getEventButton() != 2 ? button.getCurrentValue().ordinal() + 1 : button.getCurrentValue().ordinal() - 1; + + if (ordinal >= ItemCombination.values().length) { + ordinal = 0; + } + if (ordinal < 0) { + ordinal = ItemCombination.values().length - 1; + } + button.setValue(ItemCombination.values()[ordinal]); + NEEConfig.setItemCombinationMode(ItemCombination.values()[ordinal].name()); + } + } + + @SubscribeEvent + public void onDrawScreen(GuiScreenEvent.DrawScreenEvent.Post event) { + if (event.gui instanceof GuiPatternTerm) { + ContainerPatternTerm container = (ContainerPatternTerm) ((GuiPatternTerm) event.gui).inventorySlots; + if (container.isCraftingMode()) { + buttonCombination.enabled = false; + buttonCombination.visible = false; + } else { + buttonCombination.enabled = true; + buttonCombination.visible = true; } - } else if (!isGuiCraftingTerm && isGuiCraftConfirm && tracker != null) { - //Prevent opening the gui during normal use - tracker = null; } } @@ -182,3 +183,4 @@ public class GuiHandler implements INEIGuiHandler { return false; } } + diff --git a/src/main/java/com/github/vfyjxf/nee/client/NEEContainerDrawHandler.java b/src/main/java/com/github/vfyjxf/nee/client/NEEContainerDrawHandler.java index 0f714e8..60155c8 100644 --- a/src/main/java/com/github/vfyjxf/nee/client/NEEContainerDrawHandler.java +++ b/src/main/java/com/github/vfyjxf/nee/client/NEEContainerDrawHandler.java @@ -3,7 +3,6 @@ package com.github.vfyjxf.nee.client; import appeng.client.gui.implementations.GuiCraftingTerm; import appeng.client.gui.implementations.GuiPatternTerm; import codechicken.nei.NEIClientConfig; -import codechicken.nei.PositionedStack; import codechicken.nei.guihook.IContainerDrawHandler; import codechicken.nei.recipe.GuiRecipe; import codechicken.nei.recipe.IRecipeHandler; @@ -13,25 +12,21 @@ import com.github.vfyjxf.nee.utils.Ingredient; import com.github.vfyjxf.nee.utils.IngredientTracker; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.relauncher.ReflectionHelper; -import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.GuiButton; -import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.resources.I18n; import net.minecraft.inventory.Slot; import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.client.event.GuiScreenEvent; import org.lwjgl.input.Keyboard; -import org.lwjgl.input.Mouse; import java.awt.*; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Arrays; import java.util.List; +import java.util.*; /** * Please note the difference between the GTNH NEI and the official NEI @@ -40,15 +35,29 @@ public class NEEContainerDrawHandler implements IContainerDrawHandler { public static NEEContainerDrawHandler instance = new NEEContainerDrawHandler(); - private Field overlayButtonsField; - private Method recipesPerPageMethod; + public static final Map trackerMap = new HashMap<>(); + + public static boolean isGtnhNei; + + private final List overlayButtons = new ArrayList<>(); + + public Field overlayButtonsField; + public Method recipesPerPageMethod; private boolean drawRequestTooltip; private boolean drawMissingTooltip; private boolean drawCraftableTooltip; - private boolean isGtnhNei; public NEEContainerDrawHandler() { - + //gtnh nei support + isGtnhNei = true; + try { + this.overlayButtonsField = GuiRecipe.class.getDeclaredField("overlayButtons"); + this.recipesPerPageMethod = GuiRecipe.class.getDeclaredMethod("getRecipesPerPage"); + this.overlayButtonsField.setAccessible(true); + this.recipesPerPageMethod.setAccessible(true); + } catch (NoSuchMethodException | NoSuchFieldException e) { + isGtnhNei = false; + } } @Override @@ -74,103 +83,46 @@ public class NEEContainerDrawHandler implements IContainerDrawHandler { @SuppressWarnings("ALL") @Override public void renderSlotOverlay(GuiContainer gui, Slot slot) { - - if (NEEConfig.drawHighlight && gui instanceof GuiRecipe) { - //gtnh nei support - this.isGtnhNei = true; - if (this.overlayButtonsField == null || this.recipesPerPageMethod == null) { - try { - this.overlayButtonsField = GuiRecipe.class.getDeclaredField("overlayButtons"); - this.recipesPerPageMethod = GuiRecipe.class.getDeclaredMethod("getRecipesPerPage"); - this.overlayButtonsField.setAccessible(true); - this.recipesPerPageMethod.setAccessible(true); - } catch (NoSuchMethodException | NoSuchFieldException e) { - this.isGtnhNei = false; - } - } - - Minecraft mc = Minecraft.getMinecraft(); + if (NEEConfig.drawHighlight && gui instanceof GuiRecipe && !overlayButtons.isEmpty()) { GuiRecipe guiRecipe = (GuiRecipe) gui; - GuiContainer firstGui = guiRecipe.firstGui; - boolean isGuiPatternTerm = firstGui instanceof GuiPatternTerm || GuiUtils.isPatternTermExGui(firstGui); - boolean isCraftingTerm = firstGui instanceof GuiCraftingTerm || GuiUtils.isGuiWirelessCrafting(firstGui); - if (isGuiPatternTerm || isCraftingTerm) { - final ScaledResolution scaledresolution = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); - int i = scaledresolution.getScaledWidth(); - int j = scaledresolution.getScaledHeight(); - final int mouseX = Mouse.getX() * i / mc.displayWidth; - final int mouseY = j - Mouse.getY() * j / mc.displayHeight - 1; + for (GuiButton overlayButton : overlayButtons) { + if (GuiUtils.isMouseOverButton(overlayButton)) { + IngredientTracker tracker = trackerMap.get("button" + overlayButton.id); + if (tracker != null) { + for (Ingredient ingredient : tracker.getIngredients()) { + Point point = guiRecipe.getRecipePosition(tracker.getRecipeIndex()); + Slot currentSlot = guiRecipe.slotcontainer.getSlotWithStack(ingredient.getIngredient(), point.x, point.y); + if (slot.equals(currentSlot)) { + if (!NEEConfig.enableCraftAmountSettingGui) { + GuiContainer firstGui = guiRecipe.firstGui; + boolean renderAutoAbleItems = (firstGui instanceof GuiCraftingTerm || GuiUtils.isGuiWirelessCrafting(firstGui)) && ingredient.isCraftable() && ingredient.requiresToCraft(); + boolean renderCraftableItems = (firstGui instanceof GuiPatternTerm || GuiUtils.isPatternTermExGui(firstGui)) && ingredient.isCraftable(); + boolean renderMissingItems = (firstGui instanceof GuiCraftingTerm || GuiUtils.isGuiWirelessCrafting(firstGui)) && !ingredient.isCraftable() && ingredient.requiresToCraft(); + if (renderAutoAbleItems || renderCraftableItems) { + Gui.drawRect(slot.xDisplayPosition, slot.yDisplayPosition, + slot.xDisplayPosition + 16, slot.yDisplayPosition + 16, + new Color(0.0f, 0.0f, 1.0f, 0.4f).getRGB()); + this.drawCraftableTooltip = renderCraftableItems; + this.drawRequestTooltip = renderAutoAbleItems; + } + if (renderMissingItems) { + Gui.drawRect(slot.xDisplayPosition, slot.yDisplayPosition, + slot.xDisplayPosition + 16, slot.yDisplayPosition + 16, + new Color(1.0f, 0.0f, 0.0f, 0.4f).getRGB()); + this.drawMissingTooltip = true; + } + } else { - - List overlayButtons = null; - if (isGtnhNei) { - try { - overlayButtons = new ArrayList<>(Arrays.asList((GuiButton[]) this.overlayButtonsField.get(guiRecipe))); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - } else { - overlayButtons = new ArrayList<>(); - GuiButton overlay1 = ReflectionHelper.getPrivateValue(GuiRecipe.class, guiRecipe, "overlay1"); - GuiButton overlay2 = ReflectionHelper.getPrivateValue(GuiRecipe.class, guiRecipe, "overlay2"); - overlayButtons.add(overlay1); - overlayButtons.add(overlay2); - } - - if (overlayButtons != null) { - for (GuiButton button : overlayButtons) { - if (button.visible && button.enabled && GuiUtils.isMouseOverButton(button, mouseX, mouseY)) { - final int OVERLAY_BUTTON_ID_START = 4; - IRecipeHandler handler = guiRecipe.currenthandlers.get(guiRecipe.recipetype); - int recipesPerPage = 2; - if (isGtnhNei) { - try { - recipesPerPage = (int) this.recipesPerPageMethod.invoke(guiRecipe); - } catch (IllegalAccessException | InvocationTargetException e) { - e.printStackTrace(); - } - } - if (recipesPerPage >= 0 && handler != null) { - int recipeIndex = guiRecipe.page * recipesPerPage + button.id - OVERLAY_BUTTON_ID_START; - List ingredients = handler.getIngredientStacks(recipeIndex); - IngredientTracker tracker = new IngredientTracker(guiRecipe.firstGui, handler, recipeIndex); - - for (int var1 = 0; var1 < ingredients.size(); var1++) { - PositionedStack stack = ingredients.get(var1); - Ingredient ingredient = tracker.getIngredients().get(var1); - Slot stackSlot = guiRecipe.slotcontainer.getSlotWithStack(stack, guiRecipe.getRecipePosition(recipeIndex).x, guiRecipe.getRecipePosition(recipeIndex).y); - if (stackSlot.equals(slot)) { - if (!NEEConfig.enableCraftAmountSettingGui) { - boolean renderAutoAbleItems = (firstGui instanceof GuiCraftingTerm || GuiUtils.isGuiWirelessCrafting(firstGui)) && ingredient.isCraftable() && ingredient.requiresToCraft(); - boolean renderCraftableItems = (firstGui instanceof GuiPatternTerm || GuiUtils.isPatternTermExGui(firstGui)) && ingredient.isCraftable(); - boolean renderMissingItems = (firstGui instanceof GuiCraftingTerm || GuiUtils.isGuiWirelessCrafting(firstGui)) && !ingredient.isCraftable() && ingredient.requiresToCraft(); - if (renderAutoAbleItems || renderCraftableItems) { - Gui.drawRect(slot.xDisplayPosition, slot.yDisplayPosition, - slot.xDisplayPosition + 16, slot.yDisplayPosition + 16, - new Color(0.0f, 0.0f, 1.0f, 0.4f).getRGB()); - this.drawCraftableTooltip = renderCraftableItems; - this.drawRequestTooltip = renderAutoAbleItems; - } - if (renderMissingItems) { - Gui.drawRect(slot.xDisplayPosition, slot.yDisplayPosition, - slot.xDisplayPosition + 16, slot.yDisplayPosition + 16, - new Color(1.0f, 0.0f, 0.0f, 0.4f).getRGB()); - this.drawMissingTooltip = true; - } - } else { - - if (ingredient.isCraftable()) { - Gui.drawRect(slot.xDisplayPosition, slot.yDisplayPosition, - slot.xDisplayPosition + 16, slot.yDisplayPosition + 16, - new Color(0.0f, 0.0f, 1.0f, 0.4f).getRGB()); - this.drawRequestTooltip = true; - } else { - Gui.drawRect(slot.xDisplayPosition, slot.yDisplayPosition, - slot.xDisplayPosition + 16, slot.yDisplayPosition + 16, - new Color(1.0f, 0.0f, 0.0f, 0.4f).getRGB()); - this.drawMissingTooltip = true; - } - } + if (ingredient.isCraftable()) { + Gui.drawRect(slot.xDisplayPosition, slot.yDisplayPosition, + slot.xDisplayPosition + 16, slot.yDisplayPosition + 16, + new Color(0.0f, 0.0f, 1.0f, 0.4f).getRGB()); + this.drawRequestTooltip = true; + } else { + Gui.drawRect(slot.xDisplayPosition, slot.yDisplayPosition, + slot.xDisplayPosition + 16, slot.yDisplayPosition + 16, + new Color(1.0f, 0.0f, 0.0f, 0.4f).getRGB()); + this.drawMissingTooltip = true; } } } @@ -183,37 +135,41 @@ public class NEEContainerDrawHandler implements IContainerDrawHandler { @SubscribeEvent public void onDrawScreen(GuiScreenEvent.DrawScreenEvent.Post event) { - if (this.drawCraftableTooltip || this.drawRequestTooltip || this.drawMissingTooltip) { - if (event.gui instanceof GuiRecipe) { - GuiRecipe guiRecipe = (GuiRecipe) event.gui; - List overlayButtons = null; - if (this.isGtnhNei) { - try { - overlayButtons = new ArrayList<>(Arrays.asList((GuiButton[]) this.overlayButtonsField.get(guiRecipe))); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - } else { - overlayButtons = new ArrayList<>(); - GuiButton overlay1 = ReflectionHelper.getPrivateValue(GuiRecipe.class, guiRecipe, "overlay1"); - GuiButton overlay2 = ReflectionHelper.getPrivateValue(GuiRecipe.class, guiRecipe, "overlay2"); - overlayButtons.add(overlay1); - overlayButtons.add(overlay2); + if (event.gui instanceof GuiRecipe) { + GuiRecipe guiRecipe = (GuiRecipe) event.gui; + GuiContainer firstGui = guiRecipe.firstGui; + boolean isGuiPatternTerm = firstGui instanceof GuiPatternTerm || GuiUtils.isPatternTermExGui(firstGui); + boolean isCraftingTerm = firstGui instanceof GuiCraftingTerm || GuiUtils.isGuiWirelessCrafting(firstGui); + if (isCraftingTerm || isGuiPatternTerm) { + if (overlayButtons.isEmpty()) { + setOverlayButtons(guiRecipe); } - if (overlayButtons != null) { + + if (!checkTracker()) { + trackerMap.clear(); for (GuiButton button : overlayButtons) { - if (button.visible && button.enabled && GuiUtils.isMouseOverButton(button, event.mouseX, event.mouseY)) { + if (GuiUtils.isMouseOverButton(button)) { + trackerMap.put("button" + button.id, getTracker(guiRecipe, button, isCraftingTerm)); + } + } + } + + if (this.drawCraftableTooltip || this.drawRequestTooltip || this.drawMissingTooltip) { + for (GuiButton button : overlayButtons) { + if (button.visible && button.enabled && GuiUtils.isMouseOverButton(button)) { drawCraftingHelperTooltip(guiRecipe, event.mouseX, event.mouseY); this.drawCraftableTooltip = false; this.drawRequestTooltip = false; this.drawMissingTooltip = false; } } + } } } } + private void drawCraftingHelperTooltip(GuiRecipe guiRecipe, int mouseX, int mouseY) { List tooltips = new ArrayList<>(); boolean isCraftingTerm = guiRecipe.firstGui instanceof GuiCraftingTerm || GuiUtils.isGuiWirelessCrafting(guiRecipe.firstGui); @@ -234,4 +190,53 @@ public class NEEContainerDrawHandler implements IContainerDrawHandler { //drawHoveringText guiRecipe.func_146283_a(tooltips, mouseX, mouseY); } + + private void setOverlayButtons(GuiRecipe guiRecipe) { + List overlayButtons = null; + if (isGtnhNei) { + try { + overlayButtons = new ArrayList<>(Arrays.asList((GuiButton[]) NEEContainerDrawHandler.instance.overlayButtonsField.get(guiRecipe))); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } else { + overlayButtons = new ArrayList<>(); + GuiButton overlay1 = ReflectionHelper.getPrivateValue(GuiRecipe.class, guiRecipe, "overlay1"); + GuiButton overlay2 = ReflectionHelper.getPrivateValue(GuiRecipe.class, guiRecipe, "overlay2"); + overlayButtons.add(overlay1); + overlayButtons.add(overlay2); + } + if (overlayButtons != null) { + this.overlayButtons.addAll(overlayButtons); + } + } + + private boolean checkTracker() { + for (GuiButton overlayButton : overlayButtons) { + if (trackerMap.get("button" + overlayButton.id) != null) { + return true; + } + } + return false; + } + + private IngredientTracker getTracker(GuiRecipe guiRecipe, GuiButton overlayButton, boolean isCraftingTerm) { + if (overlayButton.enabled && overlayButton.visible) { + final int OVERLAY_BUTTON_ID_START = 4; + IRecipeHandler handler = guiRecipe.currenthandlers.get(guiRecipe.recipetype); + int recipesPerPage = 2; + if (isGtnhNei) { + try { + recipesPerPage = (int) NEEContainerDrawHandler.instance.recipesPerPageMethod.invoke(guiRecipe); + } catch (IllegalAccessException | InvocationTargetException e) { + e.printStackTrace(); + } + } + if (recipesPerPage >= 0 && handler != null) { + int recipeIndex = guiRecipe.page * recipesPerPage + overlayButton.id - OVERLAY_BUTTON_ID_START; + return isCraftingTerm ? new IngredientTracker(guiRecipe.firstGui, handler, recipeIndex) : new IngredientTracker(guiRecipe, handler, recipeIndex); + } + } + return null; + } } diff --git a/src/main/java/com/github/vfyjxf/nee/config/ItemCombination.java b/src/main/java/com/github/vfyjxf/nee/config/ItemCombination.java new file mode 100644 index 0000000..d37365c --- /dev/null +++ b/src/main/java/com/github/vfyjxf/nee/config/ItemCombination.java @@ -0,0 +1,13 @@ +package com.github.vfyjxf.nee.config; + +import net.minecraft.client.resources.I18n; + +import java.util.Locale; + +public enum ItemCombination { + DISABLED, ENABLED, WHITELIST; + + public String getLocalName() { + return I18n.format("gui.neenergistics.button.name" + "." + this.name().toLowerCase(Locale.ROOT)); + } +} diff --git a/src/main/java/com/github/vfyjxf/nee/config/NEEConfig.java b/src/main/java/com/github/vfyjxf/nee/config/NEEConfig.java index 721acd7..3b49986 100644 --- a/src/main/java/com/github/vfyjxf/nee/config/NEEConfig.java +++ b/src/main/java/com/github/vfyjxf/nee/config/NEEConfig.java @@ -14,17 +14,22 @@ import java.io.File; public class NEEConfig { public static Configuration config; + public static final String CATEGORY_PATTERN_TRANSFER = "transfer"; + public static final String CATEGORY_CRAFTING_HELPER = "helper"; + public static final String CATEGORY_OTHER_SETTINGS = "other"; public static String[] transformBlacklist = new String[0]; public static String[] transformPriorityList = new String[0]; public static String[] transformPriorityModList = new String[0]; + public static String itemCombinationMode = "ENABLED"; + public static String[] itemCombinationWhitelist = new String[0]; public static boolean noShift = true; public static boolean matchOtherItems = true; public static boolean drawHighlight = true; public static boolean allowSynchronousSwitchIngredient = true; - public static boolean useStackSizeFromNEI = false; - public static boolean enableCraftAmountSettingGui = true; + public static boolean useStackSizeFromNEI = true; + public static boolean enableCraftAmountSettingGui = false; public static int draggedStackDefaultSize = 1; @@ -32,70 +37,109 @@ public class NEEConfig { config = new Configuration(configFile); config.load(); - transformBlacklist = config.get("client", "transformItemBlacklist", new String[0], - "If item in the blacklist, it will not be transferred.\n" + - "the format is \" {modid:modid,name:name,meta:meta,recipeProcessor:recipeProcessorID,identifier:identifier}\"\n" + - "example: \"{modid:minecraft,name:iron_ingot,recipeProcessor:EnderIO,identifier:EnderIOAlloySmelter}\"").getStringList(); - transformPriorityList = config.get("client", "transformItemPriorityList", new String[0], - "If item in the priority list, it will be transferred first.").getStringList(); + { + transformBlacklist = config.get(CATEGORY_PATTERN_TRANSFER, "transformItemBlacklist", new String[0], + "If item in the blacklist, it will not be transferred.\n" + + "the format is \" {modid:modid,name:name,meta:meta,recipeProcessor:recipeProcessorID,identifier:identifier}\"\n" + + "example: \"{modid:minecraft,name:iron_ingot,recipeProcessor:EnderIO,identifier:EnderIOAlloySmelter}\"").getStringList(); + transformPriorityList = config.get(CATEGORY_PATTERN_TRANSFER, "transformItemPriorityList", new String[0], + "If item in the priority list, it will be transferred first.").getStringList(); - transformPriorityModList = config.get("client", "transformPriorityModList", new String[0], - "if oredict has this mod's item, use it first").getStringList(); + transformPriorityModList = config.get(CATEGORY_PATTERN_TRANSFER, "transformPriorityModList", new String[0], + "if oredict has this mod's item, use it first").getStringList(); - noShift = config.get("client", "noShift", true, - "if true, you don't need to press shift to use NEI's transfer system in CratingTerminal and PatternTerminal").getBoolean(); + noShift = config.get(CATEGORY_PATTERN_TRANSFER, "noShift", true, + "if true, you don't need to press shift to use NEI's transfer system in CratingTerminal and PatternTerminal").getBoolean(); - matchOtherItems = config.get("client", "matchOnCraftableItems", true, - "If true, Crafting Helper will match other items even they can't auto-crafting").getBoolean(); + itemCombinationMode = config.get(CATEGORY_PATTERN_TRANSFER, "itemCombinationMode", itemCombinationMode, + "Item Combination Mode Setting, here are all the modes. \n" + + "\"ENABLED\"" + " " + "\"DISABLED\"" + " " + "WHITELIST").getString(); - drawHighlight = config.get("client", "drawHighlight", true, - "if true,it will draw highlight for missing items and item which can autocraft in nei").getBoolean(); + itemCombinationWhitelist = config.get(CATEGORY_PATTERN_TRANSFER, "itemCombinationWhitelist", itemCombinationWhitelist, + "Whitelist for item combination").getStringList(); + } + { + matchOtherItems = config.get(CATEGORY_CRAFTING_HELPER, "matchOnCraftableItems", true, + "If true, Crafting Helper will match other items even they can't auto-crafting").getBoolean(); - allowSynchronousSwitchIngredient = config.get("client", "allowSynchronousSwitchIngredient", true, - "If true, it will make all similar ingredient switch at the same time").getBoolean(true); + drawHighlight = config.get(CATEGORY_CRAFTING_HELPER, "drawHighlight", true, + "if true,it will draw highlight for missing items and item which can autocraft in nei").getBoolean(); - useStackSizeFromNEI = config.get("client", "useStackSizeFromNEI", false, - "Use the StackSize set by NEI").getBoolean(); + enableCraftAmountSettingGui = config.get(CATEGORY_CRAFTING_HELPER, "enableCraftAmountSettingGui", false, + "If true, it will open a gui to set craft amount after ctrl + click [?] button").getBoolean(); + } + { + allowSynchronousSwitchIngredient = config.get(CATEGORY_OTHER_SETTINGS, "allowSynchronousSwitchIngredient", true, + "If true, it will make all similar ingredient switch at the same time").getBoolean(true); - enableCraftAmountSettingGui = config.get("client", "enableCraftAmountSettingGui", true, - "If true, it will open a gui to set craft amount after ctrl + click [?] button").getBoolean(); - - draggedStackDefaultSize = config.get("client", "draggedStackDefaultSize", 1, - "The default size of the dragged ItemStack when it is put in slot(Used when useStackSizeFromNEI is false)", 1, 64).getInt(); + useStackSizeFromNEI = config.get(CATEGORY_OTHER_SETTINGS, "useStackSizeFromNEI", true, + "Use the StackSize set by NEI").getBoolean(); + draggedStackDefaultSize = config.get(CATEGORY_OTHER_SETTINGS, "draggedStackDefaultSize", 1, + "The default size of the dragged ItemStack when it is put in slot(Used when useStackSizeFromNEI is false)", 1, 64).getInt(); + } if (config.hasChanged()) config.save(); } public static void reload() { config.load(); - transformBlacklist = config.get("client", "transformItemBlacklist", new String[0], + transformBlacklist = config.get(CATEGORY_PATTERN_TRANSFER, "transformItemBlacklist", new String[0], "If item in the blacklist, it will not be transferred.\n" + "the format is \" {modid:modid,name:name,meta:meta,recipeProcessor:recipeProcessorID,identifier:identifier}\"\n" + "example: \"{modid:minecraft,name:iron_ingot,recipeProcessor:EnderIO,identifier:EnderIOAlloySmelter}\"").getStringList(); - transformPriorityList = config.get("client", "transformItemPriorityList", new String[0], + transformPriorityList = config.get(CATEGORY_PATTERN_TRANSFER, "transformItemPriorityList", new String[0], "If item in the priority list, it will be transferred first.").getStringList(); - transformPriorityModList = config.get("client", "transformPriorityModList", new String[0], + transformPriorityModList = config.get(CATEGORY_PATTERN_TRANSFER, "transformPriorityModList", new String[0], "if oredict has this mod's item, use it first").getStringList(); - matchOtherItems = config.get("client", "matchOnCraftableItems", false, - "If false, Crafting Helper will not match other items").getBoolean(); + noShift = config.get(CATEGORY_PATTERN_TRANSFER, "noShift", true, + "if true, you don't need to press shift to use NEI's transfer system in CratingTerminal and PatternTerminal").getBoolean(); - allowSynchronousSwitchIngredient = config.get("client", "allowSynchronousSwitchIngredient", true, - "If true, it will make all similar ingredient switch at the same time").getBoolean(true); - - useStackSizeFromNEI = config.get("client", "useStackSizeFromNEI", false, - "Use the StackSize set by NEI").getBoolean(); - - enableCraftAmountSettingGui = config.get("client", "enableCraftAmountSettingGui", true, - "If true, it will open a gui to set craft amount after ctrl + click [?] button").getBoolean(); - - draggedStackDefaultSize = config.get("client", "draggedStackDefaultSize", 1, - "The default size of the dragged ItemStack when it is put in slot(Used when useStackSizeFromNEI is false)", 1, 64).getInt(); + itemCombinationMode = config.get(CATEGORY_PATTERN_TRANSFER, "itemCombinationMode", itemCombinationMode, + "Item Combination Mode Setting, here are all the modes. \n" + + "\"ENABLED\"" + " " + "\"DISABLED\"" + " " + "WHITELIST").getString(); + itemCombinationWhitelist = config.get(CATEGORY_PATTERN_TRANSFER, "itemCombinationWhitelist", itemCombinationWhitelist, + "Whitelist for item combination").getStringList(); ItemUtils.reloadConfig(); } + public static void setItemCombinationMode(String itemCombinationMode) { + NEEConfig.itemCombinationMode = itemCombinationMode; + config.get(CATEGORY_PATTERN_TRANSFER, "itemCombinationMode", itemCombinationMode, "Item Combination Mode Setting, here are all the modes. \n" + "\"ENABLED\"" + " " + "\"DISABLED\"" + " " + "WHITELIST").set(itemCombinationMode); + config.save(); + } + + public static void setItemCombinationWhitelist(String[] itemCombinationWhitelist) { + NEEConfig.itemCombinationWhitelist = itemCombinationWhitelist; + config.get(CATEGORY_PATTERN_TRANSFER, "itemCombinationWhitelist", itemCombinationWhitelist, "Whitelist for item combination").set(itemCombinationWhitelist); + config.save(); + } + + public static void setTransformBlacklist(String[] transformBlacklist) { + NEEConfig.transformBlacklist = transformBlacklist; + config.get("client", "transformItemBlacklist", new String[0], + "If item in the blacklist, it will not be transferred.\n" + + "the format is \" {modid:modid,name:name,meta:meta,recipeProcessor:recipeProcessorID,identifier:identifier}\"\n" + + "example: \"{modid:minecraft,name:iron_ingot,recipeProcessor:EnderIO,identifier:EnderIOAlloySmelter}\"").set(transformBlacklist); + config.save(); + } + + public static void setTransformPriorityList(String[] transformPriorityList) { + NEEConfig.transformPriorityList = transformPriorityList; + config.get("client", "transformPriorityModList", new String[0], + "if oredict has this mod's item, use it first").set(transformPriorityList); + config.save(); + } + + public static void setTransformPriorityModList(String[] transformPriorityModList) { + NEEConfig.transformPriorityModList = transformPriorityModList; + config.get("client", "transformPriorityModList", new String[0], + "if oredict has this mod's item, use it first").set(transformPriorityModList); + config.save(); + } + @SubscribeEvent public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event) { if (NotEnoughEnergistics.MODID.equals(event.modID)) { diff --git a/src/main/java/com/github/vfyjxf/nee/gui/GuiCraftingConfirm.java b/src/main/java/com/github/vfyjxf/nee/gui/GuiCraftingConfirm.java new file mode 100644 index 0000000..0db4f73 --- /dev/null +++ b/src/main/java/com/github/vfyjxf/nee/gui/GuiCraftingConfirm.java @@ -0,0 +1,29 @@ +package com.github.vfyjxf.nee.gui; + +import appeng.api.storage.ITerminalHost; +import appeng.api.storage.data.IAEItemStack; +import appeng.client.gui.implementations.GuiCraftConfirm; +import appeng.util.item.AEItemStack; +import com.github.vfyjxf.nee.network.NEENetworkHandler; +import com.github.vfyjxf.nee.network.packet.PacketCraftingRequest; +import net.minecraft.entity.player.InventoryPlayer; + +import static com.github.vfyjxf.nee.nei.NEECraftingHelper.*; + +public class GuiCraftingConfirm extends GuiCraftConfirm { + + public GuiCraftingConfirm(InventoryPlayer inventoryPlayer, ITerminalHost te) { + super(inventoryPlayer, te); + } + + @Override + public void onGuiClosed() { + if (tracker != null && tracker.getRequireStacks().size() > 1 && stackIndex < tracker.getRequireStacks().size()) { + IAEItemStack stack = AEItemStack.create(tracker.getRequiredStack(stackIndex)); + NEENetworkHandler.getInstance().sendToServer(new PacketCraftingRequest(stack, noPreview)); + stackIndex++; + } else { + tracker = null; + } + } +} diff --git a/src/main/java/com/github/vfyjxf/nee/gui/NEEGuiHandler.java b/src/main/java/com/github/vfyjxf/nee/gui/NEEGuiHandler.java index 39c8df3..394364f 100644 --- a/src/main/java/com/github/vfyjxf/nee/gui/NEEGuiHandler.java +++ b/src/main/java/com/github/vfyjxf/nee/gui/NEEGuiHandler.java @@ -7,6 +7,7 @@ import appeng.api.parts.IPartHost; import appeng.api.storage.ITerminalHost; import appeng.container.AEBaseContainer; import appeng.container.ContainerOpenContext; +import appeng.container.implementations.ContainerCraftConfirm; import appeng.parts.reporting.PartCraftingTerminal; import com.github.vfyjxf.nee.container.ContainerCraftingAmount; import com.github.vfyjxf.nee.utils.ModIDs; @@ -28,7 +29,8 @@ import static com.github.vfyjxf.nee.NotEnoughEnergistics.instance; public class NEEGuiHandler implements IGuiHandler { public static final int CRAFTING_AMOUNT_ID = 0; - public static final int CRAFTING_AMOUNT_WIRELESS_ID = 1; + public static final int CRAFTING_CONFIRM_ID = 1; + public static final int CRAFTING_AMOUNT_WIRELESS_ID = 2; @Nullable @Override @@ -41,10 +43,20 @@ public class NEEGuiHandler implements IGuiHandler { if (tile instanceof IPartHost) { IPartHost partHost = (IPartHost) tile; IPart part = partHost.getPart(side); - if (guiId == CRAFTING_AMOUNT_ID) { - if (part instanceof PartCraftingTerminal) { - return updateGui(new ContainerCraftingAmount(player.inventory, part), world, x, y, z, side, part); - } + switch (guiId) { + case CRAFTING_AMOUNT_ID: + if (part instanceof PartCraftingTerminal) { + return updateGui(new ContainerCraftingAmount(player.inventory, part), world, x, y, z, side, part); + } + return null; + case CRAFTING_CONFIRM_ID: + if (part instanceof PartCraftingTerminal) { + return updateGui(new ContainerCraftConfirm(player.inventory, (ITerminalHost) part), world, x, y, z, side, part); + } + return null; + + default: + break; } } } @@ -68,10 +80,20 @@ public class NEEGuiHandler implements IGuiHandler { if (tile instanceof IPartHost) { IPartHost partHost = (IPartHost) tile; IPart part = partHost.getPart(side); - if (guiId == CRAFTING_AMOUNT_ID) { - if (part instanceof PartCraftingTerminal) { - return updateGui(new GuiCraftingAmount(player.inventory, (ITerminalHost) part), world, x, y, z, side, part); - } + switch (guiId) { + case CRAFTING_AMOUNT_ID: + if (part instanceof PartCraftingTerminal) { + return updateGui(new GuiCraftingAmount(player.inventory, (ITerminalHost) part), world, x, y, z, side, part); + } + return null; + case CRAFTING_CONFIRM_ID: + if (part instanceof PartCraftingTerminal) { + return updateGui(new GuiCraftingConfirm(player.inventory, (ITerminalHost) part), world, x, y, z, side, part); + } + return null; + + default: + break; } } diff --git a/src/main/java/com/github/vfyjxf/nee/gui/widgets/GuiImgButtonEnableCombination.java b/src/main/java/com/github/vfyjxf/nee/gui/widgets/GuiImgButtonEnableCombination.java new file mode 100644 index 0000000..2c8ab59 --- /dev/null +++ b/src/main/java/com/github/vfyjxf/nee/gui/widgets/GuiImgButtonEnableCombination.java @@ -0,0 +1,87 @@ +package com.github.vfyjxf.nee.gui.widgets; + +import appeng.client.gui.widgets.ITooltip; +import com.github.vfyjxf.nee.config.ItemCombination; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.resources.I18n; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.opengl.GL11; + +public class GuiImgButtonEnableCombination extends GuiButton implements ITooltip { + + private ItemCombination currentValue; + + public GuiImgButtonEnableCombination(int x, int y, ItemCombination value) { + super(0, x, y, ""); + this.xPosition = x; + this.yPosition = y; + this.width = 8; + this.height = 8; + this.currentValue = value; + } + + @Override + public void drawButton(Minecraft minecraft, int mouseX, int mouseY) { + if (this.visible) { + GL11.glPushMatrix(); + GL11.glTranslatef(this.xPosition, this.yPosition, 0.0F); + GL11.glScalef(0.5f, 0.5f, 0.5f); + GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + minecraft.renderEngine.bindTexture(new ResourceLocation("neenergistics", "textures/gui/states.png")); + this.field_146123_n = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height; + this.drawTexturedModalRect(0, 0, 0, 0, 16, 16); + if (this.currentValue == ItemCombination.ENABLED) { + this.drawTexturedModalRect(0, 0, 16, 16, 16, 16); + } + if (this.currentValue == ItemCombination.DISABLED) { + this.drawTexturedModalRect(0, 0, 16, 0, 16, 16); + } + if (this.currentValue == ItemCombination.WHITELIST) { + this.drawTexturedModalRect(0, 0, 0, 16, 16, 16); + } + this.mouseDragged(minecraft, mouseX, mouseY); + GL11.glPopMatrix(); + } + } + + public void setValue(ItemCombination currentValue) { + this.currentValue = currentValue; + } + + public ItemCombination getCurrentValue() { + return currentValue; + } + + @Override + public String getMessage() { + return I18n.format("gui.neenergistics.button.title.combination") + + "\n" + + I18n.format("gui.neenergistics.button.tooltip.combination", currentValue.getLocalName()); + } + + @Override + public int xPos() { + return this.xPosition; + } + + @Override + public int yPos() { + return this.yPosition; + } + + @Override + public int getWidth() { + return this.width; + } + + @Override + public int getHeight() { + return this.height; + } + + @Override + public boolean isVisible() { + return this.visible; + } +} 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 f128f7c..cb01e49 100644 --- a/src/main/java/com/github/vfyjxf/nee/nei/NEECraftingHandler.java +++ b/src/main/java/com/github/vfyjxf/nee/nei/NEECraftingHandler.java @@ -6,6 +6,8 @@ import codechicken.nei.PositionedStack; import codechicken.nei.api.IOverlayHandler; import codechicken.nei.recipe.IRecipeHandler; import codechicken.nei.recipe.TemplateRecipeHandler; +import com.github.vfyjxf.nee.config.ItemCombination; +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.network.packet.PacketExtremeRecipe; @@ -18,10 +20,7 @@ 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; +import java.util.*; /** * @author vfyjxf @@ -77,12 +76,18 @@ public class NEECraftingHandler implements IOverlayHandler { for (PositionedStack positionedStack : inputs) { ItemStack currentStack = positionedStack.items[0]; boolean find = false; - for (PositionedStack storedStack : tInputs) { - ItemStack firstStack = storedStack.items[0]; - boolean areItemStackEqual = firstStack.isItemEqual(currentStack) && ItemStack.areItemStackTagsEqual(firstStack, currentStack); - if (areItemStackEqual && (firstStack.stackSize + currentStack.stackSize) <= firstStack.getMaxStackSize()) { - find = true; - storedStack.items[0].stackSize = firstStack.stackSize + currentStack.stackSize; + ItemCombination currentValue = ItemCombination.valueOf(NEEConfig.itemCombinationMode); + if (currentValue != ItemCombination.DISABLED) { + boolean isWhitelist = currentValue == ItemCombination.WHITELIST && Arrays.asList(NEEConfig.itemCombinationWhitelist).contains(identifier); + if (currentValue == ItemCombination.ENABLED || isWhitelist) { + for (PositionedStack storedStack : tInputs) { + ItemStack firstStack = storedStack.items[0]; + boolean areItemStackEqual = firstStack.isItemEqual(currentStack) && ItemStack.areItemStackTagsEqual(firstStack, currentStack); + if (areItemStackEqual && (firstStack.stackSize + currentStack.stackSize) <= firstStack.getMaxStackSize()) { + find = true; + storedStack.items[0].stackSize = firstStack.stackSize + currentStack.stackSize; + } + } } } if (!find) { 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 342fdc0..6a7c649 100644 --- a/src/main/java/com/github/vfyjxf/nee/proxy/ClientProxy.java +++ b/src/main/java/com/github/vfyjxf/nee/proxy/ClientProxy.java @@ -1,7 +1,7 @@ package com.github.vfyjxf.nee.proxy; import com.github.vfyjxf.nee.NEECommands; -import com.github.vfyjxf.nee.client.GuiHandler; +import com.github.vfyjxf.nee.client.GuiEventHandler; import com.github.vfyjxf.nee.client.NEEContainerDrawHandler; import com.github.vfyjxf.nee.config.NEEConfig; import com.github.vfyjxf.nee.nei.NEECraftingHelper; @@ -15,8 +15,8 @@ public class ClientProxy extends CommonProxy { @Override public void init(FMLInitializationEvent event) { ClientCommandHandler.instance.registerCommand(new NEECommands()); - FMLCommonHandler.instance().bus().register(GuiHandler.instance); - MinecraftForge.EVENT_BUS.register(GuiHandler.instance); + FMLCommonHandler.instance().bus().register(GuiEventHandler.instance); + MinecraftForge.EVENT_BUS.register(GuiEventHandler.instance); if (NEEConfig.noShift) { MinecraftForge.EVENT_BUS.register(NEECraftingHelper.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 3686940..b1366c8 100644 --- a/src/main/java/com/github/vfyjxf/nee/utils/GuiUtils.java +++ b/src/main/java/com/github/vfyjxf/nee/utils/GuiUtils.java @@ -5,9 +5,11 @@ import appeng.helpers.IContainerCraftingPacket; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.ScaledResolution; import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; +import org.lwjgl.input.Mouse; /** * @author vfyjxf @@ -47,7 +49,14 @@ public class GuiUtils { } } - public static boolean isMouseOverButton(GuiButton button, int mouseX, int mouseY) { + public static boolean isMouseOverButton(GuiButton button) { + Minecraft mc = Minecraft.getMinecraft(); + final ScaledResolution scaledresolution = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); + int i = scaledresolution.getScaledWidth(); + int j = scaledresolution.getScaledHeight(); + final int mouseX = Mouse.getX() * i / mc.displayWidth; + final int mouseY = j - Mouse.getY() * j / mc.displayHeight - 1; + return mouseX >= button.xPosition && mouseY >= button.yPosition && mouseX < button.xPosition + button.width && 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 63f9343..3d70e62 100644 --- a/src/main/java/com/github/vfyjxf/nee/utils/IngredientTracker.java +++ b/src/main/java/com/github/vfyjxf/nee/utils/IngredientTracker.java @@ -5,6 +5,7 @@ import appeng.api.storage.data.IItemList; import appeng.client.gui.implementations.GuiMEMonitorable; import appeng.client.me.ItemRepo; import codechicken.nei.PositionedStack; +import codechicken.nei.recipe.GuiRecipe; import codechicken.nei.recipe.IRecipeHandler; import com.github.vfyjxf.nee.config.NEEConfig; import cpw.mods.fml.relauncher.ReflectionHelper; @@ -23,12 +24,14 @@ public class IngredientTracker { private int craftingAmount = 1; private final GuiContainer termGui; private List requireStacks; + private final int recipeIndex; /** * For NEECraftingHelper */ public IngredientTracker(GuiContainer termGui, IRecipeHandler recipe, int recipeIndex) { this.termGui = termGui; + this.recipeIndex = recipeIndex; for (PositionedStack requiredIngredient : recipe.getIngredientStacks(recipeIndex)) { Ingredient ingredient = new Ingredient(requiredIngredient); @@ -46,6 +49,26 @@ public class IngredientTracker { this.calculateIngredients(); } + public IngredientTracker(GuiRecipe guiRecipe, IRecipeHandler recipe, int recipeIndex) { + this.termGui = guiRecipe.firstGui; + this.recipeIndex = recipeIndex; + getCraftableStacks(); + + for (PositionedStack requiredIngredient : recipe.getIngredientStacks(recipeIndex)) { + Ingredient ingredient = new Ingredient(requiredIngredient); + ingredients.add(ingredient); + } + + for (Ingredient ingredient : this.ingredients) { + for (IAEItemStack stack : getCraftableStacks()) { + if (ingredient.getIngredient().contains(stack.getItemStack())) { + ingredient.setCraftableIngredient(stack.getItemStack()); + } + } + } + + } + @SuppressWarnings("unchecked") private List getCraftableStacks() { @@ -160,6 +183,10 @@ public class IngredientTracker { return this.getRequireStacks().get(index); } + public int getRecipeIndex() { + return recipeIndex; + } + public void setCraftingAmount(int craftingAmount) { this.craftingAmount = craftingAmount; } diff --git a/src/main/resources/META-INF/neenergistics_at.cfg b/src/main/resources/META-INF/neenergistics_at.cfg index e228df5..01fb0e2 100644 --- a/src/main/resources/META-INF/neenergistics_at.cfg +++ b/src/main/resources/META-INF/neenergistics_at.cfg @@ -1,4 +1,5 @@ public net.minecraft.client.gui.inventory.GuiContainer field_147003_i #guiLeft public net.minecraft.client.gui.inventory.GuiContainer field_147009_r #guiTop +public net.minecraft.client.gui.inventory.GuiContainer field_147000_g #ySize public net.minecraft.client.gui.inventory.GuiContainer func_146975_c(II)Lnet/minecraft/inventory/Slot; #getSlotAtPositionv public net.minecraft.client.gui.GuiScreen func_146283_a(Ljava/util/List;II)V #drawHoveringText \ No newline at end of file diff --git a/src/main/resources/assets/neenergistics/lang/en_US.lang b/src/main/resources/assets/neenergistics/lang/en_US.lang index eb69258..75bfdb1 100644 --- a/src/main/resources/assets/neenergistics/lang/en_US.lang +++ b/src/main/resources/assets/neenergistics/lang/en_US.lang @@ -1,8 +1,15 @@ neenergistics.gui.tooltip.helper.crafting=click to request missing items neenergistics.gui.tooltip.missing=Missing Items neenergistics.gui.tooltip.helper.pattern=Autocrafting available + nei.options.keys.nee=NotEnoughEnergistics nei.options.keys.nee.count=Change Item Count nei.options.keys.nee.ingredient=Choose ingredient nei.options.keys.nee.preview=Crafting Help -nei.options.keys.nee.nopreview=Crafting Help(No Preview) \ No newline at end of file +nei.options.keys.nee.nopreview=Crafting Help(No Preview) + +gui.neenergistics.button.title.combination=Combine Items +gui.neenergistics.button.tooltip.combination=Current Mode: %s +gui.neenergistics.button.name.enabled=Enabled +gui.neenergistics.button.name.disabled=Disabled +gui.neenergistics.button.name.whitelist=Whitelist diff --git a/src/main/resources/assets/neenergistics/lang/zh_CN.lang b/src/main/resources/assets/neenergistics/lang/zh_CN.lang index 1cd2a7e..210dbed 100644 --- a/src/main/resources/assets/neenergistics/lang/zh_CN.lang +++ b/src/main/resources/assets/neenergistics/lang/zh_CN.lang @@ -1,8 +1,15 @@ neenergistics.gui.tooltip.helper.crafting=点击以请求缺失的物品 neenergistics.gui.tooltip.missing=缺失物品 neenergistics.gui.tooltip.helper.pattern=自动合成已可用 + nei.options.keys.nee=NotEnoughEnergistics nei.options.keys.nee.count=修改物品数量 nei.options.keys.nee.ingredient=选择材料 nei.options.keys.nee.preview=合成帮助 nei.options.keys.nee.nopreview=合成帮助(无预览) + +gui.neenergistics.button.title.combination=合并同类物品 +gui.neenergistics.button.tooltip.combination=当前模式: %s +gui.neenergistics.button.name.enabled=开启 +gui.neenergistics.button.name.disabled=关闭 +gui.neenergistics.button.name.whitelist=白名单 diff --git a/src/main/resources/assets/neenergistics/textures/gui/states.png b/src/main/resources/assets/neenergistics/textures/gui/states.png new file mode 100644 index 0000000..9cc7e14 Binary files /dev/null and b/src/main/resources/assets/neenergistics/textures/gui/states.png differ diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info index 80c7fc0..6876c8d 100644 --- a/src/main/resources/mcmod.info +++ b/src/main/resources/mcmod.info @@ -10,7 +10,7 @@ "authorList": [ "vfyjxf" ], - "credits": "vfyjxf", + "credits": "Thanks TheRealp455w0rd", "logoFile": "assets/neenergistics/meta/logo.png", "screenshots": [], "dependencies": []