Skip to content

Commit

Permalink
add mod priority list
Browse files Browse the repository at this point in the history
  • Loading branch information
vfyjxf committed Aug 16, 2021
1 parent 807e8cb commit ae0e23e
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 8 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
2 changes: 2 additions & 0 deletions READNE_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ NotEnoughEnergistics 是[Just Enough Energistics](https://www.curseforge.com/min
- 在处理模式中合并同类物品
- 支持增广样板终端(16 -> 4模式)
- 允许你设置转换黑名单和转换优先名单,如对应物品在里面,那么他们将不会被转移/优先被转移
- 允许你设置mod优先级列表,优先使用该mod的物品

## 当前支持的Mod列表:

- [ ] AppliedEnergistics2(我们将不会支持AE2,因为AE2没有注册对应的OverlayHandler)
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/github/vfyjxf/nee/NEEConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
}

Expand Down
21 changes: 18 additions & 3 deletions src/main/java/com/github/vfyjxf/nee/nei/NEECraftingHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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()));
}
}
Expand Down Expand Up @@ -146,8 +160,9 @@ private PacketArcaneRecipe packetArcaneRecipe(IRecipeHandler recipe, int recipeI
itemAspectClz = iA;
final NBTTagCompound recipeInputs = new NBTTagCompound();
List<PositionedStack> 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) {
Expand Down
16 changes: 13 additions & 3 deletions src/main/java/com/github/vfyjxf/nee/utils/ItemUtils.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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;
}
}

0 comments on commit ae0e23e

Please sign in to comment.