mirror of
https://github.com/GTNewHorizons/NotEnoughEnergistics.git
synced 2026-11-18 11:19:11 +00:00
Add config
Add item blacklist and item priority list
This commit is contained in:
1 parent
0a297333c7
commit
23da96e1aa
21 files changed
+362
-66
No files matched your search
@@ -0,0 +1,44 @@
|
||||
package com.github.vfyjxf.nee;
|
||||
|
||||
import com.github.vfyjxf.nee.processor.IRecipeProcessor;
|
||||
import com.github.vfyjxf.nee.processor.RecipeProcessor;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.command.WrongUsageException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.github.vfyjxf.nee.NotEnoughEnergistics.logger;
|
||||
|
||||
public class NEECommands extends CommandBase {
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "nee";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender sender) {
|
||||
return "use /nee RecipeProcessor to get RecipeProcessor and identifier,see them in log";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender sender, String[] args) {
|
||||
if (args.length != 0) {
|
||||
if ("RecipeProcessor".equals(args[0])) {
|
||||
for (IRecipeProcessor processor : RecipeProcessor.recipeProcessors) {
|
||||
logger.info("RecipeProcessor:" + processor.getRecipeProcessorId() + " identifier:");
|
||||
for (String ident : processor.getAllOverlayIdentifier()) {
|
||||
logger.info(ident);
|
||||
}
|
||||
}
|
||||
}
|
||||
}else {
|
||||
throw new WrongUsageException("use /nee RecipeProcessor to get RecipeProcessor and identifier,see them in log");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List addTabCompletionOptions(ICommandSender sender, String[] args) {
|
||||
return CommandBase.getListOfStringsMatchingLastWord(args, "RecipeProcessor");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.github.vfyjxf.nee;
|
||||
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author vfyjxf
|
||||
*/
|
||||
public class NEEConfig {
|
||||
|
||||
|
||||
public static String[] transformBlacklist = new String[0];
|
||||
public static String[] transformPriorityList = new String[0];
|
||||
|
||||
public static void loadConfig(File configFile) {
|
||||
Configuration 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 tne priority list, it will be transferred first.").getStringList();
|
||||
if (config.hasChanged()) config.save();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -74,7 +74,7 @@ public class NEINeeConfig implements IConfigureNEI {
|
||||
return;
|
||||
}
|
||||
identifiers.remove("crafting");
|
||||
identifiers.remove( "crafting2x2");
|
||||
identifiers.remove("crafting2x2");
|
||||
//PatternTermEx Support
|
||||
for (String ident : identifiers) {
|
||||
API.registerGuiOverlay(GuiPatternTermEx.class, ident);
|
||||
|
||||
@@ -3,11 +3,19 @@ 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 cpw.mods.fml.common.event.FMLServerStartingEvent;
|
||||
import net.minecraft.launchwrapper.Launch;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@Mod(modid = NotEnoughEnergistics.MODID, version = NotEnoughEnergistics.VERSION, name = NotEnoughEnergistics.NAME, dependencies = NotEnoughEnergistics.DEPENDENCIES)
|
||||
|
||||
@Mod(modid = NotEnoughEnergistics.MODID,
|
||||
version = NotEnoughEnergistics.VERSION,
|
||||
name = NotEnoughEnergistics.NAME,
|
||||
dependencies = NotEnoughEnergistics.DEPENDENCIES,
|
||||
useMetadata = true)
|
||||
public class NotEnoughEnergistics {
|
||||
public static final String MODID = "neenergistics";
|
||||
public static final String NAME = "NotEnoughEnergistics";
|
||||
@@ -18,5 +26,12 @@ public class NotEnoughEnergistics {
|
||||
@Mod.EventHandler
|
||||
public void preInit(FMLPreInitializationEvent e) {
|
||||
NEENetworkHandler.init();
|
||||
NEEConfig.loadConfig(new File(Launch.minecraftHome, "config/NotEnoughEnergistics.cfg"));
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
private void serverStarting(FMLServerStartingEvent event) {
|
||||
event.registerServerCommand(new NEECommands());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import com.github.vfyjxf.nee.network.packet.PacketArcaneRecipe;
|
||||
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;
|
||||
@@ -53,7 +54,7 @@ public class NEECraftingHandler implements IOverlayHandler {
|
||||
for (IRecipeProcessor processor : RecipeProcessor.recipeProcessors) {
|
||||
List<PositionedStack> inputs = processor.getRecipeInput(recipe, recipeIndex, identifier);
|
||||
List<PositionedStack> outputs = processor.getRecipeOutput(recipe, recipeIndex, identifier);
|
||||
|
||||
String recipeProcessorId = processor.getRecipeProcessorId();
|
||||
List<PositionedStack> tInputs = new ArrayList<>();
|
||||
|
||||
if (inputs != null && outputs != null) {
|
||||
@@ -76,11 +77,14 @@ public class NEECraftingHandler implements IOverlayHandler {
|
||||
for (PositionedStack positionedStack : tInputs) {
|
||||
ItemStack currentStack = positionedStack.items[0];
|
||||
for (ItemStack stack : positionedStack.items) {
|
||||
if (Platform.isRecipePrioritized(stack)) {
|
||||
if (Platform.isRecipePrioritized(stack) || ItemUtils.isPreferItems(stack, recipeProcessorId, identifier)) {
|
||||
currentStack = stack.copy();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ItemUtils.isInBlackList(currentStack, recipeProcessorId, identifier)) {
|
||||
continue;
|
||||
}
|
||||
recipeInputs.setTag("#" + inputIndex, currentStack.writeToNBT(new NBTTagCompound()));
|
||||
inputIndex++;
|
||||
}
|
||||
@@ -94,7 +98,6 @@ public class NEECraftingHandler implements IOverlayHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new PacketNEIPatternRecipe(recipeInputs, recipeOutputs);
|
||||
}
|
||||
|
||||
@@ -109,7 +112,7 @@ public class NEECraftingHandler implements IOverlayHandler {
|
||||
final ItemStack[] currentStackList = positionedStack.items;
|
||||
ItemStack stack = positionedStack.items[0];
|
||||
for (ItemStack currentStack : currentStackList) {
|
||||
if (Platform.isRecipePrioritized(currentStack)) {
|
||||
if (Platform.isRecipePrioritized(currentStack) || ItemUtils.isPreferItems(currentStack)) {
|
||||
stack = currentStack.copy();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,11 @@ public class AvaritiaRecipeProcessor implements IRecipeProcessor {
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipeProcessorId() {
|
||||
return "Avaritia";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PositionedStack> getRecipeInput(IRecipeHandler recipe, int recipeIndex, String identifier) {
|
||||
for (String ident : getAllOverlayIdentifier()) {
|
||||
|
||||
@@ -15,6 +15,11 @@ public class EnderIORecipeProcessor implements IRecipeProcessor {
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipeProcessorId() {
|
||||
return "EnderIO";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PositionedStack> getRecipeInput(IRecipeHandler recipe, int recipeIndex, String identifier) {
|
||||
for (String ident : getAllOverlayIdentifier()) {
|
||||
|
||||
@@ -10,6 +10,11 @@ import java.util.List;
|
||||
|
||||
public class ForestryRecipeProcessor implements IRecipeProcessor {
|
||||
|
||||
@Override
|
||||
public String getRecipeProcessorId() {
|
||||
return "Forestry";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PositionedStack> getRecipeInput(IRecipeHandler recipe, int recipeIndex, String identifier) {
|
||||
if (recipe instanceof NEIHandlerBottler) {
|
||||
|
||||
@@ -49,6 +49,11 @@ public class GregTechRecipeProcessor implements IRecipeProcessor {
|
||||
return identifiers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipeProcessorId() {
|
||||
return "GregTech5";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PositionedStack> getRecipeInput(IRecipeHandler recipe, int recipeIndex, String identifier) {
|
||||
|
||||
|
||||
@@ -18,6 +18,11 @@ public class ICRecipeProcessor implements IRecipeProcessor {
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipeProcessorId() {
|
||||
return "IC2";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PositionedStack> getRecipeInput(IRecipeHandler recipe, int recipeIndex, String identifier) {
|
||||
for (String ident : getAllOverlayIdentifier()) {
|
||||
|
||||
@@ -18,6 +18,8 @@ public interface IRecipeProcessor {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
String getRecipeProcessorId();
|
||||
|
||||
List<PositionedStack> getRecipeInput(IRecipeHandler recipe, int recipeIndex, String identifier);
|
||||
|
||||
List<PositionedStack> getRecipeOutput(IRecipeHandler recipe, int recipeIndex, String identifier);
|
||||
|
||||
@@ -19,6 +19,11 @@ public class TCNEIPluginRecipeProcessor implements IRecipeProcessor{
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipeProcessorId() {
|
||||
return "TCNEIPlugin";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PositionedStack> getRecipeInput(IRecipeHandler recipe, int recipeIndex, String identifier) {
|
||||
for(String ident : getAllOverlayIdentifier()){
|
||||
|
||||
@@ -14,6 +14,11 @@ public class VanillaRecipeProcessor implements IRecipeProcessor {
|
||||
return new HashSet<>(Arrays.asList("brewing", "smelting", "fuel"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipeProcessorId() {
|
||||
return "Vanilla";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PositionedStack> getRecipeInput(IRecipeHandler recipe, int recipeIndex, String identifier) {
|
||||
List<PositionedStack> recipeInputs = new ArrayList<>();
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
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;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.JsonToNBT;
|
||||
import net.minecraft.nbt.NBTException;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class ItemUtils {
|
||||
|
||||
public static Gson gson = new Gson();
|
||||
|
||||
public static List<StackProcessor> getTransformItemBlacklist() {
|
||||
List<StackProcessor> transformItemBlacklist = new ArrayList<>();
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return transformItemBlacklist;
|
||||
}
|
||||
|
||||
public static List<StackProcessor> getTransformItemPriorityList() {
|
||||
List<StackProcessor> transformItemPriorityList = new ArrayList<>();
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return transformItemPriorityList;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isPreferItems(ItemStack 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 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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.github.vfyjxf.nee.utils;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class StackProcessor {
|
||||
public String modid;
|
||||
public String name;
|
||||
public String meta;
|
||||
public String nbt;
|
||||
public ItemStack itemStack;
|
||||
public Item item;
|
||||
public String recipeProcessor;
|
||||
public String identifier;
|
||||
|
||||
public StackProcessor(String modid, String name, String meta, String nbt){
|
||||
this.modid = modid;
|
||||
this.name = name;
|
||||
this.meta = meta;
|
||||
this.nbt = nbt;
|
||||
}
|
||||
public StackProcessor(String modid, String name, String meta){
|
||||
this.modid = modid;
|
||||
this.name = name;
|
||||
this.meta = meta;
|
||||
}
|
||||
public StackProcessor(String modid, String name){
|
||||
this.modid = modid;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public StackProcessor(ItemStack itemStack, Item item, String recipeProcessor, String identifier){
|
||||
this.itemStack = itemStack;
|
||||
this.item = item;
|
||||
this.recipeProcessor = recipeProcessor;
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user