mirror of
https://github.com/GTNewHorizons/NotEnoughEnergistics.git
synced 2026-11-17 10:55:07 +00:00
add more commands
This commit is contained in:
1 parent
76614e44fb
commit
3401c2d802
10 files changed
+250
-52
No files matched your search
@@ -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<String> 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<String> 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;
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<IConfigElement> getConfigElements() {
|
||||
List<IConfigElement> list = new ArrayList<>();
|
||||
for (String name : NEEConfig.config.getCategoryNames()) {
|
||||
list.add(new ConfigElement(NEEConfig.config.getCategory(name)));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
@@ -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<? extends GuiScreen> mainConfigGuiClass() {
|
||||
return NEEConfigGui.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<RuntimeOptionCategoryElement> runtimeGuiCategories() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RuntimeOptionGuiHandler getHandlerFor(RuntimeOptionCategoryElement element) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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<StackProcessor> transformItemBlacklist = getTransformItemBlacklist();
|
||||
public static List<StackProcessor> transformItemPriorityList = getTransformItemPriorityList();
|
||||
|
||||
public static void reloadConfig() {
|
||||
transformItemBlacklist = getTransformItemBlacklist();
|
||||
transformItemPriorityList = getTransformItemPriorityList();
|
||||
}
|
||||
|
||||
public static List<StackProcessor> getTransformItemBlacklist() {
|
||||
List<StackProcessor> 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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user