From ae0e23eac5f09860a80e28d24c64be86634ee8e0 Mon Sep 17 00:00:00 2001 From: vfyjxf <2331007009@qq.com> Date: Tue, 17 Aug 2021 00:28:52 +0800 Subject: [PATCH] add mod priority list --- README.md | 3 ++- READNE_CN.md | 2 ++ gradle.properties | 2 +- .../java/com/github/vfyjxf/nee/NEEConfig.java | 5 +++++ .../vfyjxf/nee/nei/NEECraftingHandler.java | 21 ++++++++++++++++--- .../github/vfyjxf/nee/utils/ItemUtils.java | 16 +++++++++++--- 6 files changed, 41 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index e29697a..37c6dbd 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,8 @@ This mod removes that functionality and allows the player to use NEI's transfer - 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 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 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 it's the mod's item,it will be use first. ## Compatible Modslist as followed: diff --git a/READNE_CN.md b/READNE_CN.md index c4d1613..427518b 100644 --- a/READNE_CN.md +++ b/READNE_CN.md @@ -12,6 +12,8 @@ NotEnoughEnergistics 是[Just Enough Energistics](https://www.curseforge.com/min - 在处理模式中合并同类物品 - 支持增广样板终端(16 -> 4模式) - 允许你设置转换黑名单和转换优先名单,如对应物品在里面,那么他们将不会被转移/优先被转移 +- 允许你设置mod优先级列表,优先使用该mod的物品 + ## 当前支持的Mod列表: - [ ] AppliedEnergistics2(我们将不会支持AE2,因为AE2没有注册对应的OverlayHandler) diff --git a/gradle.properties b/gradle.properties index 4e6fb7a..4173fd6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ org.gradle.daemon=false mc_version=1.7.10 nei_version=2.1.6-GTNH ae2_version=rv3-beta-52-GTNH -mod_version=1.2.3 +mod_version=1.2.4 forge_version=10.13.4.1614 mod_group=com.github.vfyjxf.neenergistics mod_id=neenergistics diff --git a/src/main/java/com/github/vfyjxf/nee/NEEConfig.java b/src/main/java/com/github/vfyjxf/nee/NEEConfig.java index aae1ffc..fb93b72 100644 --- a/src/main/java/com/github/vfyjxf/nee/NEEConfig.java +++ b/src/main/java/com/github/vfyjxf/nee/NEEConfig.java @@ -12,6 +12,7 @@ public class NEEConfig { public static String[] transformBlacklist = new String[0]; public static String[] transformPriorityList = new String[0]; + public static String[] transformPriorityModList = new String[0]; public static void loadConfig(File configFile) { Configuration config = new Configuration(configFile); @@ -23,6 +24,10 @@ public static void loadConfig(File configFile) { "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(); + + 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/nei/NEECraftingHandler.java b/src/main/java/com/github/vfyjxf/nee/nei/NEECraftingHandler.java index 6142dd2..8949d42 100644 --- a/src/main/java/com/github/vfyjxf/nee/nei/NEECraftingHandler.java +++ b/src/main/java/com/github/vfyjxf/nee/nei/NEECraftingHandler.java @@ -75,7 +75,14 @@ private PacketNEIPatternRecipe packProcessRecipe(IRecipeHandler recipe, int reci } for (PositionedStack positionedStack : tInputs) { - ItemStack currentStack = positionedStack.items[0]; + ItemStack currentStack = positionedStack.item; + currentStack.stackSize = positionedStack.items[0].stackSize; + + ItemStack preferModItem = ItemUtils.getPreferModItem(positionedStack.items); + if (preferModItem != null) { + currentStack = preferModItem; + } + for (ItemStack stack : positionedStack.items) { if (Platform.isRecipePrioritized(stack) || ItemUtils.isPreferItems(stack, recipeProcessorId, identifier)) { currentStack = stack.copy(); @@ -112,11 +119,18 @@ private PacketNEIPatternRecipe packCraftingTableRecipe(IRecipeHandler recipe, in 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())); } } @@ -146,8 +160,9 @@ private PacketArcaneRecipe packetArcaneRecipe(IRecipeHandler recipe, int recipeI itemAspectClz = iA; final NBTTagCompound recipeInputs = new NBTTagCompound(); List ingredients = recipe.getIngredientStacks(recipeIndex); - ingredients.removeIf(positionedStack -> itemAspectClz.isInstance(positionedStack.item.getItem())); - + if (itemAspectClz != null) { + ingredients.removeIf(positionedStack -> itemAspectClz.isInstance(positionedStack.item.getItem())); + } for (PositionedStack positionedStack : ingredients) { if (positionedStack.items != null && positionedStack.items.length > 0) { 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 9ee4835..d4401b8 100644 --- a/src/main/java/com/github/vfyjxf/nee/utils/ItemUtils.java +++ b/src/main/java/com/github/vfyjxf/nee/utils/ItemUtils.java @@ -1,8 +1,5 @@ package com.github.vfyjxf.nee.utils; -import static com.github.vfyjxf.nee.NEEConfig.transformBlacklist; -import static com.github.vfyjxf.nee.NEEConfig.transformPriorityList; - import com.github.vfyjxf.nee.NotEnoughEnergistics; import com.google.gson.Gson; import cpw.mods.fml.common.registry.GameRegistry; @@ -16,6 +13,8 @@ import java.util.ArrayList; import java.util.List; +import static com.github.vfyjxf.nee.NEEConfig.*; + public final class ItemUtils { public static Gson gson = new Gson(); @@ -124,4 +123,15 @@ public static boolean isInBlackList(ItemStack itemStack, String recipeProcessor, return false; } + public static ItemStack getPreferModItem(ItemStack[] items) { + for (String currentId : transformPriorityModList) { + for(ItemStack stack : items){ + GameRegistry.UniqueIdentifier itemId = GameRegistry.findUniqueIdentifierFor(stack.getItem()); + if(currentId.equals(itemId.modId)){ + return stack; + } + } + } + return null; + } }