diff --git a/gradle.properties b/gradle.properties index e28913a..cdf20c1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,13 +6,13 @@ 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.11 +mod_version=1.2.13 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_author=vfyjxf mod_description= mod_logo=assets/neenergistics/meta/logo.png mod_credits=Thanks TheRealp455w0rd diff --git a/src/main/java/com/github/vfyjxf/nee/NEECommands.java b/src/main/java/com/github/vfyjxf/nee/NEECommands.java index f1b48db..0d834a2 100644 --- a/src/main/java/com/github/vfyjxf/nee/NEECommands.java +++ b/src/main/java/com/github/vfyjxf/nee/NEECommands.java @@ -1,11 +1,21 @@ package com.github.vfyjxf.nee; +import com.github.vfyjxf.nee.config.NEEConfig; import com.github.vfyjxf.nee.processor.IRecipeProcessor; import com.github.vfyjxf.nee.processor.RecipeProcessor; +import com.github.vfyjxf.nee.utils.ItemUtils; +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import net.minecraft.client.Minecraft; import net.minecraft.command.CommandBase; import net.minecraft.command.ICommandSender; import net.minecraft.command.WrongUsageException; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ChatComponentText; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import static com.github.vfyjxf.nee.NotEnoughEnergistics.logger; @@ -18,27 +28,86 @@ public class NEECommands extends CommandBase { @Override public String getCommandUsage(ICommandSender sender) { - return "use /nee RecipeProcessor to get RecipeProcessor and identifier,see them in log"; + return ""; } @Override public void processCommand(ICommandSender sender, String[] args) { if (args.length != 0) { - if ("RecipeProcessor".equals(args[0])) { + if ("processor".equalsIgnoreCase(args[0])) { for (IRecipeProcessor processor : RecipeProcessor.recipeProcessors) { logger.info("RecipeProcessor:" + processor.getRecipeProcessorId() + " identifier:"); for (String ident : processor.getAllOverlayIdentifier()) { logger.info(ident); } } + } else if ("add".equalsIgnoreCase(args[0]) && args.length > 1) { + if ("blacklist".equals(args[1]) || "priorityItem".equalsIgnoreCase(args[1])) { + ItemStack currentStack = Minecraft.getMinecraft().thePlayer.getCurrentEquippedItem(); + if (currentStack != null) { + String currentItemJsonString = ItemUtils.toItemJsonString(currentStack); + JsonObject itemJsonObject = new JsonParser().parse(currentItemJsonString).getAsJsonObject(); + if (args.length == 3) { + boolean hasRecipeProcessor = ItemUtils.hasRecipeProcessor(args[2]); + boolean hasOverlayIdentifier = ItemUtils.hasOverlayIdentifier(args[2]); + + if (hasRecipeProcessor) { + itemJsonObject.addProperty("recipeProcessor", args[2]); + } else if (!hasOverlayIdentifier) { + sender.addChatMessage(new ChatComponentText("Can't find processor: " + args[2])); + } + + if (hasOverlayIdentifier) { + itemJsonObject.addProperty("identifier", args[2]); + } else if (!hasRecipeProcessor) { + sender.addChatMessage(new ChatComponentText("Can't find identifier: " + args[2])); + } + + } + String newJsonString = new Gson().toJson(itemJsonObject); + String[] oldList = "blacklist".equalsIgnoreCase(args[1]) ? NEEConfig.transformBlacklist : NEEConfig.transformPriorityList; + String key = "blacklist".equalsIgnoreCase(args[1]) ? "transformItemBlacklist" : "transformItemPriorityList"; + List newList = new ArrayList<>(Arrays.asList(oldList)); + for (String currentJsonString : oldList) { + if (currentJsonString.equals(newJsonString)) { + return; + } + } + newList.add(newJsonString); + NEEConfig.config.getCategory("client").get(key).set(newList.toArray(new String[0])); + NEEConfig.config.save(); + NEEConfig.reload(); + } + } else if ("priorityMod".equalsIgnoreCase(args[1]) && args.length == 3) { + String modid = args[2]; + if (!ItemUtils.hasModId(modid)) { + List newList = new ArrayList<>(Arrays.asList(NEEConfig.transformPriorityModList)); + newList.add(modid); + NEEConfig.config.getCategory("client").get("transformPriorityModList").set(newList.toArray(new String[0])); + NEEConfig.config.save(); + } + } + } else if ("reload".equalsIgnoreCase(args[0])) { + NEEConfig.reload(); } - }else { - throw new WrongUsageException("use /nee RecipeProcessor to get RecipeProcessor and identifier,see them in log"); + } else { + throw new WrongUsageException(""); } } @Override public List addTabCompletionOptions(ICommandSender sender, String[] args) { - return CommandBase.getListOfStringsMatchingLastWord(args, "RecipeProcessor"); + return args.length <= 1 ? CommandBase.getListOfStringsMatchingLastWord(args, "reload", "add", "processor") : + args.length == 2 ? CommandBase.getListOfStringsMatchingLastWord(args, "blacklist", "priorityItem", "priorityMod") : null; + } + + @Override + public int getRequiredPermissionLevel() { + return 1; + } + + @Override + public boolean canCommandSenderUseCommand(ICommandSender sender) { + return true; } } diff --git a/src/main/java/com/github/vfyjxf/nee/NEEConfig.java b/src/main/java/com/github/vfyjxf/nee/NEEConfig.java deleted file mode 100644 index cd410c5..0000000 --- a/src/main/java/com/github/vfyjxf/nee/NEEConfig.java +++ /dev/null @@ -1,34 +0,0 @@ -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 String[] transformPriorityModList = 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 the 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/NotEnoughEnergistics.java b/src/main/java/com/github/vfyjxf/nee/NotEnoughEnergistics.java index ad944d4..5a3b045 100644 --- a/src/main/java/com/github/vfyjxf/nee/NotEnoughEnergistics.java +++ b/src/main/java/com/github/vfyjxf/nee/NotEnoughEnergistics.java @@ -2,6 +2,7 @@ package com.github.vfyjxf.nee; import appeng.client.gui.implementations.GuiPatternTerm; import appeng.container.slot.SlotFake; +import com.github.vfyjxf.nee.config.NEEConfig; import com.github.vfyjxf.nee.network.NEENetworkHandler; import com.github.vfyjxf.nee.network.packet.PacketStackCountChange; import com.github.vfyjxf.nee.utils.GuiUtils; @@ -10,13 +11,13 @@ import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; -import cpw.mods.fml.common.event.FMLServerStartingEvent; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.TickEvent; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.inventory.Slot; import net.minecraft.launchwrapper.Launch; +import net.minecraftforge.client.ClientCommandHandler; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.lwjgl.input.Mouse; @@ -28,32 +29,31 @@ import java.io.File; version = NotEnoughEnergistics.VERSION, name = NotEnoughEnergistics.NAME, dependencies = NotEnoughEnergistics.DEPENDENCIES, + guiFactory = NotEnoughEnergistics.GUI_FACTORY, useMetadata = true) 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 String GUI_FACTORY = "com.github.vfyjxf.nee.config.NEEConfigGuiFactory"; public static final Logger logger = LogManager.getLogger("NotEnoughEnergistics"); @EventHandler public void preInit(FMLPreInitializationEvent e) { NEENetworkHandler.init(); NEEConfig.loadConfig(new File(Launch.minecraftHome, "config/NotEnoughEnergistics.cfg")); + FMLCommonHandler.instance().bus().register(new NEEConfig()); } @EventHandler public void init(FMLInitializationEvent event) { if (FMLCommonHandler.instance().getSide().isClient()) { FMLCommonHandler.instance().bus().register(this); + ClientCommandHandler.instance.registerCommand(new NEECommands()); } } - @EventHandler - public void serverStarting(FMLServerStartingEvent event) { - event.registerServerCommand(new NEECommands()); - } - @SubscribeEvent public void onRenderTick(TickEvent.RenderTickEvent event) { if (event.phase == TickEvent.Phase.START) { diff --git a/src/main/java/com/github/vfyjxf/nee/config/NEEConfig.java b/src/main/java/com/github/vfyjxf/nee/config/NEEConfig.java new file mode 100644 index 0000000..0dc407d --- /dev/null +++ b/src/main/java/com/github/vfyjxf/nee/config/NEEConfig.java @@ -0,0 +1,61 @@ +package com.github.vfyjxf.nee.config; + +import com.github.vfyjxf.nee.NotEnoughEnergistics; +import com.github.vfyjxf.nee.utils.ItemUtils; +import cpw.mods.fml.client.event.ConfigChangedEvent; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.common.config.Configuration; + +import java.io.File; + +/** + * @author vfyjxf + */ +public class NEEConfig { + + public static Configuration config; + + 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) { + 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 the 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(); + } + + public static void reload() { + 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 the 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(); + ItemUtils.reloadConfig(); + } + + @SubscribeEvent + public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event) { + if (NotEnoughEnergistics.MODID.equals(event.modID)) { + config.save(); + NEEConfig.reload(); + } + } + +} diff --git a/src/main/java/com/github/vfyjxf/nee/config/NEEConfigGui.java b/src/main/java/com/github/vfyjxf/nee/config/NEEConfigGui.java new file mode 100644 index 0000000..c10505d --- /dev/null +++ b/src/main/java/com/github/vfyjxf/nee/config/NEEConfigGui.java @@ -0,0 +1,24 @@ +package com.github.vfyjxf.nee.config; + +import com.github.vfyjxf.nee.NotEnoughEnergistics; +import cpw.mods.fml.client.config.GuiConfig; +import cpw.mods.fml.client.config.IConfigElement; +import net.minecraft.client.gui.GuiScreen; +import net.minecraftforge.common.config.ConfigElement; + +import java.util.ArrayList; +import java.util.List; + +public class NEEConfigGui extends GuiConfig { + public NEEConfigGui(GuiScreen parentScreen) { + super(parentScreen, getConfigElements(), NotEnoughEnergistics.MODID, false, false, NotEnoughEnergistics.NAME); + } + + private static List getConfigElements() { + List list = new ArrayList<>(); + for (String name : NEEConfig.config.getCategoryNames()) { + list.add(new ConfigElement(NEEConfig.config.getCategory(name))); + } + return list; + } +} diff --git a/src/main/java/com/github/vfyjxf/nee/config/NEEConfigGuiFactory.java b/src/main/java/com/github/vfyjxf/nee/config/NEEConfigGuiFactory.java new file mode 100644 index 0000000..0629ce8 --- /dev/null +++ b/src/main/java/com/github/vfyjxf/nee/config/NEEConfigGuiFactory.java @@ -0,0 +1,29 @@ +package com.github.vfyjxf.nee.config; + +import cpw.mods.fml.client.IModGuiFactory; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiScreen; + +import java.util.Set; + +public class NEEConfigGuiFactory implements IModGuiFactory { + @Override + public void initialize(Minecraft minecraftInstance) { + + } + + @Override + public Class mainConfigGuiClass() { + return NEEConfigGui.class; + } + + @Override + public Set runtimeGuiCategories() { + return null; + } + + @Override + public RuntimeOptionGuiHandler getHandlerFor(RuntimeOptionCategoryElement element) { + return null; + } +} diff --git a/src/main/java/com/github/vfyjxf/nee/utils/GuiUtils.java b/src/main/java/com/github/vfyjxf/nee/utils/GuiUtils.java index 02ed992..4b5c4d0 100644 --- a/src/main/java/com/github/vfyjxf/nee/utils/GuiUtils.java +++ b/src/main/java/com/github/vfyjxf/nee/utils/GuiUtils.java @@ -11,7 +11,6 @@ import cpw.mods.fml.relauncher.ReflectionHelper; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.client.settings.KeyBinding; import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; 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 451a54e..690a984 100644 --- a/src/main/java/com/github/vfyjxf/nee/utils/ItemUtils.java +++ b/src/main/java/com/github/vfyjxf/nee/utils/ItemUtils.java @@ -2,6 +2,8 @@ package com.github.vfyjxf.nee.utils; import codechicken.nei.PositionedStack; import com.github.vfyjxf.nee.NotEnoughEnergistics; +import com.github.vfyjxf.nee.processor.IRecipeProcessor; +import com.github.vfyjxf.nee.processor.RecipeProcessor; import com.google.gson.Gson; import com.google.gson.JsonSyntaxException; import cpw.mods.fml.common.registry.GameRegistry; @@ -14,7 +16,7 @@ import net.minecraft.nbt.NBTTagCompound; import java.util.ArrayList; import java.util.List; -import static com.github.vfyjxf.nee.NEEConfig.*; +import static com.github.vfyjxf.nee.config.NEEConfig.*; public final class ItemUtils { @@ -22,6 +24,11 @@ public final class ItemUtils { public static List transformItemBlacklist = getTransformItemBlacklist(); public static List transformItemPriorityList = getTransformItemPriorityList(); + public static void reloadConfig() { + transformItemBlacklist = getTransformItemBlacklist(); + transformItemPriorityList = getTransformItemPriorityList(); + } + public static List getTransformItemBlacklist() { List transformItemBlacklist = new ArrayList<>(); for (String itemJsonString : transformBlacklist) { @@ -88,6 +95,7 @@ public final class ItemUtils { return transformItemPriorityList; } + public static boolean isPreferItems(ItemStack itemStack, String recipeProcessor, String identifier) { for (StackProcessor processor : ItemUtils.transformItemPriorityList) { ItemStack copyStack = itemStack.copy(); @@ -149,17 +157,53 @@ public final class ItemUtils { return null; } - public static int getIngredientIndex(ItemStack stack, PositionedStack positionedStack){ + public static int getIngredientIndex(ItemStack stack, PositionedStack positionedStack) { ItemStack stackInput = stack.copy(); stackInput.stackSize = 1; - for(int i = 0; i < positionedStack.items.length; i++){ + for (int i = 0; i < positionedStack.items.length; i++) { ItemStack currentStack = positionedStack.items[i].copy(); currentStack.stackSize = 1; - if(ItemStack.areItemStacksEqual(currentStack,stackInput)){ + if (ItemStack.areItemStacksEqual(currentStack, stackInput)) { return i; } } return -1; } + public static String toItemJsonString(ItemStack stack) { + GameRegistry.UniqueIdentifier identifier = GameRegistry.findUniqueIdentifierFor(stack.getItem()); + String nbtString = stack.hasTagCompound() ? ",\"nbt\":" + stack.getTagCompound().toString() : ""; + int meta = stack.getItemDamage(); + return "{" + "\"modid\":" + identifier.modId + "," + "\"name\":" + identifier.name + "," + "\"meta\":" + meta + nbtString + "}"; + } + + public static boolean hasRecipeProcessor(String processorId) { + for (IRecipeProcessor processor : RecipeProcessor.recipeProcessors) { + if (processor.getRecipeProcessorId().equals(processorId)) { + return true; + } + } + return false; + } + + public static boolean hasOverlayIdentifier(String identifier) { + for (IRecipeProcessor processor : RecipeProcessor.recipeProcessors) { + for (String ident : processor.getAllOverlayIdentifier()) { + if (ident.equals(identifier)) { + return true; + } + } + } + return false; + } + + public static boolean hasModId(String modid) { + for (String currentId : transformPriorityModList) { + if (currentId.equals(modid)) { + return true; + } + } + return false; + } + } diff --git a/src/main/resources/pack.mcmeta b/src/main/resources/pack.mcmeta new file mode 100644 index 0000000..f3fefbc --- /dev/null +++ b/src/main/resources/pack.mcmeta @@ -0,0 +1,6 @@ +{ + "pack": { + "pack_format": 1, + "description": "" + } +}