aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java86
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java4
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java3
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DiagCommand.java15
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java2
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalWishingCompassSolver.java2
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/options/customtypes/NEUDebugFlag.java52
7 files changed, 140 insertions, 24 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java
index 5d65d07e..92e2cfd6 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java
@@ -29,6 +29,7 @@ import io.github.moulberry.notenoughupdates.auction.APIManager;
import io.github.moulberry.notenoughupdates.events.RepositoryReloadEvent;
import io.github.moulberry.notenoughupdates.miscgui.GuiItemRecipe;
import io.github.moulberry.notenoughupdates.miscgui.KatSitterOverlay;
+import io.github.moulberry.notenoughupdates.options.customtypes.NEUDebugFlag;
import io.github.moulberry.notenoughupdates.recipes.CraftingOverlay;
import io.github.moulberry.notenoughupdates.recipes.CraftingRecipe;
import io.github.moulberry.notenoughupdates.recipes.Ingredient;
@@ -394,31 +395,94 @@ public class NEUManager {
return getUsagesFor(internalname).stream().filter(NeuRecipe::isAvailable).collect(Collectors.toList());
}
+ private static class DebugMatch {
+ int index;
+ String match;
+
+ DebugMatch(int index, String match) {
+ this.index = index;
+ this.match = match;
+ }
+ }
+
+
+ private String searchDebug(String[] searchArray, ArrayList<DebugMatch> debugMatches) {
+ //splitToSearch, debugMatches and query
+ final String ANSI_RED = "\u001B[31m";
+ final String ANSI_RESET = "\u001B[0m";
+ final String ANSI_YELLOW = "\u001B[33m";
+
+ //create debug message
+ StringBuilder debugBuilder = new StringBuilder();
+ for (int i = 0; i < searchArray.length; i++) {
+ final int fi = i;
+ Object[] matches = debugMatches.stream().filter((d) -> d.index == fi).toArray();
+
+ if (matches.length > 0) {
+ debugBuilder.append(ANSI_YELLOW + "[").append(((DebugMatch) matches[0]).match).append("]");
+ debugBuilder.append(ANSI_RED + "[").append(searchArray[i]).append("]").append(ANSI_RESET).append(" ");
+ } else {
+ debugBuilder.append(searchArray[i]).append(" ");
+ }
+ }
+
+ //yellow = query match and red = string match
+ return debugBuilder.toString();
+ }
+
/**
* Searches a string for a query. This method is used to mimic the behaviour of the more complex map-based search
* function. This method is used for the chest-item-search feature.
*/
public boolean searchString(String toSearch, String query) {
- int lastQueryMatched = -1;
+ final String ANSI_RESET = "\u001B[0m";
+ final String ANSI_YELLOW = "\u001B[33m";
+
+ int lastStringMatch = -1;
+ ArrayList<DebugMatch> debugMatches = new ArrayList<>();
toSearch = clean(toSearch).toLowerCase();
query = clean(query).toLowerCase();
String[] splitToSearch = toSearch.split(" ");
String[] queryArray = query.split(" ");
- out:
- for (int j = 0; j < queryArray.length; j++) {
- for (int i = 0; i < splitToSearch.length; i++) {
- if ((queryArray.length - (lastQueryMatched != -1 ? lastQueryMatched : 0)) > (splitToSearch.length - i)) continue;
- if (splitToSearch[i].startsWith(queryArray[j])) {
- lastQueryMatched = j;
- continue out;
+ {
+ String currentSearch = queryArray[0];
+ int queryIndex = 0;
+ boolean matchedLastQueryItem = false;
+
+ for (int k = 0; k < splitToSearch.length; k++) {
+ if (queryIndex - 1 != -1 && (queryArray.length - queryIndex) > (splitToSearch.length - k)) continue;
+ if (splitToSearch[k].startsWith(currentSearch)) {
+ if (((lastStringMatch != -1 ? lastStringMatch : k-1) == k-1)) {
+ debugMatches.add(new DebugMatch(k, currentSearch));
+ lastStringMatch = k;
+ if (queryIndex+1 != queryArray.length) {
+ queryIndex++;
+ currentSearch = queryArray[queryIndex];
+ } else {
+ matchedLastQueryItem = true;
+ }
+ }
+ } else if (queryIndex != 0) {
+ queryIndex = 0;
+ currentSearch = queryArray[queryIndex];
+ lastStringMatch = -1;
}
}
- return false;
- }
- return true;
+ if (matchedLastQueryItem) {
+ if (NEUDebugFlag.SEARCH.isSet()) {
+ NotEnoughUpdates.LOGGER.info("Found match for \"" + ANSI_YELLOW + query + ANSI_RESET + "\":\n\t" + searchDebug(splitToSearch, debugMatches));
+ }
+ } else {
+ if (NEUDebugFlag.SEARCH.isSet() && lastStringMatch != -1) {
+ NotEnoughUpdates.LOGGER.info("Found partial match for \"" + ANSI_YELLOW + query + ANSI_RESET + "\":\n\t" + searchDebug(splitToSearch, debugMatches));
+ }
+ }
+
+ return matchedLastQueryItem;
+ }
}
/**
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java
index c4b1bd77..b06f2ab2 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java
@@ -99,6 +99,8 @@ import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import java.awt.*;
import java.io.BufferedReader;
@@ -119,6 +121,8 @@ public class NotEnoughUpdates {
public static final int VERSION_ID = 20100;
public static final int PRE_VERSION_ID = 0;
public static final int HOTFIX_VERSION_ID = 0;
+
+ public static final Logger LOGGER = LogManager.getLogger("NotEnoughUpdates");
/**
* Registers the biomes for the crystal hollows here so optifine knows they exists
*/
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java
index 2a5e3305..972557c8 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java
@@ -58,7 +58,8 @@ public class DevTestCommand extends ClientCommandBase {
"lulonaut",
"craftyoldminer",
"eisengolem",
- "whalker"
+ "whalker",
+ "ascynx"
);
private static final String[] DEV_FAIL_STRINGS = {
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DiagCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DiagCommand.java
index 326c00b4..fb546efb 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DiagCommand.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DiagCommand.java
@@ -41,7 +41,8 @@ public class DiagCommand extends ClientCommandBase {
" center=<off | on> Disable / enable using center\n" +
"/neudiag wishing Wishing Compass Solver diagnostics\n" +
"/neudiag debug\n" +
- " <no sub-command> Show current flags\n" +
+ " <no sub-command> Show all enabled flags\n" +
+ " <list> Show all flags\n"+
" <enable | disable> <flag> Enable/disable flag\n";
private void showUsage(ICommandSender sender) {
@@ -86,6 +87,10 @@ public class DiagCommand extends ClientCommandBase {
boolean enablingFlag = true;
String action = args[1];
switch (action) {
+ case "list":
+ sender.addChatMessage(new ChatComponentText(
+ EnumChatFormatting.YELLOW + "Here are all flags:\n" + NEUDebugFlag.getFlagList()));
+ return;
case "disable":
enablingFlag = false;
// falls through
@@ -93,7 +98,7 @@ public class DiagCommand extends ClientCommandBase {
if (args.length != 3) {
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED +
"You must specify a flag:\n" +
- NEUDebugFlag.FLAG_LIST));
+ NEUDebugFlag.getFlagList()));
return;
}
@@ -108,7 +113,7 @@ public class DiagCommand extends ClientCommandBase {
} catch (IllegalArgumentException e) {
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED +
flagName + " is invalid. Valid flags are:\n" +
- NEUDebugFlag.FLAG_LIST));
+ NEUDebugFlag.getFlagList()));
return;
}
break;
@@ -118,8 +123,8 @@ public class DiagCommand extends ClientCommandBase {
}
}
- sender.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + "Effective debug flags: " +
- NotEnoughUpdates.INSTANCE.config.hidden.debugFlags.toString()));
+ sender.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + "Effective debug flags: \n" +
+ NEUDebugFlag.getEnabledFlags()));
break;
default:
showUsage(sender);
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java
index 167b6a2f..ab9345cb 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalMetalDetectorSolver.java
@@ -170,7 +170,7 @@ public class CrystalMetalDetectorSolver {
// falls through
case FOUND:
mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + "[NEU] Found solution."));
- if (NotEnoughUpdates.INSTANCE.config.hidden.debugFlags.contains(NEUDebugFlag.METAL) &&
+ if (NEUDebugFlag.METAL.isSet() &&
(previousState == SolutionState.INVALID || previousState == SolutionState.FAILED)) {
NEUDebugLogger.log(
NEUDebugFlag.METAL,
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalWishingCompassSolver.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalWishingCompassSolver.java
index 19cf9c09..07f19a60 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalWishingCompassSolver.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalWishingCompassSolver.java
@@ -923,7 +923,7 @@ public class CrystalWishingCompassSolver {
return;
}
- boolean wishingDebugFlagSet = NotEnoughUpdates.INSTANCE.config.hidden.debugFlags.contains(NEUDebugFlag.WISHING);
+ boolean wishingDebugFlagSet = NEUDebugFlag.WISHING.isSet();
if (outputAlways || wishingDebugFlagSet) {
NEUDebugLogger.logAlways(getDiagnosticMessage());
}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/customtypes/NEUDebugFlag.java b/src/main/java/io/github/moulberry/notenoughupdates/options/customtypes/NEUDebugFlag.java
index 8e0e4c11..50f459c0 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/options/customtypes/NEUDebugFlag.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/options/customtypes/NEUDebugFlag.java
@@ -19,13 +19,55 @@
package io.github.moulberry.notenoughupdates.options.customtypes;
+import io.github.moulberry.notenoughupdates.util.NEUDebugLogger;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
public enum NEUDebugFlag {
// NOTE: Removing enum values causes gson to remove all debugFlags on load if any removed value is present
- METAL,
- WISHING,
+ METAL("Metal Detector Solver"),
+ WISHING("Wishing Compass Solver"),
+ MAP("Dungeon Map Player Information"),
+ SEARCH("SearchString Matches"),
;
- public static final String FLAG_LIST =
- "METAL - Metal Detector Solver\n" +
- "WISHING - Wishing Compass Solver";
+ private final String description;
+
+ NEUDebugFlag(String description) {
+ this.description = description;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public boolean isSet() {
+ return NEUDebugLogger.isFlagEnabled(this);
+ }
+
+ public static String getFlagList() {
+ return renderFlagInformation(Arrays.asList(values()));
+ }
+
+ public static String getEnabledFlags() {
+ return renderFlagInformation(Arrays.stream(values())
+ .filter(NEUDebugFlag::isSet)
+ .collect(Collectors.toList()));
+ }
+
+ public static String renderFlagInformation(List<NEUDebugFlag> flags) {
+ int maxNameLength = flags.stream()
+ .mapToInt(it -> it.name().length())
+ .max()
+ .orElse(0);
+ return flags.stream()
+ .map(it -> (CharSequence) String.format(
+ "%-" + maxNameLength + "s" + " - %s",
+ it.name(),
+ it.getDescription()
+ ))
+ .collect(Collectors.joining("\n"));
+ }
}