diff --git a/README.md b/README.md index 39c115d..4c3be58 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,49 @@ [中文](READNE_CN.md) # Not Enough Energistics -NotEnoughEnergistics-1.12.2 is an improved version of [Just Enough Energistics](https://www.curseforge.com/minecraft/mc-mods/just-enough-energistics-jee) +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 JEI integration for the Pattern Terminal. +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 JEI's transfer system (click [+] button) to create patterns whether the player possesses the items required by the recipe. +This mod removes that functionality and allows the player to use NEI's transfer system (shift + click [?] button) to create patterns whether the player possesses the items required by the recipe. ## Features - Automatically switch the mode of PatternTerminal. +- If an item is a probability output, then nee will not transfer it. - Combine like stacks in processing patterns. - Support Processing Pattern Terminal(16 -> 4 mode). -- Allow you to add item blackList and item priority list, if item in them, it will not be transferred / transfer it first. +- Allow you to add item blackList and item priority list, if item in them, it will not be transferred / transfer it first.(use /nee RecipeProcessor to get RecipeProcessor and identifier in log) - Allow you to add mod priority list,if the mod's has this item,it will be use first. +## Compatible Modslist as followed: + +- [ ] AppliedEnergistics2(Won't support it because AE2 doesn't register OverlayHandler) +- [x] Vanilla +- [x] GregTech5 +- [x] GregTech6 +- [x] IndustrialCraft2 +- [x] Avaritia +- [x] EnderIO +- [x] Forestry(Doesn't support Fermenter and Still,because they don't have an item output) +- [x] Thaumcraft NEI Plugin +- [x] Thaumic Energistics(Allows you to transfer ArcaneRecipe from NEI to Knowledge Inscriber, it requires Thaumcraft NEI Plugin) +- [x] ThermalExpansion +- [x] ImmersiveEngineering +- [x] Mekanism +- [x] BloodMagic +- [x] BuildCraft +- [x] Avaritiaddons(auto extreme crafting table support) +If you want other Mod support,see [RecipeProcessor](./src/main/java/com/github/vfyjxf/nee/processor/RecipeProcessor.java) and [Mod support Issue](https://github.com/vfyjxf/NotEnoughEnergistics/issues/1) + +## TODO + +- [x] Add item blackList ,if item in the blacklist, it will not be transferred. +- [x] Add item priority list, if item in tne priority list, it will be transferred first. +- [x] Combine like stacks in processing patterns. + ## Credits Thanks TheRealp455w0rd and his [Just Enough Energistics](https://www.curseforge.com/minecraft/mc-mods/just-enough-energistics-jee) diff --git a/READNE_CN.md b/READNE_CN.md index aa742bd..2aef09c 100644 --- a/READNE_CN.md +++ b/READNE_CN.md @@ -1,18 +1,45 @@ # Not Enough Energistics -NotEnoughEnergistics 是[Just Enough Energistics](https://www.curseforge.com/minecraft/mc-mods/just-enough-energistics-jee) 的改进版本 +NotEnoughEnergistics 是[Just Enough Energistics](https://www.curseforge.com/minecraft/mc-mods/just-enough-energistics-jee) 的逆向移植版本 -它替换了AE2默认的JEI集成, 默认情况下ae只能识别玩家身上或者网络里的存储物品。 +它替换了AE2默认的NEI集成, 默认情况下ae只能识别玩家身上或者网络里的存储物品。 -本MOD允许你直接从jei获取配方并写入样板终端(shift点击[+]按钮) +本MOD允许你直接从nei获取配方并写入样板终端(shift点击[?]按钮) ## Features - 根据配方自动切换样板终端的模式 +- 如果一个物品输出为概率输出,那么NEE不会将它写入样板终端 - 在处理模式中合并同类物品 - 支持增广样板终端(16 -> 4模式) - 允许你设置转换黑名单和转换优先名单,如对应物品在里面,那么他们将不会被转移/优先被转移 - 允许你设置mod优先级列表,优先使用该mod的物品 +## 当前支持的Mod列表: + +- [ ] AppliedEnergistics2(我们将不会支持AE2,因为AE2没有注册对应的OverlayHandler) +- [x] Vanilla +- [x] GregTech5 +- [x] GregTech6 +- [x] IndustrialCraft2 +- [x] Avaritia +- [x] EnderIO +- [x] Forestry(不支持发酵机和蒸馏器,因为它们没有物品输出) +- [x] Thaumcraft NEI Plugin +- [x] Thaumic Energistics(允许你从NEI转移奥术合成台配方到知识记录仪,需要Thaumcraft NEI Plugin) +- [x] ThermalExpansion +- [x] ImmersiveEngineering +- [x] Mekanism +- [x] BloodMagic +- [x] BuildCraft +- [x] Avaritiaddons(允许你从nei转移终极工作台配方到梦魇工作台) + +如果你想要别的Mod的支持,请看[RecipeProcessor](./src/main/java/com/github/vfyjxf/nee/processor/RecipeProcessor.java) 或者[模组支持处理区](https://github.com/vfyjxf/NotEnoughEnergistics/issues/1) + +## TODO +- [x] 添加转换黑名单,使在黑名单里的物品不会被转移到样板终端 +- [x] 添加优先转换列表,在优先转换列表的物品会替换配方里的同类物品 +- [x] 在有多个同类物品的情况下,合并同类物品 + ## Credits 感谢 TheRealp455w0rd 和他的 [Just Enough Energistics](https://www.curseforge.com/minecraft/mc-mods/just-enough-energistics-jee) diff --git a/gradle.properties b/gradle.properties index b38485a..f4824aa 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,10 +3,11 @@ org.gradle.jvmargs=-Xmx2G -Xms2G org.gradle.daemon=false # General Specifications -mc_version=1.12.2 -jei_version=4.16.1.302 -mod_version=1.0.0 -forge_version=14.23.5.2847 +mc_version=1.7.10 +nei_version=2.1.6-GTNH +ae2_version=rv3-beta-52-GTNH +mod_version=1.2.6 +forge_version=10.13.4.1614 mod_group=com.github.vfyjxf.neenergistics mod_id=neenergistics mod_name=NotEnoughEnergistics diff --git a/libs/Avaritiaddons-1.4b.1-GTNH.jar b/libs/Avaritiaddons-1.4b.1-GTNH.jar new file mode 100644 index 0000000..ff54169 Binary files /dev/null and b/libs/Avaritiaddons-1.4b.1-GTNH.jar differ diff --git a/src/main/java/com/github/vfyjxf/nee/NEEConfig.java b/src/main/java/com/github/vfyjxf/nee/NEEConfig.java index 85193a2..2962b2e 100644 --- a/src/main/java/com/github/vfyjxf/nee/NEEConfig.java +++ b/src/main/java/com/github/vfyjxf/nee/NEEConfig.java @@ -1,30 +1,34 @@ package com.github.vfyjxf.nee; -import net.minecraftforge.common.config.Config; -import net.minecraftforge.common.config.Config.Comment; +import net.minecraftforge.common.config.Configuration; +import java.io.File; /** * @author vfyjxf */ -@Config(modid = "neenergistics", name = "NotEnoughEnergistics", category = "transfer") public class NEEConfig { - @Comment("Automatic switch Pattern Terminal's Mode when click [+].Default:true") - public static boolean allowAutomaticSwitchPatternTerminalMode = true; - @Comment("If true, print current recipe type in log.Default:false") - public static boolean allowPrintRecipeType = false; + public static String[] transformBlacklist = new String[0]; + public static String[] transformPriorityList = new String[0]; + public static String[] transformPriorityModList = new String[0]; - @Comment("If oredict has this mod's item, use it first.") - public static String[] modPriorityList = new String[0]; + public static void loadConfig(File configFile) { + Configuration config = new Configuration(configFile); + config.load(); - @Comment("If item in the blacklist, it will not be transferred.\n" + - "example:{\"itemName\":\"gregtech:meta_item_2\",\"meta\":\"32492\"}") - public static String[] itemBlacklist = new String[0]; + 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 tne priority list, it will be transferred first.").getStringList(); - @Comment("If item in tne priority list, it will be transferred first.\n" + - "example:{\"itemName\":\"gregtech:meta_item_2\",\"meta\":\"32492\"}") - public static String[] itemPriorityList = new String[0]; + transformPriorityModList = config.get("client","transformPriorityModList",new String[0], + "if oredict has this mod's item, use it first").getStringList(); + + if (config.hasChanged()) config.save(); + } } 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..57d5538 --- /dev/null +++ b/src/main/java/com/github/vfyjxf/nee/NEINeeConfig.java @@ -0,0 +1,100 @@ +package com.github.vfyjxf.nee; + +import appeng.client.gui.implementations.GuiPatternTerm; +import appeng.client.gui.implementations.GuiPatternTermEx; +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 cpw.mods.fml.common.Loader; +import thaumicenergistics.client.gui.GuiKnowledgeInscriber; +import wanion.avaritiaddons.block.extremeautocrafter.GuiExtremeAutoCrafter; + +import java.util.*; + + +public class NEINeeConfig implements IConfigureNEI { + + @Override + public void loadConfig() { + + RecipeProcessor.init(); + + Set defaultIdentifiers = new HashSet<>( + Arrays.asList("crafting", "crafting2x2", "brewing", "smelting", "fuel", null) + ); + Set identifiers = new HashSet<>(defaultIdentifiers); + + 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); + } + + installPatternTerminalExSupport(identifiers); + + installThaumicEnergisticsSupport(); + + installAvaritiaddonsSupport(); + } + + @Override + public String getName() { + return NotEnoughEnergistics.NAME; + } + + @Override + public String getVersion() { + return NotEnoughEnergistics.VERSION; + } + + private void installThaumicEnergisticsSupport() { + try { + Class.forName("thaumicenergistics.client.gui.GuiKnowledgeInscriber"); + } catch (ClassNotFoundException e) { + return; + } + if (Loader.isModLoaded("thaumcraftneiplugin")) { + NotEnoughEnergistics.logger.info("Install ThaumicEnergistics support"); + + API.registerGuiOverlay(GuiKnowledgeInscriber.class, "arcaneshapedrecipes"); + API.registerGuiOverlay(GuiKnowledgeInscriber.class, "arcaneshapelessrecipes"); + API.registerGuiOverlayHandler(GuiKnowledgeInscriber.class, new NEECraftingHandler(), "arcaneshapedrecipes"); + API.registerGuiOverlayHandler(GuiKnowledgeInscriber.class, new NEECraftingHandler(), "arcaneshapelessrecipes"); + + } + } + + private void installPatternTerminalExSupport(Set identifiers) { + try { + Class.forName("appeng.client.gui.implementations.GuiPatternTermEx"); + } catch (ClassNotFoundException e) { + return; + } + identifiers.remove("crafting"); + identifiers.remove("crafting2x2"); + //PatternTermEx Support + for (String ident : identifiers) { + API.registerGuiOverlay(GuiPatternTermEx.class, ident); + API.registerGuiOverlayHandler(GuiPatternTermEx.class, new NEECraftingHandler(), ident); + } + } + + private void installAvaritiaddonsSupport() { + try { + Class.forName("wanion.avaritiaddons.block.extremeautocrafter.GuiExtremeAutoCrafter"); + } catch (ClassNotFoundException e) { + return; + } + if (Loader.isModLoaded("avaritiaddons")) { + NotEnoughEnergistics.logger.info("Install Avaritiaddons support"); + + API.registerGuiOverlay(GuiExtremeAutoCrafter.class, "extreme"); + API.registerGuiOverlayHandler(GuiExtremeAutoCrafter.class, new NEECraftingHandler(), "extreme"); + } + } +} 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..e811cd0 --- /dev/null +++ b/src/main/java/com/github/vfyjxf/nee/nei/NEECraftingHandler.java @@ -0,0 +1,261 @@ +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.PacketArcaneRecipe; +import com.github.vfyjxf.nee.network.packet.PacketExtremeRecipe; +import com.github.vfyjxf.nee.network.packet.PacketNEIPatternRecipe; +import com.github.vfyjxf.nee.processor.IRecipeProcessor; +import com.github.vfyjxf.nee.processor.RecipeProcessor; +import com.github.vfyjxf.nee.utils.ItemUtils; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +import java.util.ArrayList; +import java.util.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 || (hasPatternTermExClz() && firstGui instanceof GuiPatternTermEx)) { + NEENetworkHandler.getInstance().sendToServer(packRecipe(recipe, recipeIndex)); + } else { + knowledgeInscriberHandler(firstGui, recipe, recipeIndex); + extremeAutoCrafterHandler(firstGui, 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); + String recipeProcessorId = processor.getRecipeProcessorId(); + List tInputs = new ArrayList<>(); + + if (inputs != null && outputs != null) { + + for (PositionedStack positionedStack : inputs) { + ItemStack currentStack = positionedStack.items[0]; + boolean find = false; + for (PositionedStack storedStack : tInputs) { + ItemStack StoredStack = storedStack.items[0]; + if (StoredStack.isItemEqual(currentStack) && (StoredStack.stackSize + currentStack.stackSize) <= StoredStack.getMaxStackSize()) { + find = true; + storedStack.items[0].stackSize = StoredStack.stackSize + currentStack.stackSize; + } + } + if (!find) { + tInputs.add(positionedStack); + } + } + for (PositionedStack positionedStack : tInputs) { + ItemStack currentStack = positionedStack.items[0]; + ItemStack preferModItem = ItemUtils.getPreferModItem(positionedStack.items); + + if (preferModItem != null) { + currentStack = preferModItem; + currentStack.stackSize = positionedStack.items[0].stackSize; + } + + for (ItemStack stack : positionedStack.items) { + if (Platform.isRecipePrioritized(stack) || ItemUtils.isPreferItems(stack, recipeProcessorId, identifier)) { + currentStack = stack.copy(); + currentStack.stackSize = positionedStack.items[0].stackSize; + break; + } + } + if (ItemUtils.isInBlackList(currentStack, recipeProcessorId, identifier)) { + continue; + } + recipeInputs.setTag("#" + inputIndex, currentStack.writeToNBT(new NBTTagCompound())); + inputIndex++; + } + + for (PositionedStack positionedStack : outputs) { + if (outputIndex >= 4 || positionedStack == null || 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]; + + ItemStack preferModItem = ItemUtils.getPreferModItem(positionedStack.items); + if (preferModItem != null) { + stack = preferModItem; + } + + for (ItemStack currentStack : currentStackList) { + if (Platform.isRecipePrioritized(currentStack) || ItemUtils.isPreferItems(currentStack)) { + stack = currentStack.copy(); + } + } + + recipeInputs.setTag("#" + slotIndex, stack.writeToNBT(new NBTTagCompound())); + } + } + return new PacketNEIPatternRecipe(recipeInputs, null); + } + + private void knowledgeInscriberHandler(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex) { + Class knowledgeInscriberClz; + try { + knowledgeInscriberClz = Class.forName("thaumicenergistics.client.gui.GuiKnowledgeInscriber"); + } catch (ClassNotFoundException e) { + return; + } + if (knowledgeInscriberClz.isInstance(firstGui)) { + NEENetworkHandler.getInstance().sendToServer(packetArcaneRecipe(recipe, recipeIndex)); + } + } + + private PacketArcaneRecipe packetArcaneRecipe(IRecipeHandler recipe, int recipeIndex) { + final Class itemAspectClz; + Class iA = null; + try { + iA = Class.forName("com.djgiannuzz.thaumcraftneiplugin.items.ItemAspect"); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + itemAspectClz = iA; + final NBTTagCompound recipeInputs = new NBTTagCompound(); + List ingredients = recipe.getIngredientStacks(recipeIndex); + if (itemAspectClz != null) { + ingredients.removeIf(positionedStack -> itemAspectClz.isInstance(positionedStack.item.getItem())); + } + for (PositionedStack positionedStack : ingredients) { + + if (positionedStack.items != null && positionedStack.items.length > 0) { + int slotIndex = getSlotIndex(positionedStack.relx * 100 + positionedStack.rely); + final ItemStack[] currentStackList = positionedStack.items; + ItemStack stack = positionedStack.item; + for (ItemStack currentStack : currentStackList) { + if (Platform.isRecipePrioritized(currentStack)) { + stack = currentStack.copy(); + } + } + recipeInputs.setTag("#" + slotIndex, stack.writeToNBT(new NBTTagCompound())); + } + } + return new PacketArcaneRecipe(recipeInputs); + } + + private void extremeAutoCrafterHandler(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex) { + final Class guiExtremeAutoCrafterClz; + try { + guiExtremeAutoCrafterClz = Class.forName("wanion.avaritiaddons.block.extremeautocrafter.GuiExtremeAutoCrafter"); + } catch (ClassNotFoundException e) { + return; + } + if (guiExtremeAutoCrafterClz.isInstance(firstGui)) { + NEENetworkHandler.getInstance().sendToServer(packetExtremeRecipe(recipe, recipeIndex)); + } + } + + private PacketExtremeRecipe packetExtremeRecipe(IRecipeHandler recipe, int recipeIndex) { + NBTTagCompound recipeInputs = new NBTTagCompound(); + List ingredients = recipe.getIngredientStacks(recipeIndex); + for (PositionedStack positionedStack : ingredients) { + int col = (positionedStack.relx - 3) / 18; + int row = (positionedStack.rely - 3) / 18; + if (positionedStack.rely == 129) { + col = (positionedStack.relx - 2) / 18; + } + int slotIndex = col + row * 9; + ItemStack currentStack = positionedStack.items[0]; + ItemStack preferModItem = ItemUtils.getPreferModItem(positionedStack.items); + if (preferModItem != null) { + currentStack = preferModItem; + } + + for (ItemStack stack : positionedStack.items) { + if (ItemUtils.isPreferItems(stack)) { + currentStack = stack.copy(); + } + } + recipeInputs.setTag("#" + slotIndex, currentStack.writeToNBT(new NBTTagCompound())); + } + return new PacketExtremeRecipe(recipeInputs); + } + + private int getSlotIndex(int xy) { + switch (xy) { + case 7533: + return 1; + case 10333: + return 2; + case 4960: + return 3; + case 7660: + return 4; + case 10360: + return 5; + case 4987: + return 6; + case 7687: + return 7; + case 10387: + return 8; + case 4832: + default: + return 0; + } + } + + private boolean isCraftingTableRecipe(IRecipeHandler recipe) { + TemplateRecipeHandler templateRecipeHandler = (TemplateRecipeHandler) recipe; + String overlayIdentifier = templateRecipeHandler.getOverlayIdentifier(); + return "crafting".equals(overlayIdentifier) || "crafting2x2".equals(overlayIdentifier); + } + + private boolean hasPatternTermExClz() { + try { + Class.forName("appeng.client.gui.implementations.GuiPatternTermEx"); + } catch (ClassNotFoundException ignored) { + return false; + } + + return true; + } +} diff --git a/src/main/java/com/github/vfyjxf/nee/network/NEENetworkHandler.java b/src/main/java/com/github/vfyjxf/nee/network/NEENetworkHandler.java index 14ce4ad..6cd844b 100644 --- a/src/main/java/com/github/vfyjxf/nee/network/NEENetworkHandler.java +++ b/src/main/java/com/github/vfyjxf/nee/network/NEENetworkHandler.java @@ -1,9 +1,11 @@ package com.github.vfyjxf.nee.network; import com.github.vfyjxf.nee.NotEnoughEnergistics; -import com.github.vfyjxf.nee.network.packet.NEERecipeTransferPacket; -import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper; -import net.minecraftforge.fml.relauncher.Side; +import com.github.vfyjxf.nee.network.packet.PacketArcaneRecipe; +import com.github.vfyjxf.nee.network.packet.PacketExtremeRecipe; +import com.github.vfyjxf.nee.network.packet.PacketNEIPatternRecipe; +import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper; +import cpw.mods.fml.relauncher.Side; public class NEENetworkHandler { @@ -14,7 +16,9 @@ public class NEENetworkHandler { } public static void init() { - NEENetworkHandler.getInstance().registerMessage(NEERecipeTransferPacket.class, NEERecipeTransferPacket.class, 0, Side.SERVER); + INSTANCE.registerMessage(PacketNEIPatternRecipe.class, PacketNEIPatternRecipe.class, 0, Side.SERVER); + INSTANCE.registerMessage(PacketArcaneRecipe.class, PacketArcaneRecipe.class, 1, Side.SERVER); + INSTANCE.registerMessage(PacketExtremeRecipe.class, PacketExtremeRecipe.class, 2, Side.SERVER); } } diff --git a/src/main/java/com/github/vfyjxf/nee/network/packet/PacketExtremeRecipe.java b/src/main/java/com/github/vfyjxf/nee/network/packet/PacketExtremeRecipe.java new file mode 100644 index 0000000..bdcd68a --- /dev/null +++ b/src/main/java/com/github/vfyjxf/nee/network/packet/PacketExtremeRecipe.java @@ -0,0 +1,97 @@ +package com.github.vfyjxf.nee.network.packet; + +import cpw.mods.fml.common.network.ByteBufUtils; +import cpw.mods.fml.common.network.simpleimpl.IMessage; +import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; +import cpw.mods.fml.common.network.simpleimpl.MessageContext; +import cpw.mods.fml.relauncher.ReflectionHelper; +import io.netty.buffer.ByteBuf; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import wanion.avaritiaddons.block.extremeautocrafter.ContainerExtremeAutoCrafter; +import wanion.avaritiaddons.block.extremeautocrafter.TileEntityExtremeAutoCrafter; + +import javax.annotation.Nonnull; +import java.lang.reflect.Field; + +/** + * @author vfyjxf + */ +public class PacketExtremeRecipe implements IMessage, IMessageHandler { + + private NBTTagCompound input; + + public PacketExtremeRecipe() { + } + + public PacketExtremeRecipe(@Nonnull NBTTagCompound input) { + this.input = input; + } + + public NBTTagCompound getInput() { + return input; + } + + @Override + public void fromBytes(ByteBuf buf) { + this.input = ByteBufUtils.readTag(buf); + } + + @Override + public void toBytes(ByteBuf buf) { + ByteBufUtils.writeTag(buf, this.input); + } + + @Override + public IMessage onMessage(PacketExtremeRecipe message, MessageContext ctx) { + EntityPlayerMP player = ctx.getServerHandler().playerEntity; + Container container = player.openContainer; + if (container instanceof ContainerExtremeAutoCrafter) { + ItemStack[] recipeInputs = new ItemStack[81]; + NBTTagCompound currentStack; + for (int i = 0; i < recipeInputs.length; i++) { + currentStack = (NBTTagCompound) message.input.getTag("#" + i); + recipeInputs[i] = currentStack == null ? null : ItemStack.loadItemStackFromNBT(currentStack); + } + int inputIndex = 0; + for (int i = 81; i < 162; i++) { + Slot fakeSlot = container.getSlot(i); + ItemStack currentItem = recipeInputs[inputIndex]; + fakeSlot.putStack(currentItem); + inputIndex++; + } + InventoryCrafting craftingMatrix = getCraftingMatrix((ContainerExtremeAutoCrafter) container); + if (craftingMatrix != null) { + container.onCraftMatrixChanged(craftingMatrix); + } + } + return null; + } + + private InventoryCrafting getCraftingMatrix(ContainerExtremeAutoCrafter container) { + Field tileEntityExtremeAutoCrafterField = ReflectionHelper.findField(ContainerExtremeAutoCrafter.class, "tileEntityExtremeAutoCrafter"); + TileEntityExtremeAutoCrafter tileEntityExtremeAutoCrafter = null; + + try { + tileEntityExtremeAutoCrafter = (TileEntityExtremeAutoCrafter) tileEntityExtremeAutoCrafterField.get(container); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + if (tileEntityExtremeAutoCrafter != null) { + Field craftingMatrixField = ReflectionHelper.findField(TileEntityExtremeAutoCrafter.class, "craftingMatrix"); + InventoryCrafting craftingMatrix = null; + try { + craftingMatrix = (InventoryCrafting) craftingMatrixField.get(tileEntityExtremeAutoCrafter); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + return craftingMatrix; + } + return null; + } + +} diff --git a/src/main/java/com/github/vfyjxf/nee/utils/ItemUtils.java b/src/main/java/com/github/vfyjxf/nee/utils/ItemUtils.java index 27d05ee..d93f536 100644 --- a/src/main/java/com/github/vfyjxf/nee/utils/ItemUtils.java +++ b/src/main/java/com/github/vfyjxf/nee/utils/ItemUtils.java @@ -1,73 +1,92 @@ package com.github.vfyjxf.nee.utils; +import com.github.vfyjxf.nee.NotEnoughEnergistics; import com.google.gson.Gson; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import mezz.jei.api.gui.IGuiIngredient; +import cpw.mods.fml.common.registry.GameRegistry; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraftforge.fml.common.registry.GameRegistry; +import net.minecraft.nbt.JsonToNBT; +import net.minecraft.nbt.NBTException; +import net.minecraft.nbt.NBTTagCompound; + import java.util.ArrayList; import java.util.List; import static com.github.vfyjxf.nee.NEEConfig.*; -/** - * @author vfyjxf - */ public final class ItemUtils { public static Gson gson = new Gson(); - private static List getTransformItemBlacklist() { + public static List getTransformItemBlacklist() { List transformItemBlacklist = new ArrayList<>(); - for (String itemJsonString : itemBlacklist) { - JsonObject jsonObject = new JsonParser().parse(itemJsonString).getAsJsonObject(); - if (jsonObject != null) { - String itemName = jsonObject.get("itemName").getAsString(); - if (itemName == null || itemName.isEmpty()) { - continue; + for (String itemJsonString : transformBlacklist) { + StackProcessor processor = gson.fromJson(itemJsonString, StackProcessor.class); + if (processor != null) { + Item currentItem = GameRegistry.findItem(processor.modid, processor.name); + if (currentItem != null) { + ItemStack currentStack = processor.meta != null ? new ItemStack(currentItem, 1, Integer.parseInt(processor.meta)) : new ItemStack(currentItem); + if (processor.nbt != null) { + NBTTagCompound nbt = null; + try { + nbt = (NBTTagCompound) JsonToNBT.func_150315_a(processor.nbt); + } catch (NBTException e) { + e.printStackTrace(); + } + if (nbt != null) { + currentStack.setTagCompound(nbt); + } + } + transformItemBlacklist.add(new StackProcessor(currentStack, currentItem, processor.recipeProcessor, processor.identifier)); } - int meta = itemJsonString.contains("meta") ? Integer.parseInt(jsonObject.get("meta").getAsString()) : 0; - String nbtJsonString = itemJsonString.contains("nbt") ? jsonObject.get("nbt").getAsString() : ""; - ItemStack currentStack = GameRegistry.makeItemStack(itemName, meta, 1, nbtJsonString); - String recipeType = itemJsonString.contains("recipeType") ? jsonObject.get("name").getAsString() : ""; - transformItemBlacklist.add(new StackProcessor(currentStack, recipeType)); } } + return transformItemBlacklist; } - private static List getTransformItemPriorityList() { + public static List getTransformItemPriorityList() { List transformItemPriorityList = new ArrayList<>(); - for (String itemJsonString : itemPriorityList) { - JsonObject jsonObject = new JsonParser().parse(itemJsonString).getAsJsonObject(); - if (jsonObject != null) { - String itemName = jsonObject.get("itemName").getAsString(); - if (itemName == null || itemName.isEmpty()) { - continue; + for (String itemJsonString : transformPriorityList) { + StackProcessor processor = gson.fromJson(itemJsonString, StackProcessor.class); + if (processor != null) { + Item currentItem = GameRegistry.findItem(processor.modid, processor.name); + if (currentItem != null) { + ItemStack currentStack = processor.meta != null ? new ItemStack(currentItem, 1, Integer.parseInt(processor.meta)) : new ItemStack(currentItem); + if (processor.nbt != null) { + NBTTagCompound nbt = null; + try { + nbt = (NBTTagCompound) JsonToNBT.func_150315_a(processor.nbt); + } catch (NBTException e) { + e.printStackTrace(); + } + if (nbt != null) { + currentStack.setTagCompound(nbt); + } + } + transformItemPriorityList.add(new StackProcessor(currentStack, currentItem, processor.recipeProcessor, processor.identifier)); } - int meta = itemJsonString.contains("meta") ? Integer.parseInt(jsonObject.get("meta").getAsString()) : 0; - String nbtJsonString = itemJsonString.contains("nbt") ? jsonObject.get("nbt").getAsString() : ""; - ItemStack currentStack = GameRegistry.makeItemStack(itemName, meta, 1, nbtJsonString); - String recipeType = itemJsonString.contains("recipeType") ? jsonObject.get("name").getAsString() : ""; - transformItemPriorityList.add(new StackProcessor(currentStack, recipeType)); } } + return transformItemPriorityList; } - public static boolean isPreferItems(ItemStack itemStack, String recipeType) { - ItemStack stack = itemStack.copy(); - stack.setCount(1); - for (StackProcessor stackProcessor : getTransformItemPriorityList()) { - if (ItemStack.areItemStacksEqual(stack, stackProcessor.itemStack)) { - String currentRecipeType = stackProcessor.recipeType; - if (currentRecipeType == null || currentRecipeType.isEmpty()) { - return true; - } else if (recipeType.equals(currentRecipeType)) { + + public static boolean isPreferItems(ItemStack itemStack, String recipeProcessor, String identifier) { + for (StackProcessor processor : getTransformItemPriorityList()) { + ItemStack copyStack = itemStack.copy(); + copyStack.stackSize = 1; + if (ItemStack.areItemStacksEqual(copyStack, processor.itemStack)) { + if (processor.recipeProcessor == null && processor.identifier == null) { return true; + } else if (processor.recipeProcessor == null) { + return identifier.equals(processor.identifier); + } else if (processor.identifier == null) { + return recipeProcessor.equals(processor.recipeProcessor); + } else { + return recipeProcessor.equals(processor.recipeProcessor) && identifier.equals(processor.identifier); } } } @@ -75,51 +94,44 @@ public final class ItemUtils { } public static boolean isPreferItems(ItemStack itemStack) { - ItemStack stack = itemStack.copy(); - stack.setCount(1); - for (StackProcessor stackProcessor : getTransformItemPriorityList()) { - if (ItemStack.areItemStacksEqual(stack, stackProcessor.itemStack)) { + for (StackProcessor processor : getTransformItemPriorityList()) { + ItemStack copyStack = itemStack.copy(); + copyStack.stackSize = 1; + if (ItemStack.areItemStacksEqual(copyStack, processor.itemStack)) { return true; } } return false; } - public static boolean isInBlackList(ItemStack itemStack, String recipeType) { - ItemStack stack = itemStack.copy(); - stack.setCount(1); - for (StackProcessor stackProcessor : getTransformItemBlacklist()) { - if (ItemStack.areItemStacksEqual(stack, stackProcessor.itemStack)) { - String currentRecipeType = stackProcessor.recipeType; - if (currentRecipeType == null || currentRecipeType.isEmpty()) { - return true; - } else if (recipeType.equals(currentRecipeType)) { + public static boolean isInBlackList(ItemStack itemStack, String recipeProcessor, String identifier) { + for (StackProcessor processor : getTransformItemBlacklist()) { + ItemStack copyStack = itemStack.copy(); + copyStack.stackSize = 1; + if (ItemStack.areItemStacksEqual(copyStack, processor.itemStack)) { + if (processor.recipeProcessor == null && processor.identifier == null) { return true; + } else if (processor.recipeProcessor == null) { + return identifier.equals(processor.identifier); + } else if (processor.identifier == null) { + return recipeProcessor.equals(processor.recipeProcessor); + } else { + return recipeProcessor.equals(processor.recipeProcessor) && identifier.equals(processor.identifier); } } } return false; } - public static ItemStack getPreferModItem(IGuiIngredient ingredient) { - for (String currentId : modPriorityList) { - for (ItemStack currentIngredient : ingredient.getAllIngredients()) { - String itemModid = currentIngredient.getItem().getRegistryName().getNamespace(); - if (itemModid.equals(currentId)) { - return currentIngredient; + public static ItemStack getPreferModItem(ItemStack[] items) { + for (String currentId : transformPriorityModList) { + for(ItemStack stack : items){ + GameRegistry.UniqueIdentifier itemId = GameRegistry.findUniqueIdentifierFor(stack.getItem()); + if(itemId.modId.equals(currentId)){ + return stack; } } } - return ItemStack.EMPTY; - } - - public static boolean isPreferModItem(ItemStack stack) { - for (String currentId : modPriorityList) { - String itemModid = stack.getItem().getRegistryName().getNamespace(); - if (itemModid.equals(currentId)) { - return true; - } - } - return false; + return null; } }