aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/makamys/neodymium/Neodymium.java4
-rw-r--r--src/main/java/makamys/neodymium/command/ISubCommand.java9
-rw-r--r--src/main/java/makamys/neodymium/command/NeodymiumCommand.java114
-rw-r--r--src/main/java/makamys/neodymium/renderer/NeoRenderer.java3
4 files changed, 128 insertions, 2 deletions
diff --git a/src/main/java/makamys/neodymium/Neodymium.java b/src/main/java/makamys/neodymium/Neodymium.java
index 615d67e..5340550 100644
--- a/src/main/java/makamys/neodymium/Neodymium.java
+++ b/src/main/java/makamys/neodymium/Neodymium.java
@@ -25,6 +25,7 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import makamys.mclib.core.MCLib;
import makamys.mclib.core.MCLibModules;
+import makamys.neodymium.command.NeodymiumCommand;
import makamys.neodymium.config.Config;
import makamys.neodymium.renderer.NeoRenderer;
import makamys.neodymium.util.ChatUtil;
@@ -70,6 +71,7 @@ public class Neodymium
{
FMLCommonHandler.instance().bus().register(this);
MinecraftForge.EVENT_BUS.register(this);
+ NeodymiumCommand.init();
}
@SubscribeEvent
@@ -212,7 +214,7 @@ public class Neodymium
rendererWorld = null;
}
- private static Pair<List<String>, List<String>> checkCompat() {
+ public static Pair<List<String>, List<String>> checkCompat() {
List<String> warns = new ArrayList<>();
List<String> criticalWarns = new ArrayList<>();
diff --git a/src/main/java/makamys/neodymium/command/ISubCommand.java b/src/main/java/makamys/neodymium/command/ISubCommand.java
new file mode 100644
index 0000000..91eccff
--- /dev/null
+++ b/src/main/java/makamys/neodymium/command/ISubCommand.java
@@ -0,0 +1,9 @@
+package makamys.neodymium.command;
+
+import net.minecraft.command.ICommandSender;
+
+public interface ISubCommand {
+
+ void processCommand(ICommandSender sender, String[] args);
+
+}
diff --git a/src/main/java/makamys/neodymium/command/NeodymiumCommand.java b/src/main/java/makamys/neodymium/command/NeodymiumCommand.java
new file mode 100644
index 0000000..e5ccaf0
--- /dev/null
+++ b/src/main/java/makamys/neodymium/command/NeodymiumCommand.java
@@ -0,0 +1,114 @@
+package makamys.neodymium.command;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Consumer;
+
+import org.apache.commons.lang3.tuple.Pair;
+
+import makamys.neodymium.Neodymium;
+import net.minecraft.command.CommandBase;
+import net.minecraft.command.ICommandSender;
+import net.minecraft.command.WrongUsageException;
+import net.minecraft.util.ChatComponentText;
+import net.minecraft.util.EnumChatFormatting;
+import net.minecraftforge.client.ClientCommandHandler;
+
+public class NeodymiumCommand extends CommandBase {
+
+ public static final EnumChatFormatting HELP_COLOR = EnumChatFormatting.BLUE;
+ public static final EnumChatFormatting HELP_USAGE_COLOR = EnumChatFormatting.YELLOW;
+ public static final EnumChatFormatting HELP_WARNING_COLOR = EnumChatFormatting.YELLOW;
+ public static final EnumChatFormatting HELP_EMPHASIS_COLOR = EnumChatFormatting.DARK_AQUA;
+ public static final EnumChatFormatting ERROR_COLOR = EnumChatFormatting.RED;
+
+ private static Map<String, ISubCommand> subCommands = new HashMap<>();
+
+ public static void init() {
+ ClientCommandHandler.instance.registerCommand(new NeodymiumCommand());
+ registerSubCommand("status", new StatusCommand());
+ }
+
+ public static void registerSubCommand(String key, ISubCommand command) {
+ subCommands.put(key, command);
+ }
+
+ @Override
+ public String getCommandName() {
+ return "neodymium";
+ }
+
+ @Override
+ public String getCommandUsage(ICommandSender sender) {
+ return "";
+ }
+
+ public int getRequiredPermissionLevel()
+ {
+ return 0;
+ }
+
+ @Override
+ public void processCommand(ICommandSender sender, String[] args) {
+ if(args.length > 0) {
+ ISubCommand subCommand = subCommands.get(args[0]);
+ if(subCommand != null) {
+ subCommand.processCommand(sender, args);
+ return;
+ }
+ }
+ throw new WrongUsageException(getCommandName() + " <" + String.join("|", subCommands.keySet()) + ">", new Object[0]);
+ }
+
+ public static void addChatMessage(ICommandSender sender, String text) {
+ sender.addChatMessage(new ChatComponentText(text));
+ }
+
+ public static void addColoredChatMessage(ICommandSender sender, String text, EnumChatFormatting color) {
+ addColoredChatMessage(sender, text, color, null);
+ }
+
+ public static void addColoredChatMessage(ICommandSender sender, String text, EnumChatFormatting color, Consumer<ChatComponentText> fixup) {
+ ChatComponentText msg = new ChatComponentText(text);
+ msg.getChatStyle().setColor(color);
+ if(fixup != null) {
+ fixup.accept(msg);
+ }
+ sender.addChatMessage(msg);
+ }
+
+ public List<String> addTabCompletionOptions(ICommandSender sender, String[] args) {
+ return args.length == 1 ? getListOfStringsMatchingLastWord(args, subCommands.keySet().toArray(new String[0])) : null;
+ }
+
+ public static class StatusCommand implements ISubCommand {
+
+ @Override
+ public void processCommand(ICommandSender sender, String[] args) {
+ if(Neodymium.renderer != null) {
+ List<String> text = Neodymium.renderer.getDebugText();
+ addColoredChatMessage(sender, text.get(0), EnumChatFormatting.LIGHT_PURPLE);
+ addChatMessages(sender, text.subList(1, text.size()));
+ }
+ Pair<List<String>, List<String>> allWarns = Neodymium.checkCompat();
+ List<String> warns = allWarns.getLeft();
+ List<String> criticalWarns = allWarns.getRight();
+ for(String line : warns) {
+ addColoredChatMessage(sender, "* " + line, HELP_WARNING_COLOR);
+ }
+ for(String line : criticalWarns) {
+ addColoredChatMessage(sender, "* " + line, ERROR_COLOR);
+ }
+ }
+
+ private static void addChatMessages(ICommandSender sender, Collection<String> messages) {
+ for(String line : messages) {
+ sender.addChatMessage(new ChatComponentText(line));
+ }
+ }
+
+ }
+
+}
diff --git a/src/main/java/makamys/neodymium/renderer/NeoRenderer.java b/src/main/java/makamys/neodymium/renderer/NeoRenderer.java
index d75aa43..0ba82d1 100644
--- a/src/main/java/makamys/neodymium/renderer/NeoRenderer.java
+++ b/src/main/java/makamys/neodymium/renderer/NeoRenderer.java
@@ -609,7 +609,8 @@ public class NeoRenderer {
}
if(hasIncompatibilities) {
text.addAll(Arrays.asList(
- EnumChatFormatting.YELLOW + "(!) Incompatibilities"
+ EnumChatFormatting.YELLOW + "(!) Incompatibilities",
+ EnumChatFormatting.YELLOW + "Type '/neodymium status'"
));
}
return text;