diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a94ba54 --- /dev/null +++ b/.gitignore @@ -0,0 +1,24 @@ +.git +.gradle +.idea +.settings +.metadata +bin +build +run +minecraft +eclipse +.classpath +.project +.apt_generated +.apt_generated_tests + +*.bat +*.sh +*.iml +*.ipr +*.iws +*.launch +.factorypath + +forge*changelog.txt diff --git a/README.md b/README.md index 0355bc1..8e440b3 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,15 @@ -# NotEnoughEnergistics -NotEnoughEnergistics is a port of Just Enough Energistics to Minecraft 1.7.10 +#Not Enough Energistics +NotEnoughEnergistics is a port of [Just Enough Energistics](https://www.curseforge.com/minecraft/mc-mods/just-enough-energistics-jee) to Minecraft 1.7.10 + +This mod replaces AE2's default NEI integration for the Pattern Terminal. + +By default, AE2 forces the player to either have the necessary items for a recipe in their personal inventory or in their ME network. + +This mod removes that functionality and allows the player to use NEI's transfer system (the [?] button) to create patterns whether the player possesses the items required by the recipe. + +##Compatible Modslist as followed: + -[x] Vanilla + -[x] GregTech + -[x] IndustrialCraft2 + -[x] Avaritia + diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..8efa59a --- /dev/null +++ b/build.gradle @@ -0,0 +1,88 @@ +buildscript { + repositories { + mavenCentral() + jcenter() + maven { + name = "github" + url = "https://github.com/juanmuscaria/maven/raw/master" + } + } + dependencies { + classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-1.4.0-SNAPSHOT' + } +} + +apply plugin: 'java' +apply plugin: 'forge' + +[compileJava, compileTestJava]*.options*.encoding = 'UTF-8' +sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' + +version = mod_version +group = mod_group +archivesBaseName = mod_archives_name + +minecraft { + version = "1.7.10-10.13.4.1614-1.7.10" + runDir = "eclipse" + replace "@VERSION@", project.version +} + +repositories { + maven { + name 'chickenbones' + url 'http://chickenbones.net/maven' + } + flatDir { + dirs 'libs' + } +} + +dependencies { + + compile "codechicken:NotEnoughItems:${mc_version}-${nei_version}:universal" + compile "codechicken:CodeChickenLib:1.7.10-1.1.3.138:dev" + compile "codechicken:CodeChickenCore:1.7.10-1.0.7.+:dev" + +// https://mvnrepository.com/artifact/com.alibaba/fastjson + implementation group: 'com.alibaba', name: 'fastjson', version: '1.2.76' + +} + +processResources { + + from(sourceSets.main.resources.srcDirs) { + include 'mcmod.info' + expand 'version': project.version, + 'mod_id': mod_id, + 'mod_name': mod_name, + 'mod_author': mod_author, + 'mod_description': mod_description, + 'mc_version': mc_version, + 'mod_version': mod_version + } + + from(sourceSets.main.resources.srcDirs) { + exclude 'mcmod.info' + } +} + +task devJar(type: Jar) { + classifier = 'dev' + from sourceSets.main.output +} + +task sourcesJar(type: Jar) { + classifier = 'sources' + from sourceSets.main.allSource +} + +jar{ + appendix project.minecraft.version +} + + +artifacts { + archives devJar + archives sourcesJar +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..c4793ed --- /dev/null +++ b/gradle.properties @@ -0,0 +1,17 @@ +# Gradle Specifications +org.gradle.jvmargs=-Xmx2G -Xms2G +org.gradle.daemon=false + +# General Specifications +mc_version=1.7.10 +nei_version=2.1.6-GTNH +ae2_version=rv3-beta-52-GTNH +mod_version=1.0.0 +forge_version=10.13.4.1614 +mod_group=com.github.vfyjxf.neenergistics +mod_id=neenergistics +mod_name=NotEnoughEnergistics +mod_archives_name=NotEnoughEnergistics +mod_author=vfyxf +mod_description= +mod_credits=Thanks TheRealp455w0rd diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..b761216 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..f0b5a51 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Wed Jul 02 15:54:47 CDT 2014 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..91a7e26 --- /dev/null +++ b/gradlew @@ -0,0 +1,164 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# For Cygwin, ensure paths are in UNIX format before anything is touched. +if $cygwin ; then + [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` +fi + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >&- +APP_HOME="`pwd -P`" +cd "$SAVED" >&- + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/libs/NotEnoughItems-1.7.10-2.1.6-GTNH-src.jar b/libs/NotEnoughItems-1.7.10-2.1.6-GTNH-src.jar new file mode 100644 index 0000000..8931a9b Binary files /dev/null and b/libs/NotEnoughItems-1.7.10-2.1.6-GTNH-src.jar differ diff --git a/libs/NotEnoughItems-1.7.10-2.1.6-GTNH-universal.jar b/libs/NotEnoughItems-1.7.10-2.1.6-GTNH-universal.jar new file mode 100644 index 0000000..949ea5a Binary files /dev/null and b/libs/NotEnoughItems-1.7.10-2.1.6-GTNH-universal.jar differ diff --git a/libs/appliedenergistics2-rv3-beta-51-GTNH-dev.jar b/libs/appliedenergistics2-rv3-beta-51-GTNH-dev.jar new file mode 100644 index 0000000..258be5b Binary files /dev/null and b/libs/appliedenergistics2-rv3-beta-51-GTNH-dev.jar differ diff --git a/libs/appliedenergistics2-rv3-beta-51-GTNH-sources.jar b/libs/appliedenergistics2-rv3-beta-51-GTNH-sources.jar new file mode 100644 index 0000000..ad0e759 Binary files /dev/null and b/libs/appliedenergistics2-rv3-beta-51-GTNH-sources.jar differ diff --git a/src/main/java/com/github/vfyjxf/nee/Config.java b/src/main/java/com/github/vfyjxf/nee/Config.java new file mode 100644 index 0000000..b402464 --- /dev/null +++ b/src/main/java/com/github/vfyjxf/nee/Config.java @@ -0,0 +1,4 @@ +package com.github.vfyjxf.nee; + +public class Config { +} diff --git a/src/main/java/com/github/vfyjxf/nee/NEINeeConfig.java b/src/main/java/com/github/vfyjxf/nee/NEINeeConfig.java new file mode 100644 index 0000000..26cdbbe --- /dev/null +++ b/src/main/java/com/github/vfyjxf/nee/NEINeeConfig.java @@ -0,0 +1,41 @@ +package com.github.vfyjxf.nee; + +import appeng.client.gui.implementations.GuiPatternTerm; +import codechicken.nei.api.API; +import codechicken.nei.api.IConfigureNEI; +import com.github.vfyjxf.nee.nei.NEECraftingHandler; +import com.github.vfyjxf.nee.processor.IRecipeProcessor; +import com.github.vfyjxf.nee.processor.RecipeProcessor; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + + +public class NEINeeConfig implements IConfigureNEI { + @Override + public void loadConfig() { + + RecipeProcessor.init(); + + List identifiers = new ArrayList<>(Arrays.asList("crafting", "crafting2x2","brewing","smelting","fuel")); + for(IRecipeProcessor processor : RecipeProcessor.recipeProcessors){ + identifiers.addAll(processor.getAllOverlayIdentifier()); + } + + for(String ident : identifiers){ + API.registerGuiOverlay(GuiPatternTerm.class,ident); + API.registerGuiOverlayHandler(GuiPatternTerm.class, new NEECraftingHandler(), ident); + } + } + + @Override + public String getName() { + return NotEnoughEnergistics.NAME; + } + + @Override + public String getVersion() { + return NotEnoughEnergistics.VERSION; + } +} diff --git a/src/main/java/com/github/vfyjxf/nee/NotEnoughEnergistics.java b/src/main/java/com/github/vfyjxf/nee/NotEnoughEnergistics.java new file mode 100644 index 0000000..7c0cc8f --- /dev/null +++ b/src/main/java/com/github/vfyjxf/nee/NotEnoughEnergistics.java @@ -0,0 +1,22 @@ +package com.github.vfyjxf.nee; + +import com.github.vfyjxf.nee.network.NEENetworkHandler; +import cpw.mods.fml.common.Mod; +import cpw.mods.fml.common.event.FMLPreInitializationEvent; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + + +@Mod(modid = NotEnoughEnergistics.MODID, version = NotEnoughEnergistics.VERSION, name = NotEnoughEnergistics.NAME, dependencies = NotEnoughEnergistics.DEPENDENCIES) +public class NotEnoughEnergistics { + public static final String MODID = "neenergistics"; + public static final String NAME = "NotEnoughEnergistics"; + public static final String VERSION = "@VERSION@"; + public static final String DEPENDENCIES = "required-after:NotEnoughItems;required-after:appliedenergistics2"; + public static final Logger logger = LogManager.getLogger("NotEnoughEnergistics"); + + @Mod.EventHandler + public void preInit(FMLPreInitializationEvent e) { + NEENetworkHandler.init(); + } +} diff --git a/src/main/java/com/github/vfyjxf/nee/nei/NEECraftingHandler.java b/src/main/java/com/github/vfyjxf/nee/nei/NEECraftingHandler.java new file mode 100644 index 0000000..b7d74ad --- /dev/null +++ b/src/main/java/com/github/vfyjxf/nee/nei/NEECraftingHandler.java @@ -0,0 +1,106 @@ +package com.github.vfyjxf.nee.nei; + +import appeng.client.gui.implementations.GuiPatternTerm; +import appeng.client.gui.implementations.GuiPatternTermEx; +import codechicken.nei.api.IOverlayHandler; +import codechicken.nei.recipe.TemplateRecipeHandler; +import com.github.vfyjxf.nee.network.NEENetworkHandler; +import appeng.util.Platform; +import codechicken.nei.PositionedStack; +import codechicken.nei.recipe.IRecipeHandler; +import com.github.vfyjxf.nee.network.packet.PacketNEIPatternRecipe; +import com.github.vfyjxf.nee.processor.IRecipeProcessor; +import com.github.vfyjxf.nee.processor.RecipeProcessor; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +import java.util.List; + +/** + * @author vfyjxf + */ +public class NEECraftingHandler implements IOverlayHandler { + + public static final String OUTPUT_KEY = "Outputs"; + + @Override + public void overlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean shift) { + if (firstGui instanceof GuiPatternTerm || firstGui instanceof GuiPatternTermEx) { + NEENetworkHandler.getInstance().sendToServer(packRecipe(recipe, recipeIndex)); + } + + } + + private PacketNEIPatternRecipe packRecipe(IRecipeHandler recipe, int recipeIndex) { + if (isCraftingTableRecipe(recipe)) { + return packCraftingTableRecipe(recipe, recipeIndex); + } else { + return packProcessRecipe(recipe, recipeIndex); + } + } + + private PacketNEIPatternRecipe packProcessRecipe(IRecipeHandler recipe, int recipeIndex) { + final NBTTagCompound recipeInputs = new NBTTagCompound(); + NBTTagCompound recipeOutputs = new NBTTagCompound(); + String identifier = ((TemplateRecipeHandler) recipe).getOverlayIdentifier(); + int inputIndex = 0; + int outputIndex = 0; + //get all recipe inputs and other stacks,use first item + for (IRecipeProcessor processor : RecipeProcessor.recipeProcessors) { + List inputs = processor.getRecipeInput(recipe, recipeIndex, identifier); + List outputs = processor.getRecipeOutput(recipe, recipeIndex, identifier); + if (inputs != null && outputs != null) { + for (PositionedStack positionedStack : inputs) { + ItemStack currentStack = positionedStack.items[0]; + for (ItemStack stack : positionedStack.items) { + if (Platform.isRecipePrioritized(stack)) { + currentStack = stack.copy(); + break; + } + } + recipeInputs.setTag("#" + inputIndex, currentStack.writeToNBT(new NBTTagCompound())); + inputIndex++; + } + + for (PositionedStack positionedStack : outputs) { + if (outputIndex >= 3 || positionedStack.item == null) { + continue; + } + recipeOutputs.setTag(OUTPUT_KEY + outputIndex, positionedStack.item.writeToNBT(new NBTTagCompound())); + outputIndex++; + } + } + } + + return new PacketNEIPatternRecipe(recipeInputs, recipeOutputs); + } + + private PacketNEIPatternRecipe packCraftingTableRecipe(IRecipeHandler recipe, int recipeIndex) { + final NBTTagCompound recipeInputs = new NBTTagCompound(); + final List ingredients = recipe.getIngredientStacks(recipeIndex); + for (final 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.items[0]; + for (ItemStack currentStack : currentStackList) { + if (Platform.isRecipePrioritized(currentStack)) { + stack = currentStack.copy(); + } + } + recipeInputs.setTag("#" + slotIndex, stack.writeToNBT(new NBTTagCompound())); + } + } + return new PacketNEIPatternRecipe(recipeInputs, null); + } + + private boolean isCraftingTableRecipe(IRecipeHandler recipe) { + TemplateRecipeHandler templateRecipeHandler = (TemplateRecipeHandler) recipe; + String overlayIdentifier = templateRecipeHandler.getOverlayIdentifier(); + return "crafting".equals(overlayIdentifier) || "crafting2x2".equals(overlayIdentifier); + } + +} diff --git a/src/main/java/com/github/vfyjxf/nee/network/NEENetworkHandler.java b/src/main/java/com/github/vfyjxf/nee/network/NEENetworkHandler.java new file mode 100644 index 0000000..74db87d --- /dev/null +++ b/src/main/java/com/github/vfyjxf/nee/network/NEENetworkHandler.java @@ -0,0 +1,20 @@ +package com.github.vfyjxf.nee.network; + +import com.github.vfyjxf.nee.NotEnoughEnergistics; +import com.github.vfyjxf.nee.network.packet.PacketNEIPatternRecipe; +import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper; +import cpw.mods.fml.relauncher.Side; + +public class NEENetworkHandler { + + private static final SimpleNetworkWrapper INSTANCE = new SimpleNetworkWrapper(NotEnoughEnergistics.MODID); + + public static SimpleNetworkWrapper getInstance(){ + return INSTANCE; + } + + public static void init(){ + INSTANCE.registerMessage(PacketNEIPatternRecipe.class, PacketNEIPatternRecipe.class,0, Side.SERVER); + } + +} diff --git a/src/main/java/com/github/vfyjxf/nee/network/packet/PacketNEIPatternRecipe.java b/src/main/java/com/github/vfyjxf/nee/network/packet/PacketNEIPatternRecipe.java new file mode 100644 index 0000000..8d55efd --- /dev/null +++ b/src/main/java/com/github/vfyjxf/nee/network/packet/PacketNEIPatternRecipe.java @@ -0,0 +1,166 @@ +package com.github.vfyjxf.nee.network.packet; + +import appeng.api.networking.IGrid; +import appeng.api.networking.IGridNode; +import appeng.api.networking.security.ISecurityGrid; +import appeng.api.networking.storage.IStorageGrid; +import appeng.container.implementations.ContainerPatternTerm; +import appeng.container.implementations.ContainerPatternTermEx; +import appeng.helpers.IContainerCraftingPacket; +import com.github.vfyjxf.nee.nei.NEECraftingHandler; +import cpw.mods.fml.common.network.ByteBufUtils; +import cpw.mods.fml.common.network.simpleimpl.IMessage; +import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; +import cpw.mods.fml.common.network.simpleimpl.MessageContext; +import io.netty.buffer.ByteBuf; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import static com.github.vfyjxf.nee.nei.NEECraftingHandler.OUTPUT_KEY; + +import javax.annotation.Nonnull; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + + +public class PacketNEIPatternRecipe implements IMessage, IMessageHandler { + + NBTTagCompound input; + NBTTagCompound output; + private final ItemStack EMPTY = (ItemStack) null; + + public PacketNEIPatternRecipe() { + } + + public PacketNEIPatternRecipe(@Nonnull NBTTagCompound input, NBTTagCompound output) { + this.input = input; + this.output = output; + } + + + @Override + public void fromBytes(ByteBuf buf) { + this.input = ByteBufUtils.readTag(buf); + if (buf.readBoolean()) { + this.output = ByteBufUtils.readTag(buf); + } + } + + @Override + public void toBytes(ByteBuf buf) { + ByteBufUtils.writeTag(buf, this.input); + if (this.output != null) { + buf.writeBoolean(true); + ByteBufUtils.writeTag(buf, this.output); + } else { + buf.writeBoolean(false); + } + } + + @Override + public IMessage onMessage(PacketNEIPatternRecipe message, MessageContext ctx) { + EntityPlayerMP player = ctx.getServerHandler().playerEntity; + Container container = player.openContainer; + if (container instanceof ContainerPatternTerm && message.output == null) { + ((ContainerPatternTerm) container).getPatternTerminal().setCraftingRecipe(true); + message.craftingTableRecipeHandler((ContainerPatternTerm) container, message); + } else if (container instanceof ContainerPatternTerm) { + ((ContainerPatternTerm) container).getPatternTerminal().setCraftingRecipe(false); + message.processRecipeHandler((ContainerPatternTerm) container, message); + } else if (container instanceof ContainerPatternTermEx){ + + } + return null; + } + + private void craftingTableRecipeHandler(ContainerPatternTerm container, PacketNEIPatternRecipe message) { + 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 : ItemStack.loadItemStackFromNBT(currentStack); + } + + final IContainerCraftingPacket cct = container; + final IGridNode node = cct.getNetworkNode(); + + if (node != null) { + final IGrid grid = node.getGrid(); + if (grid == null) { + return; + } + + final IStorageGrid inv = grid.getCache(IStorageGrid.class); + final ISecurityGrid security = grid.getCache(ISecurityGrid.class); + final IInventory craftMatrix = cct.getInventoryByName("crafting"); + + if (inv != null && message.input != null && security != null) { + for (int i = 0; i < craftMatrix.getSizeInventory(); i++) { + ItemStack currentItem = null; + if (recipeInput[i] != null) { + currentItem = recipeInput[i].copy(); + } + craftMatrix.setInventorySlotContents(i, currentItem); + } + container.onCraftMatrixChanged(craftMatrix); + } + + } + + } + + private void processRecipeHandler(ContainerPatternTerm container, PacketNEIPatternRecipe message) { + + ItemStack[] recipeInput = new ItemStack[9]; + ItemStack[] recipeOutput = new ItemStack[3]; + + + for (int i = 0; i < recipeInput.length; i++) { + NBTTagCompound currentStack = (NBTTagCompound) message.input.getTag("#" + i); + recipeInput[i] = currentStack == null ? null : ItemStack.loadItemStackFromNBT(currentStack); + } + + for (int i = 0; i < recipeOutput.length; i++) { + NBTTagCompound currentStack = (NBTTagCompound) message.output.getTag(OUTPUT_KEY + i); + recipeOutput[i] = currentStack == null ? null : ItemStack.loadItemStackFromNBT(currentStack); + } + + final IContainerCraftingPacket cct = container; + final IGridNode node = cct.getNetworkNode(); + + if (node != null) { + final IGrid grid = node.getGrid(); + if (grid == null) { + return; + } + final IStorageGrid inv = grid.getCache(IStorageGrid.class); + final ISecurityGrid security = grid.getCache(ISecurityGrid.class); + final IInventory craftMatrix = cct.getInventoryByName("crafting"); + final IInventory outputMatrix = cct.getInventoryByName("output"); + + if (inv != null && message.input != null && security != null) { + for (int i = 0; i < craftMatrix.getSizeInventory(); i++) { + ItemStack currentItem = null; + if (recipeInput[i] != null) { + currentItem = recipeInput[i].copy(); + } + craftMatrix.setInventorySlotContents(i, currentItem); + } + + for (int i = 0; i < outputMatrix.getSizeInventory(); i++) { + ItemStack currentItem = null; + if (recipeOutput[i] != null) { + currentItem = recipeOutput[i].copy(); + } + outputMatrix.setInventorySlotContents(i, currentItem); + } + container.onCraftMatrixChanged(craftMatrix); + } + } + } + +} diff --git a/src/main/java/com/github/vfyjxf/nee/processor/AvaritiaRecipeProcessor.java b/src/main/java/com/github/vfyjxf/nee/processor/AvaritiaRecipeProcessor.java new file mode 100644 index 0000000..2eb2f5f --- /dev/null +++ b/src/main/java/com/github/vfyjxf/nee/processor/AvaritiaRecipeProcessor.java @@ -0,0 +1,37 @@ +package com.github.vfyjxf.nee.processor; + +import codechicken.nei.PositionedStack; +import codechicken.nei.recipe.IRecipeHandler; + +import java.util.*; + +public class AvaritiaRecipeProcessor implements IRecipeProcessor{ + @Override + public Set getAllOverlayIdentifier() { + return new HashSet<>(Arrays.asList( + "extreme","extreme_compression" + )); + } + + @Override + public List getRecipeInput(IRecipeHandler recipe, int recipeIndex, String identifier) { + for(String ident : getAllOverlayIdentifier()){ + if(ident.equals(identifier)){ + return new ArrayList<>(recipe.getIngredientStacks(recipeIndex)); + } + } + return null; + } + + @Override + public List getRecipeOutput(IRecipeHandler recipe, int recipeIndex, String identifier) { + for(String ident : getAllOverlayIdentifier()){ + if(ident.equals(identifier)){ + List recipeOutput = new ArrayList<>(); + recipeOutput.add(recipe.getResultStack(recipeIndex)); + return recipeOutput; + } + } + return null; + } +} diff --git a/src/main/java/com/github/vfyjxf/nee/processor/GregTechRecipeProcessor.java b/src/main/java/com/github/vfyjxf/nee/processor/GregTechRecipeProcessor.java new file mode 100644 index 0000000..cfacf1c --- /dev/null +++ b/src/main/java/com/github/vfyjxf/nee/processor/GregTechRecipeProcessor.java @@ -0,0 +1,71 @@ +package com.github.vfyjxf.nee.processor; + +import codechicken.nei.PositionedStack; +import codechicken.nei.recipe.IRecipeHandler; +import gregtech.api.enums.ItemList; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fluids.FluidStack; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +/** + * @author vfyjxf + */ +public class GregTechRecipeProcessor implements IRecipeProcessor { + + private static final Class gtDefaultClz, gtAssLineClz; + + static { + Class gtDH = null; + Class gtAL = null; + try { + gtDH = Class.forName("gregtech.nei.GT_NEI_DefaultHandler"); + gtAL = Class.forName("gregtech.nei.GT_NEI_AssLineHandler"); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + gtDefaultClz = gtDH; + gtAssLineClz = gtAL; + } + + @Override + public Set getAllOverlayIdentifier() { + + Set identifiers = new HashSet<>(); + for (GT_Recipe.GT_Recipe_Map tMap : GT_Recipe.GT_Recipe_Map.sMappings) { + if (tMap.mNEIAllowed) { + identifiers.add(tMap.mNEIName); + } + } + identifiers.add("gt.recipe.fakeAssemblylineProcess"); + return identifiers; + } + + @Override + public List getRecipeInput(IRecipeHandler recipe, int recipeIndex, String identifier) { + if (gtDefaultClz.isInstance(recipe) || gtAssLineClz.isInstance(recipe)) { + List recipeInputs = new ArrayList<>(recipe.getIngredientStacks(recipeIndex)); + recipeInputs.removeIf(positionedStack -> GT_Utility.getFluidFromDisplayStack(positionedStack.items[0]) != null); + return recipeInputs; + } + return null; + } + + @Override + public List getRecipeOutput(IRecipeHandler recipe, int recipeIndex, String identifier) { + if (gtDefaultClz.isInstance(recipe) || gtAssLineClz.isInstance(recipe)) { + List recipeOutputs = new ArrayList<>(recipe.getOtherStacks(recipeIndex)); + recipeOutputs.removeIf(positionedStack -> GT_Utility.getFluidFromDisplayStack(positionedStack.items[0]) != null); + return recipeOutputs; + } + return null; + } + +} diff --git a/src/main/java/com/github/vfyjxf/nee/processor/ICRecipeProcessor.java b/src/main/java/com/github/vfyjxf/nee/processor/ICRecipeProcessor.java new file mode 100644 index 0000000..c1b979e --- /dev/null +++ b/src/main/java/com/github/vfyjxf/nee/processor/ICRecipeProcessor.java @@ -0,0 +1,44 @@ +package com.github.vfyjxf.nee.processor; + +import codechicken.nei.PositionedStack; +import codechicken.nei.recipe.IRecipeHandler; + +import java.util.*; + +/** + * @author vfyjxf + */ +public class ICRecipeProcessor implements IRecipeProcessor { + @Override + public Set getAllOverlayIdentifier() { + return new HashSet<>(Arrays.asList( + "blastfurnace", "BlockCutter", "centrifuge", "compressor", "extractor", "fluidcanner", "macerator", + "metalformer", "oreWashing", "solidcanner" + )); + } + + @Override + public List getRecipeInput(IRecipeHandler recipe, int recipeIndex, String identifier) { + for (String ident : getAllOverlayIdentifier()) { + if (identifier.equals(ident)) { + return new ArrayList<>(recipe.getIngredientStacks(recipeIndex)); + } + } + return null; + } + + @Override + public List getRecipeOutput(IRecipeHandler recipe, int recipeIndex, String identifier) { + for (String ident : getAllOverlayIdentifier()) { + if (identifier.equals(ident)) { + List recipeOutputs = new ArrayList<>(); + recipeOutputs.add(recipe.getResultStack(recipeIndex)); + recipeOutputs.addAll(recipe.getOtherStacks(recipeIndex)); + return recipeOutputs; + } + } + return null; + } + + +} diff --git a/src/main/java/com/github/vfyjxf/nee/processor/IRecipeProcessor.java b/src/main/java/com/github/vfyjxf/nee/processor/IRecipeProcessor.java new file mode 100644 index 0000000..51e4ce2 --- /dev/null +++ b/src/main/java/com/github/vfyjxf/nee/processor/IRecipeProcessor.java @@ -0,0 +1,25 @@ +package com.github.vfyjxf.nee.processor; + +import codechicken.nei.PositionedStack; +import codechicken.nei.recipe.IRecipeHandler; +import com.github.vfyjxf.nee.network.packet.PacketNEIPatternRecipe; + +import java.util.Collections; +import java.util.List; +import java.util.Set; + +/** + * @author vfyjxf + */ +public interface IRecipeProcessor { + + + default Set getAllOverlayIdentifier(){ + return Collections.emptySet(); + } + + List getRecipeInput(IRecipeHandler recipe, int recipeIndex, String identifier); + + List getRecipeOutput(IRecipeHandler recipe, int recipeIndex, String identifier); + +} diff --git a/src/main/java/com/github/vfyjxf/nee/processor/RecipeProcessor.java b/src/main/java/com/github/vfyjxf/nee/processor/RecipeProcessor.java new file mode 100644 index 0000000..2176695 --- /dev/null +++ b/src/main/java/com/github/vfyjxf/nee/processor/RecipeProcessor.java @@ -0,0 +1,31 @@ +package com.github.vfyjxf.nee.processor; + +import com.github.vfyjxf.nee.NotEnoughEnergistics; +import cpw.mods.fml.common.Loader; + +import java.util.ArrayList; +import java.util.List; + +public class RecipeProcessor { + public static List recipeProcessors = new ArrayList<>(); + + public static void init(){ + NotEnoughEnergistics.logger.info("-----Not Enough Energistics Init Start-----"); + NotEnoughEnergistics.logger.info("Install Vanilla Support"); + recipeProcessors.add(new VanillaRecipeProcessor()); + if(Loader.isModLoaded("gregtech")){ + NotEnoughEnergistics.logger.info("Found GregTech,install GregTech Support"); + recipeProcessors.add(new GregTechRecipeProcessor()); + } + if(Loader.isModLoaded("IC2")){ + NotEnoughEnergistics.logger.info("Found IC2,install IC2 Support"); + recipeProcessors.add(new ICRecipeProcessor()); + } + if(Loader.isModLoaded("Avaritia")){ + NotEnoughEnergistics.logger.info("Found Avaritia, install Avaritia Support"); + recipeProcessors.add(new AvaritiaRecipeProcessor()); + } + NotEnoughEnergistics.logger.info("-----Not Enough Energistics Init Finished-----"); + } + +} diff --git a/src/main/java/com/github/vfyjxf/nee/processor/VanillaRecipeProcessor.java b/src/main/java/com/github/vfyjxf/nee/processor/VanillaRecipeProcessor.java new file mode 100644 index 0000000..3f11409 --- /dev/null +++ b/src/main/java/com/github/vfyjxf/nee/processor/VanillaRecipeProcessor.java @@ -0,0 +1,38 @@ +package com.github.vfyjxf.nee.processor; + +import codechicken.nei.PositionedStack; +import codechicken.nei.recipe.IRecipeHandler; + +import java.util.*; + +/** + * @author vfyjxf + */ +public class VanillaRecipeProcessor implements IRecipeProcessor { + @Override + public Set getAllOverlayIdentifier() { + return new HashSet<>(Arrays.asList("brewing", "smelting", "fuel")); + } + + @Override + public List getRecipeInput(IRecipeHandler recipe, int recipeIndex, String identifier) { + List recipeInputs = new ArrayList<>(); + if ("brewing".equals(identifier) || "smelting".equals(identifier) || "fuel".equals(identifier)) { + recipeInputs.addAll(recipe.getIngredientStacks(recipeIndex)); + recipeInputs.addAll(recipe.getOtherStacks(recipeIndex)); + } + return recipeInputs; + } + + @Override + public List getRecipeOutput(IRecipeHandler recipe, int recipeIndex, String identifier) { + if ("brewing".equals(identifier) || "smelting".equals(identifier) || "fuel".equals(identifier)) { + List recipeOutput = new ArrayList<>(); + recipeOutput.add(recipe.getResultStack(recipeIndex)); + return recipeOutput; + } + return null; + } + + +} diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info new file mode 100644 index 0000000..d05eaa7 --- /dev/null +++ b/src/main/resources/mcmod.info @@ -0,0 +1,13 @@ +[{ + "modid": "${mod_id}", + "name": "${mod_name}", + "description": "${mod_description}", + "version": "${mod_version}", + "mcversion": "${mc_version}", + "url": "", + "updateUrl": "", + "authorList": ["${mod_author}"], + "credits": "", + "screenshots": [], + "dependencies": [] +}] \ No newline at end of file