mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-11-21 20:52:11 +00:00
Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c582b1a82c | ||
|
|
1bb550305c | ||
|
|
6649d28708 | ||
|
|
6b7e465306 | ||
|
|
ab1e8153f5 | ||
|
|
4257235e6e | ||
|
|
1c33a5b7d6 |
No files matched your search
@@ -24,6 +24,7 @@ DASH : '-' ;
|
||||
RECIPE_INGREDIENTS : '<&' | '<' ;
|
||||
RECIPE_RESULT : '>&' | '>' ;
|
||||
RECIPE_OTHERS : '^&' | '^' ;
|
||||
RECIPE_TEXT : '~' ;
|
||||
|
||||
OR : '|' ;
|
||||
LEFT_BRACKET : '{' ;
|
||||
@@ -33,7 +34,7 @@ SPACE : ' ' ;
|
||||
ESCAPED_SYMBOL : '\\' . ;
|
||||
|
||||
PREFIX : CLEAN_SYMBOL {searchParser.hasRedefinedPrefix(getText().charAt(0))}? ;
|
||||
CLEAN_SYMBOL : ~[-<>^{}|/\\ "] ;
|
||||
CLEAN_SYMBOL : ~[-<>^~{}|/\\ "] ;
|
||||
|
||||
mode REGEX;
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ recipeClauseExpression
|
||||
: ingredientsPrefix=RECIPE_INGREDIENTS searchExpression[0, $ingredientsPrefix.getText().length() > 1]
|
||||
| resultPrefix=RECIPE_RESULT searchExpression[1, $resultPrefix.getText().length() > 1]
|
||||
| othersPrefix=RECIPE_OTHERS searchExpression[2, $othersPrefix.getText().length() > 1]
|
||||
| RECIPE_TEXT searchExpression[4, false]
|
||||
| searchExpression[3, false]
|
||||
;
|
||||
|
||||
|
||||
@@ -447,6 +447,7 @@ public class ClientHandler {
|
||||
if (event.world == mc.theWorld) {
|
||||
NEIClientConfig.unloadWorld();
|
||||
ItemMobSpawner.clearEntityReferences();
|
||||
WorldOverlayRenderer.onWorldUnload();
|
||||
RecipeItemInputHandler.instance.clearTooltipCache();
|
||||
RecipeHandlerRef.clearCache();
|
||||
ItemPanels.itemPanel.craftablesPanel.clearGuiReferences();
|
||||
|
||||
@@ -21,6 +21,8 @@ import codechicken.lib.vec.Rectangle4i;
|
||||
import codechicken.nei.api.GuiInfo;
|
||||
import codechicken.nei.api.INEIGuiHandler;
|
||||
import codechicken.nei.guihook.GuiContainerManager;
|
||||
import codechicken.nei.item.ItemNameOverlayMode;
|
||||
import codechicken.nei.item.ItemNameOverlayRenderer;
|
||||
import codechicken.nei.recipe.Recipe.RecipeId;
|
||||
import codechicken.nei.recipe.StackInfo;
|
||||
|
||||
@@ -29,6 +31,8 @@ public abstract class ItemsGrid<T extends ItemsGrid.ItemsGridSlot, M extends Ite
|
||||
protected static class ScreenCapture {
|
||||
|
||||
private long nextCacheRefresh = 0;
|
||||
private ItemNameOverlayMode itemNameOverlayMode;
|
||||
private long itemNameOverlayRevision;
|
||||
private final Framebuffer framebuffer;
|
||||
|
||||
public ScreenCapture() {
|
||||
@@ -45,6 +49,8 @@ public abstract class ItemsGrid<T extends ItemsGrid.ItemsGridSlot, M extends Ite
|
||||
final Minecraft minecraft = Minecraft.getMinecraft();
|
||||
return this.nextCacheRefresh == 0 || this.framebuffer.framebufferWidth != minecraft.displayWidth
|
||||
|| framebuffer.framebufferHeight != minecraft.displayHeight
|
||||
|| this.itemNameOverlayMode != NEIClientConfig.getItemNameOverlayMode()
|
||||
|| this.itemNameOverlayRevision != ItemNameOverlayRenderer.INSTANCE.getCacheRevision()
|
||||
|| getGridRenderingCacheFPS(mode) > 0 && this.nextCacheRefresh < System.currentTimeMillis();
|
||||
}
|
||||
|
||||
@@ -70,6 +76,9 @@ public abstract class ItemsGrid<T extends ItemsGrid.ItemsGridSlot, M extends Ite
|
||||
|
||||
callback.run();
|
||||
|
||||
this.itemNameOverlayMode = NEIClientConfig.getItemNameOverlayMode();
|
||||
this.itemNameOverlayRevision = ItemNameOverlayRenderer.INSTANCE.getCacheRevision();
|
||||
|
||||
GL11.glPopAttrib();
|
||||
|
||||
Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(false);
|
||||
|
||||
@@ -713,6 +713,8 @@ public class LayoutManager implements IContainerInputHandler, IContainerTooltipH
|
||||
|
||||
@Override
|
||||
public void load(GuiContainer gui) {
|
||||
NEIController.load(gui);
|
||||
|
||||
if (isEnabled()) {
|
||||
setInputFocused(null);
|
||||
|
||||
@@ -726,8 +728,6 @@ public class LayoutManager implements IContainerInputHandler, IContainerTooltipH
|
||||
AutoFocusWidget.instance.load(gui);
|
||||
}
|
||||
|
||||
NEIController.load(gui);
|
||||
|
||||
if (checkCreativeInv(gui) && gui.mc.currentScreen instanceof GuiContainerCreative) // override creative with
|
||||
// creative+
|
||||
gui.mc.displayGuiScreen(null); // close the screen and wait for the server to open it for us
|
||||
|
||||
@@ -47,6 +47,7 @@ import codechicken.nei.config.GuiPanelSettings;
|
||||
import codechicken.nei.config.OptionButton;
|
||||
import codechicken.nei.config.OptionCycled;
|
||||
import codechicken.nei.config.OptionExportConfig;
|
||||
import codechicken.nei.config.OptionFloatField;
|
||||
import codechicken.nei.config.OptionGamemodes;
|
||||
import codechicken.nei.config.OptionIntegerField;
|
||||
import codechicken.nei.config.OptionList;
|
||||
@@ -57,6 +58,11 @@ import codechicken.nei.config.OptionToggleButtonBoubs;
|
||||
import codechicken.nei.config.OptionUtilities;
|
||||
import codechicken.nei.config.preset.GuiPresetList;
|
||||
import codechicken.nei.event.NEIConfigsLoadedEvent;
|
||||
import codechicken.nei.item.ItemNameOverlayMode;
|
||||
import codechicken.nei.item.ItemNameOverlayRenderer;
|
||||
import codechicken.nei.item.ItemNameOverlaySettings;
|
||||
import codechicken.nei.moboverlay.MobOverlayScan;
|
||||
import codechicken.nei.moboverlay.MobOverlayStyle;
|
||||
import codechicken.nei.recipe.IRecipeHandler;
|
||||
import codechicken.nei.recipe.InformationHandler;
|
||||
import codechicken.nei.recipe.RecipeCatalysts;
|
||||
@@ -70,6 +76,7 @@ public class NEIClientConfig {
|
||||
private static boolean enabledOverride;
|
||||
private static String worldPath;
|
||||
private static final String CHEAT_MODE_KEY = "cheatmode";
|
||||
private static ItemNameOverlaySettings itemNameOverlaySettings = ItemNameOverlaySettings.defaults();
|
||||
|
||||
public static Logger logger = LogManager.getLogger("NotEnoughItems");
|
||||
public static File configDir = new File(CommonUtils.getMinecraftDir(), "config/NEI/");
|
||||
@@ -420,6 +427,8 @@ public class NEIClientConfig {
|
||||
tag.getTag("inventory.itemIDs").getIntValue(1);
|
||||
API.addOption(new OptionCycled("inventory.itemIDs", 3, true));
|
||||
|
||||
setItemNameOverlayDefaults(tag);
|
||||
|
||||
tag.getTag("world.highlight_tips").getBooleanValue(false);
|
||||
tag.getTag("world.highlight_tips.x").getIntValue(5000);
|
||||
tag.getTag("world.highlight_tips.y").getIntValue(100);
|
||||
@@ -442,6 +451,46 @@ public class NEIClientConfig {
|
||||
tag.getTag("world.overlays.lock").getBooleanValue(true);
|
||||
API.addOption(new OptionToggleButton("world.overlays.lock", true));
|
||||
|
||||
tag.getTag("world.overlays.mobOverlayStyle")
|
||||
.setComment("Mark on each block of the mob spawn overlay: " + MobOverlayStyle.formatAllNames())
|
||||
.getValue(MobOverlayStyle.DEFAULT.formatName());
|
||||
API.addOption(new OptionCycled("world.overlays.mobOverlayStyle", MobOverlayStyle.values().length, true) {
|
||||
|
||||
@Override
|
||||
public int value() {
|
||||
return MobOverlayStyle.parseStyle(getTag().getValue()).ordinal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(int value) {
|
||||
getTag().setValue(MobOverlayStyle.values()[value].formatName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getButtonText() {
|
||||
return translateN(
|
||||
"world.overlays.mobOverlayStyle."
|
||||
+ MobOverlayStyle.parseStyle(getTag().getValue()).formatName());
|
||||
}
|
||||
});
|
||||
|
||||
tag.getTag("world.overlays.mobOverlayRadius")
|
||||
.setComment("Blocks scanned on each side of the player by the mob spawn overlay")
|
||||
.getIntValue(MobOverlayScan.DEFAULT_RADIUS);
|
||||
API.addOption(
|
||||
new OptionIntegerField(
|
||||
"world.overlays.mobOverlayRadius",
|
||||
MobOverlayScan.MIN_RADIUS,
|
||||
MobOverlayScan.MAX_RADIUS));
|
||||
tag.getTag("world.overlays.mobOverlayVerticalRadius")
|
||||
.setComment("Blocks scanned above and below the player by the mob spawn overlay")
|
||||
.getIntValue(MobOverlayScan.DEFAULT_VERTICAL_RADIUS);
|
||||
API.addOption(
|
||||
new OptionIntegerField(
|
||||
"world.overlays.mobOverlayVerticalRadius",
|
||||
MobOverlayScan.MIN_VERTICAL_RADIUS,
|
||||
MobOverlayScan.MAX_VERTICAL_RADIUS));
|
||||
|
||||
tag.getTag("inventory.itempanelScale").getIntValue(100);
|
||||
ItemsPanelGrid.updateScale();
|
||||
API.addOption(new OptionIntegerField("inventory.itempanelScale", 1, 1000) {
|
||||
@@ -549,6 +598,99 @@ public class NEIClientConfig {
|
||||
setDefaultKeyBindings();
|
||||
}
|
||||
|
||||
private static void setItemNameOverlayDefaults(ConfigTagParent tag) {
|
||||
final ConfigTag overlay = tag.getTag("inventory.itemNameOverlay");
|
||||
final int previousMode = overlay.getValue() != null ? overlay.getIntValue(3) : 3;
|
||||
tag.getTag("inventory.itemNameOverlay.mode")
|
||||
.setComment("Icon name labels: 0 = items, 1 = fluids, 2 = all, 3 = off").getIntValue(previousMode);
|
||||
// Move the old scalar value into the new settings page without losing the selection.
|
||||
if (overlay.getValue() != null) {
|
||||
overlay.setValue(null);
|
||||
}
|
||||
API.addOption(new OptionCycled("inventory.itemNameOverlay.mode", 4, true) {
|
||||
|
||||
@Override
|
||||
public void setValue(int value) {
|
||||
super.setValue(value);
|
||||
reloadItemNameOverlaySettings();
|
||||
}
|
||||
});
|
||||
|
||||
addItemNameScaleOption(tag, "fontScale", "Preferred scale for ordinary fonts", 0.5f);
|
||||
addItemNameScaleOption(tag, "unicodeFontScale", "Preferred scale for Unicode text and fonts", 0.5625f);
|
||||
addItemNameScaleOption(tag, "minimumScale", "Minimum scale for fitting a name into its label", 0.3f);
|
||||
addItemNameIntegerOption(tag, "width", "Total label width in icon coordinates", 18, 4, 32);
|
||||
addItemNameIntegerOption(tag, "maxCharacters", "Maximum characters per line; 0 means automatic", 0, 0, 256);
|
||||
addItemNameIntegerOption(tag, "maxLines", "Maximum number of name lines", 2, 1, 4);
|
||||
|
||||
tag.getTag("inventory.itemNameOverlay.outline").setComment("Draw a one-screen-pixel outline around names")
|
||||
.getBooleanValue(true);
|
||||
API.addOption(new OptionToggleButton("inventory.itemNameOverlay.outline", true) {
|
||||
|
||||
@Override
|
||||
public boolean onClick(int button) {
|
||||
final boolean changed = super.onClick(button);
|
||||
reloadItemNameOverlaySettings();
|
||||
return changed;
|
||||
}
|
||||
});
|
||||
reloadItemNameOverlaySettings();
|
||||
}
|
||||
|
||||
private static void addItemNameScaleOption(ConfigTagParent tag, String name, String comment, float defaultValue) {
|
||||
final String path = "inventory.itemNameOverlay." + name;
|
||||
tag.getTag(path).setComment(comment).setDefaultValue(Float.toString(defaultValue));
|
||||
API.addOption(new OptionFloatField(path, 0.1f, 2f) {
|
||||
|
||||
@Override
|
||||
public void onTextChange(String text) {
|
||||
reloadItemNameOverlaySettings();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void addItemNameIntegerOption(ConfigTagParent tag, String name, String comment, int defaultValue,
|
||||
int min, int max) {
|
||||
final String path = "inventory.itemNameOverlay." + name;
|
||||
tag.getTag(path).setComment(comment).getIntValue(defaultValue);
|
||||
API.addOption(new OptionIntegerField(path, min, max) {
|
||||
|
||||
@Override
|
||||
public void onTextChange(String text) {
|
||||
reloadItemNameOverlaySettings();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static float readItemNameScale(String name, float fallback) {
|
||||
try {
|
||||
final float value = Float
|
||||
.parseFloat(getSetting("inventory.itemNameOverlay." + name).getValue(Float.toString(fallback)));
|
||||
return Float.isFinite(value) ? value : fallback;
|
||||
} catch (NumberFormatException ignored) {
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
|
||||
public static void reloadItemNameOverlaySettings() {
|
||||
itemNameOverlaySettings = new ItemNameOverlaySettings(
|
||||
ItemNameOverlayMode.fromConfigValue(getIntSetting("inventory.itemNameOverlay.mode")),
|
||||
readItemNameScale("fontScale", 0.5f),
|
||||
readItemNameScale("unicodeFontScale", 0.5625f),
|
||||
readItemNameScale("minimumScale", 0.3f),
|
||||
getIntSetting("inventory.itemNameOverlay.width"),
|
||||
getIntSetting("inventory.itemNameOverlay.maxCharacters"),
|
||||
getIntSetting("inventory.itemNameOverlay.maxLines"),
|
||||
getBooleanSetting("inventory.itemNameOverlay.outline"));
|
||||
ItemNameOverlayRenderer.INSTANCE.setSettings(itemNameOverlaySettings);
|
||||
}
|
||||
|
||||
private static void refreshItemNameOverlaySetting(String setting) {
|
||||
if (setting.startsWith("inventory.itemNameOverlay.")) {
|
||||
reloadItemNameOverlaySettings();
|
||||
}
|
||||
}
|
||||
|
||||
private static void linkOptionList() {
|
||||
OptionList.setOptionList(new OptionList("nei.options") {
|
||||
|
||||
@@ -1231,11 +1373,13 @@ public class NEIClientConfig {
|
||||
public static void toggleBooleanSetting(String setting) {
|
||||
ConfigTag tag = getSetting(setting);
|
||||
tag.setBooleanValue(!tag.getBooleanValue());
|
||||
refreshItemNameOverlaySetting(setting);
|
||||
}
|
||||
|
||||
public static void cycleSetting(String setting, int max) {
|
||||
ConfigTag tag = getSetting(setting);
|
||||
tag.setIntValue((tag.getIntValue() + 1) % max);
|
||||
refreshItemNameOverlaySetting(setting);
|
||||
}
|
||||
|
||||
public static int getIntSetting(String setting) {
|
||||
@@ -1244,6 +1388,7 @@ public class NEIClientConfig {
|
||||
|
||||
public static void setIntSetting(String setting, int val) {
|
||||
getSetting(setting).setIntValue(val);
|
||||
refreshItemNameOverlaySetting(setting);
|
||||
}
|
||||
|
||||
public static String getSearchExpression() {
|
||||
@@ -1274,6 +1419,14 @@ public class NEIClientConfig {
|
||||
return OpenGlHelper.framebufferSupported ? getIntSetting("inventory.gridRenderingCacheMode") : 0;
|
||||
}
|
||||
|
||||
public static ItemNameOverlayMode getItemNameOverlayMode() {
|
||||
return itemNameOverlaySettings.mode;
|
||||
}
|
||||
|
||||
public static ItemNameOverlaySettings getItemNameOverlaySettings() {
|
||||
return itemNameOverlaySettings;
|
||||
}
|
||||
|
||||
public static boolean enableCollapsibleItems() {
|
||||
return getBooleanSetting("inventory.collapsibleItems.enabled");
|
||||
}
|
||||
|
||||
@@ -58,7 +58,9 @@ public class SearchTextFormatter implements TextFormatter {
|
||||
|
||||
int startIndex = 0;
|
||||
|
||||
for (SearchToken token : searchParser.splitSearchText(contextPart[1])) {
|
||||
final String prefixes = contextPart[0].startsWith("~") ? "" : searchParser.getPrefixes();
|
||||
|
||||
for (SearchToken token : searchParser.splitSearchText(contextPart[1], prefixes)) {
|
||||
formattedText.append(contextPart[1].substring(startIndex, token.start));
|
||||
EnumChatFormatting tokenColor = EnumChatFormatting.RESET;
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -21,6 +22,7 @@ import codechicken.nei.filter.AllMultiRecipeFilter;
|
||||
import codechicken.nei.filter.AnyMultiRecipeFilter;
|
||||
import codechicken.nei.filter.RecipeFilter;
|
||||
import codechicken.nei.filter.RecipeFilter.FilterContext;
|
||||
import codechicken.nei.filter.RecipeTextFilter;
|
||||
import codechicken.nei.search.ItemFilterVisitor;
|
||||
import codechicken.nei.search.RecipeFilterVisitor;
|
||||
import codechicken.nei.search.SearchExpressionUtils;
|
||||
@@ -207,7 +209,8 @@ public class SearchTokenParser {
|
||||
for (String[] contextQuery : splitByDelimiters(subQuery[1], contextTokens, false)) {
|
||||
|
||||
if (contextQuery[1].isEmpty() || contextQuery[0].startsWith(">")
|
||||
|| contextQuery[0].startsWith("^")) {
|
||||
|| contextQuery[0].startsWith("^")
|
||||
|| contextQuery[0].startsWith("~")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -286,6 +289,7 @@ public class SearchTokenParser {
|
||||
}
|
||||
|
||||
final List<IRecipeFilter> tokens = new ArrayList<>();
|
||||
final boolean recipeText = contextQuery[0].startsWith("~");
|
||||
FilterContext context = FilterContext.ANY;
|
||||
|
||||
if (!contextQuery[0].isEmpty()) {
|
||||
@@ -293,12 +297,26 @@ public class SearchTokenParser {
|
||||
contextQuery[0] = contextQuery[0].substring(1);
|
||||
}
|
||||
|
||||
for (SearchToken token : splitSearchText(contextQuery[0] + contextQuery[1])) {
|
||||
final ItemFilter result = token.getFilter(this);
|
||||
if (result != null) {
|
||||
tokens.add(
|
||||
new RecipeFilter(context, token.ignore == null || token.ignore != '!', result));
|
||||
for (SearchToken token : splitSearchText(
|
||||
contextQuery[0] + contextQuery[1],
|
||||
recipeText ? "" : getPrefixes())) {
|
||||
|
||||
if (recipeText) {
|
||||
final IRecipeFilter text = recipeTextFilter(token);
|
||||
if (text != null) {
|
||||
tokens.add(text);
|
||||
}
|
||||
} else {
|
||||
final ItemFilter result = token.getFilter(this);
|
||||
if (result != null) {
|
||||
tokens.add(
|
||||
new RecipeFilter(
|
||||
context,
|
||||
token.ignore == null || token.ignore != '!',
|
||||
result));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (tokens.size() == 1) {
|
||||
@@ -338,14 +356,31 @@ public class SearchTokenParser {
|
||||
|
||||
}
|
||||
|
||||
private static IRecipeFilter recipeTextFilter(SearchToken token) {
|
||||
if (token.rawText.isEmpty()) return null;
|
||||
final List<Predicate<List<String>>> words = new ArrayList<>();
|
||||
|
||||
for (String word : token.words) {
|
||||
final Pattern pattern = SearchField.getPattern(word);
|
||||
if (pattern != null) words.add(RecipeTextFilter.matching(pattern));
|
||||
}
|
||||
|
||||
if (words.isEmpty()) return null;
|
||||
final Predicate<List<String>> text = lines -> words.stream().allMatch(word -> word.test(lines));
|
||||
return new RecipeTextFilter(token.ignore == null ? text : text.negate());
|
||||
}
|
||||
|
||||
public List<SearchToken> splitSearchText(String filterText) {
|
||||
return splitSearchText(filterText, getPrefixes());
|
||||
}
|
||||
|
||||
public List<SearchToken> splitSearchText(String filterText, String prefixes) {
|
||||
if (filterText.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
final List<SearchToken> tokens = new ArrayList<>();
|
||||
final int spaceMode = NEIClientConfig.getIntSetting("inventory.search.spaceMode");
|
||||
final String prefixes = getPrefixes();
|
||||
SearchToken lastToken = null;
|
||||
int lastEnd = 0;
|
||||
|
||||
@@ -514,7 +549,7 @@ public class SearchTokenParser {
|
||||
|
||||
public String getRecipeContextTokens() {
|
||||
// '^' is the start anchor and the negated class in regex mode
|
||||
return NEIClientConfig.getIntSetting("inventory.search.patternMode") == 2 ? "<>" : "<>^";
|
||||
return NEIClientConfig.getIntSetting("inventory.search.patternMode") == 2 ? "<>~" : "<>~^";
|
||||
}
|
||||
|
||||
public char getRedefinedPrefix(char prefix) {
|
||||
|
||||
@@ -4,27 +4,22 @@ import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockSnow;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EnumCreatureType;
|
||||
import net.minecraft.entity.passive.EntityPig;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.world.EnumSkyBlock;
|
||||
import net.minecraft.world.SpawnerAnimals;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.cardinalstar.cubicchunks.world.api.IMinMaxHeight;
|
||||
|
||||
import codechicken.lib.math.MathHelper;
|
||||
import codechicken.nei.KeyManager.IKeyStateTracker;
|
||||
import codechicken.nei.moboverlay.MobOverlayDisplayList;
|
||||
import codechicken.nei.moboverlay.MobOverlayFace;
|
||||
import codechicken.nei.moboverlay.MobOverlayScan;
|
||||
import codechicken.nei.moboverlay.MobOverlayStyle;
|
||||
import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||
|
||||
public class WorldOverlayRenderer implements IKeyStateTracker {
|
||||
@@ -32,14 +27,20 @@ public class WorldOverlayRenderer implements IKeyStateTracker {
|
||||
public static int chunkOverlay = 0;
|
||||
|
||||
public static int mobOverlay = 0;
|
||||
private static byte[] mobSpawnCache;
|
||||
private static long mobOverlayUpdateTime;
|
||||
private static final MobOverlayScan MOB_OVERLAY_SCAN = new MobOverlayScan();
|
||||
private static final MobOverlayFace MARKED_FACE = new MobOverlayFace();
|
||||
private static final MobOverlayDisplayList MOB_OVERLAY_LIST = new MobOverlayDisplayList();
|
||||
|
||||
public static void reset() {
|
||||
mobOverlay = 0;
|
||||
chunkOverlay = 0;
|
||||
}
|
||||
|
||||
public static void onWorldUnload() {
|
||||
MOB_OVERLAY_SCAN.clear();
|
||||
MOB_OVERLAY_LIST.delete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tickKeyStates() {
|
||||
if (Minecraft.getMinecraft().currentScreen != null) return;
|
||||
@@ -82,158 +83,97 @@ public class WorldOverlayRenderer implements IKeyStateTracker {
|
||||
GL11.glPopAttrib();
|
||||
}
|
||||
|
||||
private static void buildMobSpawnOverlay(Entity entity) {
|
||||
if (mobSpawnCache == null) {
|
||||
mobSpawnCache = new byte[33 * 33 * 33]; // 35kB
|
||||
}
|
||||
|
||||
World world = entity.worldObj;
|
||||
int worldHeight = world.getHeight();
|
||||
|
||||
int x1 = (int) entity.posX;
|
||||
int z1 = (int) entity.posZ;
|
||||
int y1 = (int) MathHelper.clip(entity.posY, 16, worldHeight - 16);
|
||||
|
||||
for (int i = 0; i <= 32; i++) {
|
||||
int x = x1 - 16 + i;
|
||||
for (int j = 0; j <= 32; j++) {
|
||||
int z = z1 - 16 + j;
|
||||
int bufIndex = (i * 33 + j) * 33;
|
||||
|
||||
Chunk chunk = world.getChunkFromBlockCoords(x, z);
|
||||
BiomeGenBase biome = world.getBiomeGenForCoords(x, z);
|
||||
if (biome.getSpawnableList(EnumCreatureType.monster).isEmpty() || biome.getSpawningChance() <= 0) {
|
||||
mobSpawnCache[bufIndex] = -1;
|
||||
continue;
|
||||
}
|
||||
|
||||
int maxHeight = chunk.worldObj.getHeightValue(x, z);
|
||||
|
||||
for (int k = 0; k <= 32; k++) {
|
||||
int y = y1 - 16 + k;
|
||||
|
||||
if (y >= worldHeight) {
|
||||
mobSpawnCache[bufIndex + k] = -1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (y > maxHeight) {
|
||||
mobSpawnCache[bufIndex + k] = -1;
|
||||
break;
|
||||
}
|
||||
mobSpawnCache[bufIndex + k] = getSpawnMode(chunk, x, y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static double getOverlayYOffset(World world, int x, int y, int z) {
|
||||
Block block = world.getBlock(x, y, z);
|
||||
if (block instanceof BlockSnow) {
|
||||
int meta = world.getBlockMetadata(x, y, z) & 7;
|
||||
return (1 + meta) / 8.0 + 0.02;
|
||||
}
|
||||
return 0.02;
|
||||
}
|
||||
|
||||
/**
|
||||
* The model view matrix is relative to ({@code intOffsetX}, {@code intOffsetY}, {@code intOffsetZ}), the camera
|
||||
* position cast to {@code int}.
|
||||
*/
|
||||
private static void renderMobSpawnOverlay(Entity entity, int intOffsetX, int intOffsetY, int intOffsetZ) {
|
||||
if (mobOverlay == 0) {
|
||||
if (mobSpawnCache != null) {
|
||||
mobSpawnCache = null;
|
||||
}
|
||||
MOB_OVERLAY_SCAN.clear();
|
||||
MOB_OVERLAY_LIST.delete();
|
||||
return;
|
||||
}
|
||||
|
||||
long worldTime = entity.worldObj.getTotalWorldTime();
|
||||
if (mobSpawnCache == null || mobOverlayUpdateTime != worldTime) {
|
||||
mobOverlayUpdateTime = worldTime;
|
||||
buildMobSpawnOverlay(entity);
|
||||
MOB_OVERLAY_SCAN.update(
|
||||
entity,
|
||||
NEIClientConfig.getIntSetting("world.overlays.mobOverlayRadius"),
|
||||
NEIClientConfig.getIntSetting("world.overlays.mobOverlayVerticalRadius"));
|
||||
final MobOverlayStyle style = MobOverlayStyle
|
||||
.parseStyle(NEIClientConfig.getSetting("world.overlays.mobOverlayStyle").getValue());
|
||||
final long worldTicks = entity.worldObj.getTotalWorldTime();
|
||||
if (MOB_OVERLAY_LIST.isCompileDue(MOB_OVERLAY_SCAN.getModesVersion(), style, worldTicks)) {
|
||||
compileMobOverlayList(style, worldTicks);
|
||||
}
|
||||
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
beginMobOverlayDraw(style);
|
||||
MOB_OVERLAY_LIST.draw(intOffsetX, intOffsetY, intOffsetZ);
|
||||
endMobOverlayDraw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a marked face to {@link #MOB_OVERLAY_LIST} for each block of {@link #MOB_OVERLAY_SCAN} where mobs can spawn.
|
||||
*/
|
||||
private static void compileMobOverlayList(MobOverlayStyle style, long worldTicks) {
|
||||
MOB_OVERLAY_LIST.beginCompile(MOB_OVERLAY_SCAN, style, worldTicks);
|
||||
final float alpha = style.computeAlpha();
|
||||
final Tessellator tess = Tessellator.instance;
|
||||
tess.startDrawing(style.glMode);
|
||||
final int span = MOB_OVERLAY_SCAN.getSpan();
|
||||
for (int i = 0; i < span; i++) {
|
||||
for (int j = 0; j < span; j++) {
|
||||
for (int k = 0; k < MOB_OVERLAY_SCAN.getHeight(); k++) {
|
||||
if (MOB_OVERLAY_SCAN.readSpawnMode(i, k, j) == 0) continue;
|
||||
|
||||
MARKED_FACE.moveTo(i, k + MOB_OVERLAY_SCAN.readOverlayYOffset(i, k, j), j);
|
||||
loadNeighbourModes(i, k, j);
|
||||
MARKED_FACE.applyColor(style.colouring, alpha);
|
||||
style.addVertices(MARKED_FACE);
|
||||
}
|
||||
}
|
||||
}
|
||||
tess.draw();
|
||||
MOB_OVERLAY_LIST.endCompile();
|
||||
}
|
||||
|
||||
private static void beginMobOverlayDraw(MobOverlayStyle style) {
|
||||
final ResourceLocation texture = style.texture;
|
||||
if (texture == null) {
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
} else {
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
|
||||
}
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glLineWidth(1.5F);
|
||||
// the outline of `MobOverlayStyle.CONNECTED` lies in the plane of the tint. With depth writes on, the depth
|
||||
// test discards most of the outline
|
||||
GL11.glDepthMask(false);
|
||||
}
|
||||
|
||||
int curSpawnMode = 2;
|
||||
|
||||
World world = entity.worldObj;
|
||||
int x1 = (int) entity.posX - intOffsetX;
|
||||
int z1 = (int) entity.posZ - intOffsetZ;
|
||||
int y1 = (int) MathHelper.clip(entity.posY, 16, world.getHeight() - 16) - intOffsetY;
|
||||
|
||||
final Tessellator tess = Tessellator.instance;
|
||||
tess.startDrawing(GL11.GL_LINES);
|
||||
tess.setColorOpaque(255, 0, 0);
|
||||
|
||||
for (int i = 0; i <= 32; i++) {
|
||||
int x = x1 - 16 + i;
|
||||
for (int j = 0; j <= 32; j++) {
|
||||
int z = z1 - 16 + j;
|
||||
int cacheIndex = (i * 33 + j) * 33;
|
||||
|
||||
for (int k = 0; k <= 32; k++) {
|
||||
int y = y1 - 16 + k;
|
||||
int spawnMode = mobSpawnCache[cacheIndex + k];
|
||||
if (spawnMode == 0) {
|
||||
continue;
|
||||
} else if (spawnMode == -1) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (spawnMode != curSpawnMode) {
|
||||
if (spawnMode == 1) {
|
||||
tess.setColorOpaque(255, 255, 0);
|
||||
} else {
|
||||
tess.setColorOpaque(255, 0, 0);
|
||||
}
|
||||
curSpawnMode = spawnMode;
|
||||
}
|
||||
|
||||
double yOff = getOverlayYOffset(world, x + intOffsetX, y + intOffsetY, z + intOffsetZ);
|
||||
|
||||
tess.addVertex(x, y + yOff, z);
|
||||
tess.addVertex(x + 1, y + yOff, z + 1);
|
||||
tess.addVertex(x + 1, y + yOff, z);
|
||||
tess.addVertex(x, y + yOff, z + 1);
|
||||
}
|
||||
private static void loadNeighbourModes(int i, int k, int j) {
|
||||
final int span = MOB_OVERLAY_SCAN.getSpan();
|
||||
for (int offsetX = -1; offsetX <= 1; offsetX++) {
|
||||
for (int offsetZ = -1; offsetZ <= 1; offsetZ++) {
|
||||
final int neighbourI = i + offsetX;
|
||||
final int neighbourJ = j + offsetZ;
|
||||
final boolean isInScan = neighbourI >= 0 && neighbourI < span && neighbourJ >= 0 && neighbourJ < span;
|
||||
final byte spawnMode = isInScan ? MOB_OVERLAY_SCAN.readSpawnMode(neighbourI, k, neighbourJ)
|
||||
: MobOverlayFace.OUTSIDE_SCAN;
|
||||
MARKED_FACE.setNeighbourMode(offsetX, offsetZ, spawnMode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tess.draw();
|
||||
/** Undo the GL state changes of {@link #beginMobOverlayDraw}, except the texture binding. */
|
||||
private static void endMobOverlayDraw() {
|
||||
GL11.glDepthMask(true);
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
}
|
||||
|
||||
private static final Entity dummyEntity = new EntityPig(null);
|
||||
private static final AxisAlignedBB aabb = AxisAlignedBB.getBoundingBox(0, 0, 0, 0, 0, 0);
|
||||
|
||||
private static byte getSpawnMode(Chunk chunk, int x, int y, int z) {
|
||||
if (y >= chunk.worldObj.getHeight()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (chunk.getSavedLightValue(EnumSkyBlock.Block, x & 15, y, z & 15) >= 8
|
||||
|| !SpawnerAnimals.canCreatureTypeSpawnAtLocation(EnumCreatureType.monster, chunk.worldObj, x, y, z)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
aabb.minX = x + 0.2;
|
||||
aabb.maxX = x + 0.8;
|
||||
aabb.minY = y + 0.01;
|
||||
aabb.maxY = y + 1.8;
|
||||
aabb.minZ = z + 0.2;
|
||||
aabb.maxZ = z + 0.8;
|
||||
if (!chunk.worldObj.getCollidingBoundingBoxes(dummyEntity, aabb).isEmpty()
|
||||
|| chunk.worldObj.isAnyLiquid(aabb)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (byte) (chunk.getSavedLightValue(EnumSkyBlock.Sky, x & 15, y, z & 15) >= 8 ? 1 : 2);
|
||||
}
|
||||
|
||||
private static void renderChunkBounds(Entity entity, int intOffsetX, int intOffsetY, int intOffsetZ) {
|
||||
if (chunkOverlay == 0) return;
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@ import java.util.Map;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import org.lwjgl.input.Mouse;
|
||||
@@ -205,9 +207,24 @@ public abstract class ShortcutInputHandler {
|
||||
|
||||
private static boolean copyItemStackID(ItemStack stackover) {
|
||||
if (stackover == null || stackover.getItem() == null) return false;
|
||||
GuiScreen.setClipboardString(
|
||||
stackover.getItem().delegate.name()
|
||||
+ (stackover.getItemDamage() != 0 ? "/" + stackover.getItemDamage() : ""));
|
||||
|
||||
String clipboard;
|
||||
|
||||
if (StackInfo.isFluidDisplayItem(stackover)) {
|
||||
final FluidStack fluid = StackInfo.getFluid(stackover);
|
||||
|
||||
if (fluid == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
clipboard = FluidRegistry.getDefaultFluidName(fluid.getFluid());
|
||||
} else {
|
||||
clipboard = stackover.getItem().delegate.name()
|
||||
+ (stackover.getItemDamage() != 0 ? "/" + stackover.getItemDamage() : "");
|
||||
}
|
||||
|
||||
GuiScreen.setClipboardString(clipboard);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package codechicken.nei.config;
|
||||
|
||||
import codechicken.lib.gui.GuiDraw;
|
||||
|
||||
public class OptionFloatField extends OptionTextField {
|
||||
|
||||
public final float min;
|
||||
public final float max;
|
||||
|
||||
public OptionFloatField(String name, float min, float max) {
|
||||
super(name);
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getMaxInputWidth() {
|
||||
return GuiDraw.getStringWidth(Float.toString(max)) + 32;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidInput(String text) {
|
||||
if (text.isEmpty() || text.equals(".")) {
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
return Float.isFinite(Float.parseFloat(text));
|
||||
} catch (NumberFormatException ignored) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidValue(String text) {
|
||||
try {
|
||||
final float value = Float.parseFloat(text);
|
||||
return Float.isFinite(value) && value >= min && value <= max;
|
||||
} catch (NumberFormatException ignored) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import codechicken.nei.api.IRecipeFilter;
|
||||
import codechicken.nei.api.ItemFilter;
|
||||
import codechicken.nei.api.ItemInfo;
|
||||
import codechicken.nei.recipe.IRecipeHandler;
|
||||
import codechicken.nei.recipe.RecipeRole;
|
||||
|
||||
public class RecipeFilter implements IRecipeFilter {
|
||||
|
||||
@@ -47,17 +48,17 @@ public class RecipeFilter implements IRecipeFilter {
|
||||
public boolean matches(IRecipeHandler handler, int recipeIndex) {
|
||||
|
||||
if ((this.context == FilterContext.ANY || this.context == FilterContext.INPUT)
|
||||
&& matchPositionedStack(handler.getIngredientStacks(recipeIndex), this.anyMatch)) {
|
||||
&& matchPositionedStack(handler.getSearchStacks(recipeIndex, RecipeRole.INPUT), this.anyMatch)) {
|
||||
return this.anyMatch;
|
||||
}
|
||||
|
||||
if ((this.context == FilterContext.ANY || this.context == FilterContext.OUTPUT)
|
||||
&& matchPositionedStack(handler.getResultStacks(recipeIndex), this.anyMatch)) {
|
||||
&& matchPositionedStack(handler.getSearchStacks(recipeIndex, RecipeRole.OUTPUT), this.anyMatch)) {
|
||||
return this.anyMatch;
|
||||
}
|
||||
|
||||
if ((this.context == FilterContext.ANY || this.context == FilterContext.AUXILIARY)
|
||||
&& matchPositionedStack(handler.getAuxiliaryStacks(recipeIndex), this.anyMatch)) {
|
||||
&& matchPositionedStack(handler.getSearchStacks(recipeIndex, RecipeRole.AUXILIARY), this.anyMatch)) {
|
||||
return this.anyMatch;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package codechicken.nei.filter;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import codechicken.nei.api.IRecipeFilter;
|
||||
import codechicken.nei.recipe.IRecipeHandler;
|
||||
|
||||
public class RecipeTextFilter implements IRecipeFilter {
|
||||
|
||||
private final Predicate<List<String>> lines;
|
||||
|
||||
public RecipeTextFilter(Predicate<List<String>> lines) {
|
||||
this.lines = lines;
|
||||
}
|
||||
|
||||
public static Predicate<List<String>> matching(Pattern pattern) {
|
||||
return lines -> {
|
||||
for (String line : lines) {
|
||||
if (pattern.matcher(line).find()) return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(IRecipeHandler handler, int recipeIndex) {
|
||||
final List<String> text = handler.getSearchText(recipeIndex);
|
||||
return !text.isEmpty() && this.lines.test(text);
|
||||
}
|
||||
}
|
||||
@@ -50,6 +50,8 @@ import codechicken.nei.KeyManager;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.NEIClientUtils;
|
||||
import codechicken.nei.NEIModContainer;
|
||||
import codechicken.nei.item.ItemNameOverlayMode;
|
||||
import codechicken.nei.item.ItemNameOverlayRenderer;
|
||||
import codechicken.nei.recipe.StackInfo;
|
||||
import codechicken.nei.util.ItemUntranslator;
|
||||
import codechicken.nei.util.ReadableNumberConverter;
|
||||
@@ -62,6 +64,7 @@ public class GuiContainerManager {
|
||||
@Override
|
||||
public void onResourceManagerReload(IResourceManager p_110549_1_) {
|
||||
renderingErrorItems.clear();
|
||||
ItemNameOverlayRenderer.INSTANCE.clearCache();
|
||||
ItemList.loadItems.restart();
|
||||
|
||||
if (NEIClientConfig.enableItemUntranslator()) {
|
||||
@@ -348,12 +351,28 @@ public class GuiContainerManager {
|
||||
|
||||
drawItems.renderItemAndEffectIntoGUI(fontRenderer, renderEngine, itemstack, offsetX, offsetY);
|
||||
|
||||
final ItemNameOverlayMode nameMode = NEIClientConfig.getItemNameOverlayMode();
|
||||
int nameHeight = 0;
|
||||
if (nameMode != ItemNameOverlayMode.OFF) {
|
||||
nameHeight = stackSize.isEmpty() ? 11
|
||||
: Math.max(
|
||||
0,
|
||||
(int) (16
|
||||
- (Math.max(fontRenderer.FONT_HEIGHT, GuiDraw.fontRenderer.FONT_HEIGHT) - 1)
|
||||
* scale
|
||||
- 1));
|
||||
}
|
||||
|
||||
if (scale != 1f && !stackSize.isEmpty()) {
|
||||
drawBigStackSize(offsetX, offsetY, stackSize, scale);
|
||||
stackSize = "";
|
||||
}
|
||||
|
||||
drawItems.renderItemOverlayIntoGUI(fontRenderer, renderEngine, itemstack, offsetX, offsetY, stackSize);
|
||||
if (nameMode != ItemNameOverlayMode.OFF) {
|
||||
ItemNameOverlayRenderer.INSTANCE
|
||||
.render(nameMode, itemstack, fontRenderer, offsetX, offsetY, nameHeight);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -620,6 +639,9 @@ public class GuiContainerManager {
|
||||
* Called at the start of drawScreen
|
||||
*/
|
||||
public void preDraw() {
|
||||
if (NEIClientConfig.getItemNameOverlayMode() != ItemNameOverlayMode.OFF) {
|
||||
ItemNameOverlayRenderer.INSTANCE.refreshFontState();
|
||||
}
|
||||
for (IContainerDrawHandler drawHandler : drawHandlers) drawHandler.onPreDraw(window);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package codechicken.nei.item;
|
||||
|
||||
public enum ItemNameOverlayMode {
|
||||
|
||||
ITEMS(true, false),
|
||||
FLUIDS(false, true),
|
||||
ALL(true, true),
|
||||
OFF(false, false);
|
||||
|
||||
private final boolean items;
|
||||
private final boolean fluids;
|
||||
|
||||
private ItemNameOverlayMode(boolean items, boolean fluids) {
|
||||
this.items = items;
|
||||
this.fluids = fluids;
|
||||
}
|
||||
|
||||
public boolean includes(boolean fluidDisplay) {
|
||||
return fluidDisplay ? fluids : items;
|
||||
}
|
||||
|
||||
public static ItemNameOverlayMode fromConfigValue(int value) {
|
||||
return switch (value) {
|
||||
case 0 -> ITEMS;
|
||||
case 1 -> FLUIDS;
|
||||
case 2 -> ALL;
|
||||
default -> OFF;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,609 @@
|
||||
package codechicken.nei.item;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.FloatBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.util.font.FontRendering;
|
||||
import com.gtnewhorizon.gtnhlib.util.font.IFontParameters;
|
||||
|
||||
import codechicken.nei.LRUCache;
|
||||
import codechicken.nei.recipe.StackInfo;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
|
||||
public class ItemNameOverlayRenderer {
|
||||
|
||||
public static final ItemNameOverlayRenderer INSTANCE = new ItemNameOverlayRenderer();
|
||||
|
||||
private static final int[] OUTLINE_STEPS = { -1, -1, 1, 0, 1, 0, 0, 1, 0, 1, -1, 0, -1, 0, 0, -1 };
|
||||
|
||||
private final FloatBuffer matrixBuffer = BufferUtils.createFloatBuffer(16);
|
||||
private final LRUCache<LayoutKey, LabelLayout> layouts = new LRUCache<>(2048);
|
||||
private final LayoutKey lookupKey = new LayoutKey(null, "", 0, 0, false);
|
||||
private final GuiScaleCache guiScaleCache = new GuiScaleCache();
|
||||
private ItemNameOverlaySettings settings = ItemNameOverlaySettings.defaults();
|
||||
private Object fontState;
|
||||
private long cacheRevision;
|
||||
|
||||
public void render(ItemNameOverlayMode mode, ItemStack stack, FontRenderer font, int x, int y,
|
||||
int availableHeight) {
|
||||
if (mode == ItemNameOverlayMode.OFF || stack == null || stack.getItem() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final boolean fluidDisplay = StackInfo.isFluidDisplayItem(stack);
|
||||
if (!mode.includes(fluidDisplay)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final String name;
|
||||
if (fluidDisplay) {
|
||||
final FluidStack fluid = StackInfo.getFluid(stack);
|
||||
name = fluid != null ? fluid.getLocalizedName() : stack.getDisplayName();
|
||||
// Fluid renderers own their amount overlay, so reserve its bottom row.
|
||||
availableHeight = Math.min(availableHeight, font.getUnicodeFlag() ? 8 : 11);
|
||||
} else {
|
||||
name = stack.getDisplayName();
|
||||
}
|
||||
|
||||
final ItemNameOverlaySettings currentSettings = settings;
|
||||
drawLabel(
|
||||
font,
|
||||
name,
|
||||
x + (16 - currentSettings.width) / 2f,
|
||||
(float) y,
|
||||
currentSettings.width,
|
||||
availableHeight,
|
||||
currentSettings);
|
||||
}
|
||||
|
||||
public void drawLabel(FontRenderer font, String text, int x, int y, int width, int height) {
|
||||
drawLabel(font, text, (float) x, (float) y, width, height, settings);
|
||||
}
|
||||
|
||||
private void drawLabel(FontRenderer font, String text, float x, float y, int width, int height,
|
||||
ItemNameOverlaySettings currentSettings) {
|
||||
if (text == null || text.isEmpty() || width <= 0 || height <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
lookupKey.set(font, text, width, height, font.getUnicodeFlag());
|
||||
LabelLayout layout = layouts.get(lookupKey);
|
||||
if (layout == null) {
|
||||
// Stored keys are copies; the reusable lookup key never enters the cache.
|
||||
final LayoutKey key = new LayoutKey(lookupKey);
|
||||
layout = createLayout(key, currentSettings);
|
||||
layouts.put(key, layout);
|
||||
}
|
||||
if (layout.lines.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
final int guiScale = readRenderTransform();
|
||||
final float scaleX = matrixBuffer.get(0);
|
||||
final float scaleY = matrixBuffer.get(5);
|
||||
final float translateX = matrixBuffer.get(12);
|
||||
final float translateY = matrixBuffer.get(13);
|
||||
final float pixelScaleX = Math.abs(scaleX) * guiScale;
|
||||
final float pixelScaleY = Math.abs(scaleY) * guiScale;
|
||||
if (pixelScaleX <= 0 || pixelScaleY <= 0) {
|
||||
return;
|
||||
}
|
||||
final float inverseScale = 1f / layout.scale;
|
||||
final float pixelWidth = inverseScale / pixelScaleX;
|
||||
final float pixelHeight = inverseScale / pixelScaleY;
|
||||
|
||||
GL11.glPushAttrib(GL11.GL_ENABLE_BIT | GL11.GL_CURRENT_BIT | GL11.GL_COLOR_BUFFER_BIT);
|
||||
GL11.glPushMatrix();
|
||||
try {
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
GL11.glEnable(GL11.GL_ALPHA_TEST);
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glTranslatef(x, y, 0);
|
||||
GL11.glScalef(layout.scale, layout.scale, 1);
|
||||
|
||||
for (LabelLine line : layout.lines) {
|
||||
final float alignedX = (alignToPixel(x + line.x, translateX, scaleX, guiScale) - x) * inverseScale;
|
||||
final float alignedY = (alignToPixel(y + line.y, translateY, scaleY, guiScale) - y) * inverseScale;
|
||||
GL11.glTranslatef(alignedX, alignedY, 0);
|
||||
if (currentSettings.outline) {
|
||||
drawOutlinedLine(font, line.text, pixelWidth, pixelHeight);
|
||||
} else {
|
||||
font.drawString(line.text, 0, 0, 0xFFFFFFFF);
|
||||
}
|
||||
GL11.glTranslatef(-alignedX, -alignedY, 0);
|
||||
}
|
||||
} finally {
|
||||
GL11.glPopMatrix();
|
||||
GL11.glPopAttrib();
|
||||
}
|
||||
}
|
||||
|
||||
public void setSettings(ItemNameOverlaySettings settings) {
|
||||
Objects.requireNonNull(settings);
|
||||
if (!this.settings.equals(settings)) {
|
||||
this.settings = settings;
|
||||
clearCache();
|
||||
}
|
||||
}
|
||||
|
||||
public void refreshFontState() {
|
||||
final Object currentState = FontAccess.currentState();
|
||||
if (!Objects.equals(fontState, currentState)) {
|
||||
fontState = currentState;
|
||||
clearCache();
|
||||
}
|
||||
}
|
||||
|
||||
public void clearCache() {
|
||||
layouts.clear();
|
||||
lookupKey.set(null, "", 0, 0, false);
|
||||
cacheRevision++;
|
||||
}
|
||||
|
||||
public long getCacheRevision() {
|
||||
return cacheRevision;
|
||||
}
|
||||
|
||||
private int readRenderTransform() {
|
||||
final Minecraft minecraft = Minecraft.getMinecraft();
|
||||
final int guiScale = guiScaleCache.getScaleFactor(minecraft);
|
||||
matrixBuffer.clear();
|
||||
GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, matrixBuffer);
|
||||
return guiScale;
|
||||
}
|
||||
|
||||
private float alignToPixel(float coordinate, float translation, float scale, int guiScale) {
|
||||
final float screenPosition = (translation + coordinate * scale) * guiScale;
|
||||
return (Math.round(screenPosition) / (float) guiScale - translation) / scale;
|
||||
}
|
||||
|
||||
private LabelLayout createLayout(LayoutKey key, ItemNameOverlaySettings settings) {
|
||||
final FontRenderer font = key.font;
|
||||
final String text = sanitizeText(key.text);
|
||||
final float minimumScale = settings.minimumScale;
|
||||
if (text.isEmpty()) {
|
||||
return new LabelLayout(font, key.width, Collections.emptyList(), minimumScale);
|
||||
}
|
||||
|
||||
final boolean unicode = key.unicode || hasUnicodeCharacters(text);
|
||||
final float preferredScale = Math.max(minimumScale, unicode ? settings.unicodeFontScale : settings.fontScale);
|
||||
final float lineHeight = FontAccess.lineHeight(font);
|
||||
final float singleLineScale = Math.min(
|
||||
preferredScale,
|
||||
Math.min(key.width / (float) Math.max(1, getTextWidth(font, text)), key.height / (lineHeight + 1)));
|
||||
if (singleLineScale >= minimumScale && fitsCharacterLimit(text, settings.maxCharacters)) {
|
||||
return new LabelLayout(font, key.width, Collections.singletonList(text), singleLineScale);
|
||||
}
|
||||
|
||||
int availableLines = 1;
|
||||
for (int lineCount = 2; lineCount <= settings.maxLines; lineCount++) {
|
||||
final float wrappedScale = Math.min(preferredScale, key.height / (lineHeight * lineCount + 1));
|
||||
if (wrappedScale < minimumScale) {
|
||||
break;
|
||||
}
|
||||
availableLines = lineCount;
|
||||
final int maximumWidth = (int) (key.width / minimumScale);
|
||||
List<String> completeLines = wrapText(font, text, maximumWidth, lineCount, settings.maxCharacters);
|
||||
if (fitsWidth(font, completeLines, maximumWidth, settings.maxCharacters)) {
|
||||
// Find the narrowest complete split before reducing the configured multi-line scale.
|
||||
int lowerWidth = 1;
|
||||
int upperWidth = maximumWidth;
|
||||
while (lowerWidth < upperWidth) {
|
||||
final int candidateWidth = lowerWidth + (upperWidth - lowerWidth) / 2;
|
||||
final List<String> candidateLines = wrapText(
|
||||
font,
|
||||
text,
|
||||
candidateWidth,
|
||||
lineCount,
|
||||
settings.maxCharacters);
|
||||
if (fitsWidth(font, candidateLines, candidateWidth, settings.maxCharacters)) {
|
||||
upperWidth = candidateWidth;
|
||||
completeLines = candidateLines;
|
||||
} else {
|
||||
lowerWidth = candidateWidth + 1;
|
||||
}
|
||||
}
|
||||
|
||||
int widestLine = 1;
|
||||
for (String line : completeLines) {
|
||||
widestLine = Math.max(widestLine, getTextWidth(font, line));
|
||||
}
|
||||
final float completeScale = Math.min(wrappedScale, key.width / (float) widestLine);
|
||||
return new LabelLayout(font, key.width, completeLines, completeScale);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
final float croppedScale = Math.min(preferredScale, key.height / (lineHeight * availableLines + 1));
|
||||
if (croppedScale < minimumScale) {
|
||||
return new LabelLayout(font, key.width, Collections.emptyList(), croppedScale);
|
||||
}
|
||||
|
||||
final int textWidth = (int) (key.width / croppedScale);
|
||||
final List<String> shortenedLines = new ArrayList<>(
|
||||
wrapText(font, text, textWidth, availableLines, settings.maxCharacters));
|
||||
if (shortenedLines.isEmpty()) {
|
||||
final String line = ellipsize(font, text, textWidth, settings.maxCharacters);
|
||||
if (!line.isEmpty()) {
|
||||
shortenedLines.add(line);
|
||||
}
|
||||
} else {
|
||||
final int lastLine = shortenedLines.size() - 1;
|
||||
shortenedLines
|
||||
.set(lastLine, ellipsize(font, shortenedLines.get(lastLine), textWidth, settings.maxCharacters));
|
||||
}
|
||||
return new LabelLayout(font, key.width, shortenedLines, croppedScale);
|
||||
}
|
||||
|
||||
private List<String> wrapText(FontRenderer font, String text, int width, int maxLines, int maxCharacters) {
|
||||
if (text.indexOf(' ') >= 0) {
|
||||
final List<String> wordLines = wrapText(font, text, width, maxLines, maxCharacters, true);
|
||||
if (fitsWidth(font, wordLines, width, maxCharacters)) {
|
||||
return wordLines;
|
||||
}
|
||||
}
|
||||
return wrapText(font, text, width, maxLines, maxCharacters, false);
|
||||
}
|
||||
|
||||
private List<String> wrapText(FontRenderer font, String text, int width, int maxLines, int maxCharacters,
|
||||
boolean wordBreaks) {
|
||||
final List<String> lines = new ArrayList<>(maxLines);
|
||||
String remainder = text;
|
||||
while (!remainder.isEmpty()) {
|
||||
if (lines.size() == maxLines - 1) {
|
||||
lines.add(remainder);
|
||||
break;
|
||||
}
|
||||
String prefix = trimToWidth(font, remainder, width);
|
||||
if (maxCharacters > 0) {
|
||||
prefix = trimCharacters(prefix, maxCharacters);
|
||||
}
|
||||
if (prefix.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
int split = prefix.length();
|
||||
if (wordBreaks && split < remainder.length()) {
|
||||
final int lastSpace = prefix.lastIndexOf(' ');
|
||||
if (lastSpace > 0) {
|
||||
split = lastSpace;
|
||||
}
|
||||
}
|
||||
lines.add(remainder.substring(0, split).trim());
|
||||
remainder = remainder.substring(split).trim();
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
private boolean fitsWidth(FontRenderer font, List<String> lines, int width, int maxCharacters) {
|
||||
if (lines.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
for (String line : lines) {
|
||||
if (getTextWidth(font, line) > width || !fitsCharacterLimit(line, maxCharacters)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private String sanitizeText(String text) {
|
||||
text = FontAccess.preprocess(text);
|
||||
if (text.indexOf('\u00a7') >= 0) {
|
||||
final StringBuilder plain = new StringBuilder(text.length());
|
||||
for (int index = 0; index < text.length(); index++) {
|
||||
if (text.charAt(index) == '\u00a7' && index + 1 < text.length()) {
|
||||
index++;
|
||||
} else {
|
||||
plain.append(text.charAt(index));
|
||||
}
|
||||
}
|
||||
text = plain.toString();
|
||||
}
|
||||
return text.replace('\n', ' ').replace('\r', ' ').replace('\t', ' ').trim();
|
||||
}
|
||||
|
||||
private String ellipsize(FontRenderer font, String text, int width, int maxCharacters) {
|
||||
if (getTextWidth(font, text) <= width && fitsCharacterLimit(text, maxCharacters)) {
|
||||
return text;
|
||||
}
|
||||
|
||||
String suffix = trimToWidth(font, "...", width);
|
||||
if (maxCharacters > 0) {
|
||||
suffix = trimCharacters(suffix, maxCharacters);
|
||||
}
|
||||
String prefix = trimToWidth(font, text, width - getTextWidth(font, suffix)).trim();
|
||||
if (maxCharacters > 0) {
|
||||
prefix = trimCharacters(prefix, maxCharacters - suffix.codePointCount(0, suffix.length()));
|
||||
}
|
||||
String shortened = prefix + suffix;
|
||||
// Custom glyph spacing at the join must be measured as part of the complete string.
|
||||
while (!prefix.isEmpty() && getTextWidth(font, shortened) > width) {
|
||||
prefix = prefix.substring(0, prefix.offsetByCodePoints(prefix.length(), -1)).trim();
|
||||
shortened = prefix + suffix;
|
||||
}
|
||||
return shortened;
|
||||
}
|
||||
|
||||
private String trimToWidth(FontRenderer font, String text, int width) {
|
||||
if (width <= 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
final String trimmed = FontAccess.trimToWidth(font, text, width);
|
||||
final int length = trimmed.length();
|
||||
return length > 0 && Character.isHighSurrogate(trimmed.charAt(length - 1)) ? trimmed.substring(0, length - 1)
|
||||
: trimmed;
|
||||
}
|
||||
|
||||
private static int getTextWidth(FontRenderer font, String text) {
|
||||
return FontAccess.width(font, text);
|
||||
}
|
||||
|
||||
private static boolean fitsCharacterLimit(String text, int limit) {
|
||||
return limit == 0 || text.codePointCount(0, text.length()) <= limit;
|
||||
}
|
||||
|
||||
private static String trimCharacters(String text, int limit) {
|
||||
final int count = Math.min(limit, text.codePointCount(0, text.length()));
|
||||
return text.substring(0, text.offsetByCodePoints(0, count));
|
||||
}
|
||||
|
||||
private boolean hasUnicodeCharacters(String text) {
|
||||
for (int index = 0; index < text.length(); index++) {
|
||||
if (text.charAt(index) > 255) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void drawOutlinedLine(FontRenderer font, String text, float pixelWidth, float pixelHeight) {
|
||||
// Visit each neighboring screen pixel once, then return to the center.
|
||||
for (int index = 0; index < OUTLINE_STEPS.length; index += 2) {
|
||||
GL11.glTranslatef(OUTLINE_STEPS[index] * pixelWidth, OUTLINE_STEPS[index + 1] * pixelHeight, 0);
|
||||
font.drawString(text, 0, 0, 0xFF000000);
|
||||
}
|
||||
GL11.glTranslatef(pixelWidth, 0, 0);
|
||||
font.drawString(text, 0, 0, 0xFFFFFFFF);
|
||||
}
|
||||
|
||||
private static class LabelLayout {
|
||||
|
||||
private final LabelLine[] lines;
|
||||
private final float scale;
|
||||
|
||||
private LabelLayout(FontRenderer font, int width, List<String> texts, float scale) {
|
||||
this.lines = new LabelLine[texts.size()];
|
||||
this.scale = scale;
|
||||
final float lineHeight = FontAccess.lineHeight(font);
|
||||
final float anchorOffset = (lineHeight - font.FONT_HEIGHT) / 2f;
|
||||
for (int index = 0; index < texts.size(); index++) {
|
||||
final String text = texts.get(index);
|
||||
this.lines[index] = new LabelLine(
|
||||
text,
|
||||
(width - getTextWidth(font, text) * scale) / 2f,
|
||||
(1 + anchorOffset + index * lineHeight) * scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class LabelLine {
|
||||
|
||||
private final String text;
|
||||
private final float x;
|
||||
private final float y;
|
||||
|
||||
private LabelLine(String text, float x, float y) {
|
||||
this.text = text;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
}
|
||||
|
||||
private static class FontAccess {
|
||||
|
||||
private static final boolean GTNH_FONTS = hasFontAPI();
|
||||
private static Method settingsMethod = findSettingsMethod();
|
||||
|
||||
private static boolean hasFontAPI() {
|
||||
if (!Loader.isModLoaded("gtnhlib")) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
FontRendering.class.getMethod("preprocessText", String.class);
|
||||
IFontParameters.class.getMethod("getCharWidthFine", char.class);
|
||||
IFontParameters.class.getMethod("getGlyphScaleX");
|
||||
IFontParameters.class.getMethod("getGlyphScaleY");
|
||||
IFontParameters.class.getMethod("getGlyphSpacing");
|
||||
IFontParameters.class.getMethod("getWhitespaceScale");
|
||||
return true;
|
||||
} catch (ReflectiveOperationException | LinkageError ignored) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static Method findSettingsMethod() {
|
||||
if (!Loader.isModLoaded("angelica")) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return Class.forName(
|
||||
"com.gtnewhorizons.angelica.client.font.GlyphSettings",
|
||||
false,
|
||||
ItemNameOverlayRenderer.class.getClassLoader()).getMethod("current");
|
||||
} catch (ReflectiveOperationException | LinkageError ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static Object currentState() {
|
||||
if (settingsMethod != null) {
|
||||
try {
|
||||
return settingsMethod.invoke(null, (Object[]) null);
|
||||
} catch (ReflectiveOperationException | LinkageError ignored) {
|
||||
settingsMethod = null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String preprocess(String text) {
|
||||
return GTNH_FONTS ? FontRendering.preprocessText(text) : text;
|
||||
}
|
||||
|
||||
private static int width(FontRenderer font, String text) {
|
||||
// Preserve custom FontRenderer subclasses' own measurement overrides.
|
||||
return GTNH_FONTS && font.getClass() == FontRenderer.class && font instanceof IFontParameters
|
||||
? FontRendering.getStringWidth(text, font)
|
||||
: font.getStringWidth(text);
|
||||
}
|
||||
|
||||
private static String trimToWidth(FontRenderer font, String text, int width) {
|
||||
return GTNH_FONTS && font.getClass() == FontRenderer.class && font instanceof IFontParameters
|
||||
? FontRendering.trimStringToWidth(text, width, false, font)
|
||||
: font.trimStringToWidth(text, width);
|
||||
}
|
||||
|
||||
private static float lineHeight(FontRenderer font) {
|
||||
if (GTNH_FONTS && font instanceof IFontParameters parameters) {
|
||||
final float scale = parameters.getGlyphScaleY();
|
||||
if (Float.isFinite(scale) && scale > 0) {
|
||||
return font.FONT_HEIGHT * scale;
|
||||
}
|
||||
}
|
||||
return font.FONT_HEIGHT;
|
||||
}
|
||||
|
||||
private static void applyMetrics(LayoutKey key, FontRenderer font) {
|
||||
if (GTNH_FONTS && font instanceof IFontParameters parameters) {
|
||||
key.glyphScaleX = parameters.getGlyphScaleX();
|
||||
key.glyphScaleY = parameters.getGlyphScaleY();
|
||||
key.glyphSpacing = parameters.getGlyphSpacing();
|
||||
key.whitespaceScale = parameters.getWhitespaceScale();
|
||||
} else {
|
||||
key.glyphScaleX = 1;
|
||||
key.glyphScaleY = 1;
|
||||
key.glyphSpacing = 0;
|
||||
key.whitespaceScale = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class GuiScaleCache {
|
||||
|
||||
private int displayWidth = -1;
|
||||
private int displayHeight = -1;
|
||||
private int setting;
|
||||
private boolean unicode;
|
||||
private int scaleFactor;
|
||||
|
||||
private int getScaleFactor(Minecraft minecraft) {
|
||||
final boolean currentUnicode = minecraft.func_152349_b();
|
||||
if (displayWidth != minecraft.displayWidth || displayHeight != minecraft.displayHeight
|
||||
|| setting != minecraft.gameSettings.guiScale
|
||||
|| unicode != currentUnicode) {
|
||||
displayWidth = minecraft.displayWidth;
|
||||
displayHeight = minecraft.displayHeight;
|
||||
setting = minecraft.gameSettings.guiScale;
|
||||
unicode = currentUnicode;
|
||||
scaleFactor = new ScaledResolution(minecraft, displayWidth, displayHeight).getScaleFactor();
|
||||
}
|
||||
return scaleFactor;
|
||||
}
|
||||
}
|
||||
|
||||
private static class LayoutKey {
|
||||
|
||||
private FontRenderer font;
|
||||
private String text;
|
||||
private int width;
|
||||
private int height;
|
||||
private int fontHeight;
|
||||
private float glyphScaleX;
|
||||
private float glyphScaleY;
|
||||
private float glyphSpacing;
|
||||
private float whitespaceScale;
|
||||
private boolean unicode;
|
||||
private int hash;
|
||||
|
||||
private LayoutKey(FontRenderer font, String text, int width, int height, boolean unicode) {
|
||||
set(font, text, width, height, unicode);
|
||||
}
|
||||
|
||||
private LayoutKey(LayoutKey key) {
|
||||
this.font = key.font;
|
||||
this.text = key.text;
|
||||
this.width = key.width;
|
||||
this.height = key.height;
|
||||
this.fontHeight = key.fontHeight;
|
||||
this.glyphScaleX = key.glyphScaleX;
|
||||
this.glyphScaleY = key.glyphScaleY;
|
||||
this.glyphSpacing = key.glyphSpacing;
|
||||
this.whitespaceScale = key.whitespaceScale;
|
||||
this.unicode = key.unicode;
|
||||
this.hash = key.hash;
|
||||
}
|
||||
|
||||
private void set(FontRenderer font, String text, int width, int height, boolean unicode) {
|
||||
this.font = font;
|
||||
this.text = text;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.fontHeight = font != null ? font.FONT_HEIGHT : 0;
|
||||
if (font != null) {
|
||||
FontAccess.applyMetrics(this, font);
|
||||
} else {
|
||||
this.glyphScaleX = 1;
|
||||
this.glyphScaleY = 1;
|
||||
this.glyphSpacing = 0;
|
||||
this.whitespaceScale = 1;
|
||||
}
|
||||
this.unicode = unicode;
|
||||
int hash = System.identityHashCode(font);
|
||||
hash = 31 * hash + text.hashCode();
|
||||
hash = 31 * hash + width;
|
||||
hash = 31 * hash + height;
|
||||
hash = 31 * hash + fontHeight;
|
||||
hash = 31 * hash + Float.floatToIntBits(glyphScaleX);
|
||||
hash = 31 * hash + Float.floatToIntBits(glyphScaleY);
|
||||
hash = 31 * hash + Float.floatToIntBits(glyphSpacing);
|
||||
hash = 31 * hash + Float.floatToIntBits(whitespaceScale);
|
||||
this.hash = 31 * hash + Boolean.hashCode(unicode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
return other instanceof LayoutKey key && font == key.font
|
||||
&& text.equals(key.text)
|
||||
&& width == key.width
|
||||
&& height == key.height
|
||||
&& fontHeight == key.fontHeight
|
||||
&& Float.compare(glyphScaleX, key.glyphScaleX) == 0
|
||||
&& Float.compare(glyphScaleY, key.glyphScaleY) == 0
|
||||
&& Float.compare(glyphSpacing, key.glyphSpacing) == 0
|
||||
&& Float.compare(whitespaceScale, key.whitespaceScale) == 0
|
||||
&& unicode == key.unicode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package codechicken.nei.item;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class ItemNameOverlaySettings {
|
||||
|
||||
private static final ItemNameOverlaySettings DEFAULT = new ItemNameOverlaySettings(
|
||||
ItemNameOverlayMode.OFF,
|
||||
0.5f,
|
||||
0.5625f,
|
||||
0.3f,
|
||||
18,
|
||||
0,
|
||||
2,
|
||||
true);
|
||||
|
||||
public final ItemNameOverlayMode mode;
|
||||
public final float fontScale;
|
||||
public final float unicodeFontScale;
|
||||
public final float minimumScale;
|
||||
public final int width;
|
||||
public final int maxCharacters;
|
||||
public final int maxLines;
|
||||
public final boolean outline;
|
||||
|
||||
public ItemNameOverlaySettings(ItemNameOverlayMode mode, float fontScale, float unicodeFontScale,
|
||||
float minimumScale, int width, int maxCharacters, int maxLines, boolean outline) {
|
||||
this.mode = Objects.requireNonNull(mode);
|
||||
this.fontScale = normalizeScale(fontScale, 0.5f);
|
||||
this.unicodeFontScale = normalizeScale(unicodeFontScale, 0.5625f);
|
||||
this.minimumScale = normalizeScale(minimumScale, 0.3f);
|
||||
this.width = Math.max(4, Math.min(32, width));
|
||||
this.maxCharacters = Math.max(0, Math.min(256, maxCharacters));
|
||||
this.maxLines = Math.max(1, Math.min(4, maxLines));
|
||||
this.outline = outline;
|
||||
}
|
||||
|
||||
public static ItemNameOverlaySettings defaults() {
|
||||
return DEFAULT;
|
||||
}
|
||||
|
||||
private static float normalizeScale(float value, float fallback) {
|
||||
return Float.isFinite(value) ? Math.max(0.1f, Math.min(2f, value)) : fallback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
return other instanceof ItemNameOverlaySettings settings && getClass() == other.getClass()
|
||||
&& mode == settings.mode
|
||||
&& fontScale == settings.fontScale
|
||||
&& unicodeFontScale == settings.unicodeFontScale
|
||||
&& minimumScale == settings.minimumScale
|
||||
&& width == settings.width
|
||||
&& maxCharacters == settings.maxCharacters
|
||||
&& maxLines == settings.maxLines
|
||||
&& outline == settings.outline;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = mode.hashCode();
|
||||
hash = 31 * hash + Float.floatToIntBits(fontScale);
|
||||
hash = 31 * hash + Float.floatToIntBits(unicodeFontScale);
|
||||
hash = 31 * hash + Float.floatToIntBits(minimumScale);
|
||||
hash = 31 * hash + width;
|
||||
hash = 31 * hash + maxCharacters;
|
||||
hash = 31 * hash + maxLines;
|
||||
return 31 * hash + Boolean.hashCode(outline);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package codechicken.nei.moboverlay;
|
||||
|
||||
import net.minecraft.client.renderer.GLAllocation;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
/** The mob spawn overlay quads, compiled into a GL display list. */
|
||||
public final class MobOverlayDisplayList {
|
||||
|
||||
private int listId = -1;
|
||||
private int modesVersion;
|
||||
private MobOverlayStyle style;
|
||||
private int minX;
|
||||
private int minY;
|
||||
private int minZ;
|
||||
private long compiledTicks;
|
||||
|
||||
/**
|
||||
* Compiles after a {@link MobOverlayScan#getModesVersion} change are debounced to one per {@code MIN_COMPILE_TICKS}
|
||||
* ticks, because the version changes several times per second while the player moves fast, and a compile runs for a
|
||||
* millisecond or more.
|
||||
*/
|
||||
public boolean isCompileDue(int currentModesVersion, MobOverlayStyle currentStyle, long worldTicks) {
|
||||
final int MIN_COMPILE_TICKS = 5;
|
||||
if (listId < 0 || style != currentStyle) return true;
|
||||
|
||||
// after a dimension change or a server switch, `worldTicks` can be lower than `compiledTicks`
|
||||
final boolean isWaitOver = worldTicks - compiledTicks >= MIN_COMPILE_TICKS || worldTicks < compiledTicks;
|
||||
return modesVersion != currentModesVersion && isWaitOver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Quad positions are relative to block ({@link MobOverlayScan#getMinX}, {@link MobOverlayScan#getMinY},
|
||||
* {@link MobOverlayScan#getMinZ}) of {@code scan}.
|
||||
*/
|
||||
public void beginCompile(MobOverlayScan scan, MobOverlayStyle newStyle, long worldTicks) {
|
||||
if (listId < 0) listId = GLAllocation.generateDisplayLists(1);
|
||||
modesVersion = scan.getModesVersion();
|
||||
style = newStyle;
|
||||
minX = scan.getMinX();
|
||||
minY = scan.getMinY();
|
||||
minZ = scan.getMinZ();
|
||||
compiledTicks = worldTicks;
|
||||
GL11.glNewList(listId, GL11.GL_COMPILE);
|
||||
}
|
||||
|
||||
public void endCompile() {
|
||||
GL11.glEndList();
|
||||
}
|
||||
|
||||
/** The model view matrix is relative to block ({@code cameraX}, {@code cameraY}, {@code cameraZ}). */
|
||||
public void draw(int cameraX, int cameraY, int cameraZ) {
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslated(minX - cameraX, minY - cameraY, minZ - cameraZ);
|
||||
GL11.glCallList(listId);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
if (listId < 0) return;
|
||||
|
||||
GLAllocation.deleteDisplayLists(listId);
|
||||
listId = -1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package codechicken.nei.moboverlay;
|
||||
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
|
||||
/** Vertex builder for one block's top face in the mob spawn overlay. */
|
||||
public final class MobOverlayFace {
|
||||
|
||||
public static final byte OUTSIDE_SCAN = -2;
|
||||
|
||||
private static final int NEIGHBOURHOOD_SIZE = 3;
|
||||
|
||||
private final byte[] neighbourModes = new byte[NEIGHBOURHOOD_SIZE * NEIGHBOURHOOD_SIZE];
|
||||
private double x;
|
||||
private double y;
|
||||
private double z;
|
||||
|
||||
/** {@code (x, y, z)} is the north-west corner of the block's top face. */
|
||||
public void moveTo(double x, double y, double z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public void setNeighbourMode(int offsetX, int offsetZ, byte spawnMode) {
|
||||
neighbourModes[indexNeighbour(offsetX, offsetZ)] = spawnMode;
|
||||
}
|
||||
|
||||
public void applyColor(MobOverlayStyle.Colouring colouring, float alpha) {
|
||||
final boolean isNightOnly = neighbourModes[indexNeighbour(0, 0)] == MobOverlayScan.NIGHT_ONLY;
|
||||
final int rgb = switch (colouring) {
|
||||
case OVERLAY -> isNightOnly ? 0xFFFF00 : 0xFF0000;
|
||||
case STICKER -> isNightOnly ? 0xFFFFFF : 0xFF7373;
|
||||
};
|
||||
Tessellator.instance.setColorRGBA_I(rgb, Math.round(alpha * 255));
|
||||
}
|
||||
|
||||
public boolean isJoined(int offsetX, int offsetZ) {
|
||||
final byte neighbourMode = neighbourModes[indexNeighbour(offsetX, offsetZ)];
|
||||
// no outline along the edge of the scan
|
||||
return neighbourMode == neighbourModes[indexNeighbour(0, 0)] || neighbourMode == OUTSIDE_SCAN;
|
||||
}
|
||||
|
||||
public void addFullFace() {
|
||||
addVertex(0, 0);
|
||||
addVertex(0, 1);
|
||||
addVertex(1, 1);
|
||||
addVertex(1, 0);
|
||||
}
|
||||
|
||||
/** Add one cell of a 3 x 3 grid over the face. The outer rows and columns of the grid are {@code width} wide. */
|
||||
public void addCell(int offsetX, int offsetZ, double width) {
|
||||
final double west = computeCellStart(offsetX, width);
|
||||
final double east = 1 - computeCellStart(-offsetX, width);
|
||||
final double north = computeCellStart(offsetZ, width);
|
||||
final double south = 1 - computeCellStart(-offsetZ, width);
|
||||
addVertex(west, north);
|
||||
addVertex(west, south);
|
||||
addVertex(east, south);
|
||||
addVertex(east, north);
|
||||
}
|
||||
|
||||
/** The texture is upright to a player facing north (-z). */
|
||||
public void addTexturedFace() {
|
||||
addTexturedVertex(0, 0);
|
||||
addTexturedVertex(0, 1);
|
||||
addTexturedVertex(1, 1);
|
||||
addTexturedVertex(1, 0);
|
||||
}
|
||||
|
||||
/** @param offsetX 0 at the west edge, 1 at the east edge */
|
||||
public void addVertex(double offsetX, double offsetZ) {
|
||||
Tessellator.instance.addVertex(x + offsetX, y, z + offsetZ);
|
||||
}
|
||||
|
||||
private void addTexturedVertex(double offsetX, double offsetZ) {
|
||||
Tessellator.instance.setTextureUV(offsetX, offsetZ);
|
||||
addVertex(offsetX, offsetZ);
|
||||
}
|
||||
|
||||
private static int indexNeighbour(int offsetX, int offsetZ) {
|
||||
return (offsetX + 1) * NEIGHBOURHOOD_SIZE + offsetZ + 1;
|
||||
}
|
||||
|
||||
private static double computeCellStart(int offset, double width) {
|
||||
if (offset < 0) return 0;
|
||||
return offset == 0 ? width : 1 - width;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,420 @@
|
||||
package codechicken.nei.moboverlay;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EnumCreatureType;
|
||||
import net.minecraft.entity.passive.EntityPig;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.world.EnumSkyBlock;
|
||||
import net.minecraft.world.IWorldAccess;
|
||||
import net.minecraft.world.SpawnerAnimals;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
|
||||
import codechicken.lib.math.MathHelper;
|
||||
|
||||
/**
|
||||
* Spawn modes, and the tops of flat blocks such as carpets, in a box around the player. The spawn modes are from
|
||||
* {@link Column#getSpawnMode}: 0 for no spawns, 1 for night only and 2 for any time. The box moves with the player once
|
||||
* the player is a few blocks from the box's centre, and {@link #update} scans only the blocks that enter the box.
|
||||
* {@link #update} rescans the column of a block or light change on the next tick. On each tick, {@link #update} also
|
||||
* rescans a slice of the columns, for changes with no block update, such as a boat that moves into the box.
|
||||
*/
|
||||
public final class MobOverlayScan {
|
||||
|
||||
public static final byte NIGHT_ONLY = 1;
|
||||
public static final int MIN_RADIUS = 8;
|
||||
public static final int MAX_RADIUS = 64;
|
||||
public static final int DEFAULT_RADIUS = 32;
|
||||
public static final int MIN_VERTICAL_RADIUS = 4;
|
||||
public static final int MAX_VERTICAL_RADIUS = 64;
|
||||
public static final int DEFAULT_VERTICAL_RADIUS = 16;
|
||||
private static final int RECENTRE_DISTANCE = 4;
|
||||
private static final int VERTICAL_RECENTRE_DISTANCE = 2;
|
||||
private static final int RESCAN_TICKS = 40;
|
||||
private static final int SPAWN_MODE_MASK = 3;
|
||||
private static final int COVER_TOP_SHIFT = 2;
|
||||
private static final int COVER_TOP_STEPS = 32;
|
||||
|
||||
private final IWorldAccess changeListener = new ChangeListener();
|
||||
private final Column column = new Column();
|
||||
private int radius;
|
||||
private int verticalRadius;
|
||||
private int span;
|
||||
private int height;
|
||||
// a ring buffer over the box, indexed by `findCell()`. A cell has the spawn mode in the bits of `SPAWN_MODE_MASK`,
|
||||
// and `Column.readCoverTop()` shifted left by `COVER_TOP_SHIFT`
|
||||
private byte[] modes = new byte[0];
|
||||
// indexed by `findColumn(x, z)`
|
||||
private boolean[] dirty = new boolean[0];
|
||||
private boolean hasDirtyColumns;
|
||||
private int minX;
|
||||
private int minY;
|
||||
private int minZ;
|
||||
// the slice rescan of `update()` continues from this column, numbered `(x - minX) * span + (z - minZ)`
|
||||
private int nextRescanColumn;
|
||||
private int modesVersion;
|
||||
private boolean hasModes;
|
||||
private long scannedTick;
|
||||
// world of `modes`, with `changeListener` added
|
||||
private World scannedWorld;
|
||||
|
||||
public void clear() {
|
||||
if (scannedWorld == null && span == 0) return;
|
||||
|
||||
if (scannedWorld != null) scannedWorld.removeWorldAccess(changeListener);
|
||||
radius = 0;
|
||||
verticalRadius = 0;
|
||||
span = 0;
|
||||
height = 0;
|
||||
modes = new byte[0];
|
||||
dirty = new boolean[0];
|
||||
hasModes = false;
|
||||
scannedWorld = null;
|
||||
// `Chunk.worldObj` references the world
|
||||
column.chunk = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scan every column in this call after {@link #clear}, a change of either radius, a world change, or a move of
|
||||
* {@link #getSpan} blocks or more across or {@link #getHeight} blocks or more up or down. {@code newRadius} is
|
||||
* clamped between {@link #MIN_RADIUS} and {@link #MAX_RADIUS}, and {@code newVerticalRadius} between
|
||||
* {@link #MIN_VERTICAL_RADIUS} and {@link #MAX_VERTICAL_RADIUS}.
|
||||
*/
|
||||
public void update(Entity entity, int newRadius, int newVerticalRadius) {
|
||||
final World world = entity.worldObj;
|
||||
final int clampedRadius = (int) MathHelper.clip(newRadius, MIN_RADIUS, MAX_RADIUS);
|
||||
final int clampedVerticalRadius = (int) MathHelper
|
||||
.clip(newVerticalRadius, MIN_VERTICAL_RADIUS, MAX_VERTICAL_RADIUS);
|
||||
if (radius != clampedRadius || verticalRadius != clampedVerticalRadius) {
|
||||
resize(clampedRadius, clampedVerticalRadius);
|
||||
}
|
||||
final int centreX = MathHelper.floor_double(entity.posX);
|
||||
final int centreY = (int) MathHelper.clip(entity.posY, verticalRadius, world.getHeight() - verticalRadius);
|
||||
final int centreZ = MathHelper.floor_double(entity.posZ);
|
||||
final boolean isNearBox = Math.abs(centreX - radius - minX) < span && Math.abs(centreZ - radius - minZ) < span
|
||||
&& Math.abs(centreY - verticalRadius - minY) < height;
|
||||
if (!(hasModes && world == scannedWorld && isNearBox)) {
|
||||
if (world != scannedWorld) watchWorld(world);
|
||||
scanFullBox(centreX, centreY, centreZ);
|
||||
return;
|
||||
}
|
||||
|
||||
final long worldTicks = world.getTotalWorldTime();
|
||||
if (worldTicks == scannedTick) return;
|
||||
|
||||
scannedTick = worldTicks;
|
||||
boolean isChanged = moveBox(centreX, centreY, centreZ);
|
||||
if (hasDirtyColumns) isChanged |= rescanDirtyColumns();
|
||||
isChanged |= rescanSlice();
|
||||
if (isChanged) modesVersion++;
|
||||
}
|
||||
|
||||
/** The version changes when a spawn mode or the top of a flat block changes, or the box moves. */
|
||||
public int getModesVersion() {
|
||||
return modesVersion;
|
||||
}
|
||||
|
||||
public int getSpan() {
|
||||
return span;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public int getMinX() {
|
||||
return minX;
|
||||
}
|
||||
|
||||
public int getMinY() {
|
||||
return minY;
|
||||
}
|
||||
|
||||
public int getMinZ() {
|
||||
return minZ;
|
||||
}
|
||||
|
||||
/** {@code i} and {@code j} are from 0 to {@link #getSpan}, and {@code k} is from 0 to {@link #getHeight}. */
|
||||
public byte readSpawnMode(int i, int k, int j) {
|
||||
return (byte) (modes[findCell(minX + i, minY + k, minZ + j)] & SPAWN_MODE_MASK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Height of the overlay above the bottom of the block, so that a flat block such as a carpet does not cover the
|
||||
* overlay. The indices are those of {@link #readSpawnMode}.
|
||||
*/
|
||||
public double readOverlayYOffset(int i, int k, int j) {
|
||||
final double OVERLAY_GAP = 0.02;
|
||||
final int coverTopSteps = modes[findCell(minX + i, minY + k, minZ + j)] >> COVER_TOP_SHIFT;
|
||||
return (double) coverTopSteps / COVER_TOP_STEPS + OVERLAY_GAP;
|
||||
}
|
||||
|
||||
private void resize(int newRadius, int newVerticalRadius) {
|
||||
radius = newRadius;
|
||||
verticalRadius = newVerticalRadius;
|
||||
span = 2 * newRadius + 1;
|
||||
height = 2 * newVerticalRadius + 1;
|
||||
modes = new byte[span * span * height];
|
||||
dirty = new boolean[span * span];
|
||||
hasModes = false;
|
||||
nextRescanColumn = 0;
|
||||
}
|
||||
|
||||
private void scanFullBox(int centreX, int centreY, int centreZ) {
|
||||
minX = centreX - radius;
|
||||
minY = centreY - verticalRadius;
|
||||
minZ = centreZ - radius;
|
||||
for (int x = minX; x < minX + span; x++) {
|
||||
for (int z = minZ; z < minZ + span; z++) {
|
||||
scanColumn(x, z);
|
||||
}
|
||||
}
|
||||
hasModes = true;
|
||||
modesVersion++;
|
||||
scannedTick = scannedWorld.getTotalWorldTime();
|
||||
}
|
||||
|
||||
private void watchWorld(World world) {
|
||||
if (scannedWorld != null) scannedWorld.removeWorldAccess(changeListener);
|
||||
world.addWorldAccess(changeListener);
|
||||
scannedWorld = world;
|
||||
}
|
||||
|
||||
/** @return whether the box moved */
|
||||
private boolean moveBox(int centreX, int centreY, int centreZ) {
|
||||
boolean isMoved = false;
|
||||
final int offsetX = centreX - radius - minX;
|
||||
if (Math.abs(offsetX) > RECENTRE_DISTANCE) {
|
||||
final int enteringX = offsetX > 0 ? minX + span : minX + offsetX;
|
||||
minX += offsetX;
|
||||
for (int x = enteringX; x < enteringX + Math.abs(offsetX); x++) {
|
||||
for (int z = minZ; z < minZ + span; z++) {
|
||||
scanColumn(x, z);
|
||||
}
|
||||
}
|
||||
isMoved = true;
|
||||
}
|
||||
|
||||
final int offsetZ = centreZ - radius - minZ;
|
||||
if (Math.abs(offsetZ) > RECENTRE_DISTANCE) {
|
||||
final int enteringZ = offsetZ > 0 ? minZ + span : minZ + offsetZ;
|
||||
minZ += offsetZ;
|
||||
for (int x = minX; x < minX + span; x++) {
|
||||
for (int z = enteringZ; z < enteringZ + Math.abs(offsetZ); z++) {
|
||||
scanColumn(x, z);
|
||||
}
|
||||
}
|
||||
isMoved = true;
|
||||
}
|
||||
|
||||
final int offsetY = centreY - verticalRadius - minY;
|
||||
if (Math.abs(offsetY) > VERTICAL_RECENTRE_DISTANCE) {
|
||||
final int enteringY = offsetY > 0 ? minY + height : minY + offsetY;
|
||||
minY += offsetY;
|
||||
for (int x = minX; x < minX + span; x++) {
|
||||
for (int z = minZ; z < minZ + span; z++) {
|
||||
column.moveTo(x, z);
|
||||
column.scan(enteringY, enteringY + Math.abs(offsetY));
|
||||
}
|
||||
}
|
||||
isMoved = true;
|
||||
}
|
||||
return isMoved;
|
||||
}
|
||||
|
||||
private boolean rescanDirtyColumns() {
|
||||
hasDirtyColumns = false;
|
||||
boolean isChanged = false;
|
||||
for (int x = minX; x < minX + span; x++) {
|
||||
for (int z = minZ; z < minZ + span; z++) {
|
||||
if (dirty[findColumn(x, z)]) isChanged |= scanColumn(x, z);
|
||||
}
|
||||
}
|
||||
return isChanged;
|
||||
}
|
||||
|
||||
private boolean rescanSlice() {
|
||||
final int columnCount = span * span;
|
||||
final int sliceEnd = Math.min(columnCount, nextRescanColumn + (columnCount + RESCAN_TICKS - 1) / RESCAN_TICKS);
|
||||
boolean isChanged = false;
|
||||
for (; nextRescanColumn < sliceEnd; nextRescanColumn++) {
|
||||
final int x = minX + nextRescanColumn / span;
|
||||
final int z = minZ + nextRescanColumn % span;
|
||||
isChanged |= scanColumn(x, z);
|
||||
}
|
||||
if (nextRescanColumn >= columnCount) nextRescanColumn = 0;
|
||||
return isChanged;
|
||||
}
|
||||
|
||||
/** @return whether a spawn mode or the top of a flat block changed */
|
||||
private boolean scanColumn(int x, int z) {
|
||||
column.moveTo(x, z);
|
||||
dirty[findColumn(x, z)] = false;
|
||||
return column.scan(minY, minY + height);
|
||||
}
|
||||
|
||||
private int findColumn(int x, int z) {
|
||||
return Math.floorMod(x, span) * span + Math.floorMod(z, span);
|
||||
}
|
||||
|
||||
private int findCell(int x, int y, int z) {
|
||||
return findColumn(x, z) * height + Math.floorMod(y, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link #moveTo} reads a column's chunk, biome and highest non-air block in the box, and {@link #scan} reads the
|
||||
* column's blocks.
|
||||
*/
|
||||
private final class Column {
|
||||
|
||||
private final Entity dummyEntity = new EntityPig(null);
|
||||
private final AxisAlignedBB spawnBox = AxisAlignedBB.getBoundingBox(0, 0, 0, 0, 0, 0);
|
||||
private int x;
|
||||
private int z;
|
||||
private Chunk chunk;
|
||||
private int topY;
|
||||
private boolean canBiomeSpawn;
|
||||
|
||||
private void moveTo(int newX, int newZ) {
|
||||
x = newX;
|
||||
z = newZ;
|
||||
final BiomeGenBase biome = scannedWorld.getBiomeGenForCoords(x, z);
|
||||
canBiomeSpawn = !biome.getSpawnableList(EnumCreatureType.monster).isEmpty()
|
||||
&& biome.getSpawningChance() > 0;
|
||||
chunk = scannedWorld.getChunkFromBlockCoords(x, z);
|
||||
// `getHeightValue()` is the height above the highest block with a light opacity above 0. A block with a
|
||||
// light opacity of 0 can be higher: Tinkers' Construct slime grass, a hopper or a snow layer. A mob can
|
||||
// spawn on top of slime grass, a hopper or a full snow block. Search the blocks for the highest non-air
|
||||
// block
|
||||
final int SECTION_HEIGHT = 16;
|
||||
int y = Math.min(minY + height - 1, chunk.getTopFilledSegment() + SECTION_HEIGHT - 1);
|
||||
while (y >= minY && chunk.getBlock(x & 15, y, z & 15).isAir(chunk.worldObj, x, y, z)) y--;
|
||||
topY = y + 1;
|
||||
}
|
||||
|
||||
/** @return whether a spawn mode or the top of a flat block changed */
|
||||
private boolean scan(int fromY, int toY) {
|
||||
boolean isChanged = false;
|
||||
for (int y = fromY; y < toY; y++) {
|
||||
final int spawnMode = canBiomeSpawn && y <= topY ? getSpawnMode(y) : 0;
|
||||
final byte cellValue = (byte) (spawnMode == 0 ? 0 : spawnMode | (readCoverTop(y) << COVER_TOP_SHIFT));
|
||||
final int cell = findCell(x, y, z);
|
||||
isChanged |= modes[cell] != cellValue;
|
||||
modes[cell] = cellValue;
|
||||
}
|
||||
return isChanged;
|
||||
}
|
||||
|
||||
/** The spawn mode of the block at height {@code y} in this column. */
|
||||
private byte getSpawnMode(int y) {
|
||||
if (y >= chunk.worldObj.getHeight()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (chunk.getSavedLightValue(EnumSkyBlock.Block, x & 15, y, z & 15) >= 8 || !SpawnerAnimals
|
||||
.canCreatureTypeSpawnAtLocation(EnumCreatureType.monster, chunk.worldObj, x, y, z)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// the size of a zombie, a creeper and a skeleton that is not a wither skeleton. A taller or wider monster,
|
||||
// such as an enderman or a spider, needs more room
|
||||
final double MOB_WIDTH = 0.6;
|
||||
final double MOB_HEIGHT = 1.8;
|
||||
spawnBox.minX = x + 0.5 - MOB_WIDTH / 2;
|
||||
spawnBox.maxX = x + 0.5 + MOB_WIDTH / 2;
|
||||
spawnBox.minY = y;
|
||||
spawnBox.maxY = y + MOB_HEIGHT;
|
||||
spawnBox.minZ = z + 0.5 - MOB_WIDTH / 2;
|
||||
spawnBox.maxZ = z + 0.5 + MOB_WIDTH / 2;
|
||||
if (!chunk.worldObj.getCollidingBoundingBoxes(dummyEntity, spawnBox).isEmpty()
|
||||
|| chunk.worldObj.isAnyLiquid(spawnBox)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (byte) (chunk.getSavedLightValue(EnumSkyBlock.Sky, x & 15, y, z & 15) >= 8 ? 1 : 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* The top of the block at height {@code y}, in fractions of a block with {@link MobOverlayScan#COVER_TOP_STEPS}
|
||||
* as the denominator, or 0 for a tall block.
|
||||
*/
|
||||
private int readCoverTop(int y) {
|
||||
final double MAX_COVER_TOP = 0.25;
|
||||
final Block block = chunk.getBlock(x & 15, y, z & 15);
|
||||
block.setBlockBoundsBasedOnState(chunk.worldObj, x, y, z);
|
||||
final double top = block.getBlockBoundsMaxY();
|
||||
// a mark on the bounds of a plant or a sloped rail would float above most of the block. Keep the mark at
|
||||
// the floor for a tall block
|
||||
return top > MAX_COVER_TOP ? 0 : (int) Math.ceil(top * COVER_TOP_STEPS);
|
||||
}
|
||||
}
|
||||
|
||||
/** Marks the columns of the block and light changes in {@link #scannedWorld}. */
|
||||
private final class ChangeListener implements IWorldAccess {
|
||||
|
||||
@Override
|
||||
public void markBlockForUpdate(int x, int y, int z) {
|
||||
markChanged(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markBlockForRenderUpdate(int x, int y, int z) {
|
||||
markChanged(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markBlockRangeForRenderUpdate(int fromX, int fromY, int fromZ, int toX, int toY, int toZ) {
|
||||
for (int x = Math.max(fromX, minX); x <= Math.min(toX, minX + span - 1); x++) {
|
||||
for (int z = Math.max(fromZ, minZ); z <= Math.min(toZ, minZ + span - 1); z++) {
|
||||
markColumn(x, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playSound(String soundName, double x, double y, double z, float volume, float pitch) {}
|
||||
|
||||
@Override
|
||||
public void playSoundToNearExcept(EntityPlayer player, String soundName, double x, double y, double z,
|
||||
float volume, float pitch) {}
|
||||
|
||||
@Override
|
||||
public void spawnParticle(String particleName, double x, double y, double z, double velocityX, double velocityY,
|
||||
double velocityZ) {}
|
||||
|
||||
@Override
|
||||
public void onEntityCreate(Entity entity) {}
|
||||
|
||||
@Override
|
||||
public void onEntityDestroy(Entity entity) {}
|
||||
|
||||
@Override
|
||||
public void playRecord(String recordName, int x, int y, int z) {}
|
||||
|
||||
@Override
|
||||
public void broadcastSound(int soundId, int x, int y, int z, int data) {}
|
||||
|
||||
@Override
|
||||
public void playAuxSFX(EntityPlayer player, int sfxType, int x, int y, int z, int data) {}
|
||||
|
||||
@Override
|
||||
public void destroyBlockPartially(int breakerId, int x, int y, int z, int progress) {}
|
||||
|
||||
@Override
|
||||
public void onStaticEntitiesChanged() {}
|
||||
|
||||
private void markChanged(int x, int y, int z) {
|
||||
// spawn modes depend on the block below and the block above
|
||||
final boolean isInBox = x >= minX && x < minX + span && z >= minZ && z < minZ + span;
|
||||
if (isInBox && y >= minY - 1 && y <= minY + height) markColumn(x, z);
|
||||
}
|
||||
|
||||
private void markColumn(int x, int z) {
|
||||
dirty[findColumn(x, z)] = true;
|
||||
hasDirtyColumns = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
package codechicken.nei.moboverlay;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
/**
|
||||
* Each style is a mark drawn on every block where mobs can spawn. {@code world.overlays.mobOverlayStyle} is saved as
|
||||
* {@link #formatName()}.
|
||||
*/
|
||||
public enum MobOverlayStyle {
|
||||
|
||||
/** NEI's original cross from corner to corner. */
|
||||
X(GL11.GL_LINES) {
|
||||
|
||||
@Override
|
||||
public void addVertices(MobOverlayFace face) {
|
||||
face.addVertex(0, 0);
|
||||
face.addVertex(1, 1);
|
||||
face.addVertex(1, 0);
|
||||
face.addVertex(0, 1);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* A light tint, with a stronger outline around each area of one spawn mode, like a connected texture.
|
||||
*/
|
||||
CONNECTED(GL11.GL_QUADS) {
|
||||
|
||||
@Override
|
||||
public void addVertices(MobOverlayFace face) {
|
||||
final double OUTLINE_WIDTH = 1.0 / 16;
|
||||
face.addFullFace();
|
||||
face.applyColor(Colouring.OVERLAY, MARK_ALPHA);
|
||||
for (int offsetX = -1; offsetX <= 1; offsetX++) {
|
||||
for (int offsetZ = -1; offsetZ <= 1; offsetZ++) {
|
||||
// a corner cell is drawn when either edge next to the corner is outlined, and on an inside corner
|
||||
final boolean isOutline = !(face.isJoined(offsetX, offsetZ) && face.isJoined(offsetX, 0)
|
||||
&& face.isJoined(0, offsetZ));
|
||||
if (isOutline) face.addCell(offsetX, offsetZ, OUTLINE_WIDTH);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/** A small square in the middle of the block, with no tint. */
|
||||
SQUARE(GL11.GL_QUADS) {
|
||||
|
||||
@Override
|
||||
public void addVertices(MobOverlayFace face) {
|
||||
final double CENTRE = 0.5;
|
||||
final double HALF_SIDE = 7.0 / 64;
|
||||
face.addVertex(CENTRE - HALF_SIDE, CENTRE - HALF_SIDE);
|
||||
face.addVertex(CENTRE - HALF_SIDE, CENTRE + HALF_SIDE);
|
||||
face.addVertex(CENTRE + HALF_SIDE, CENTRE + HALF_SIDE);
|
||||
face.addVertex(CENTRE + HALF_SIDE, CENTRE - HALF_SIDE);
|
||||
}
|
||||
},
|
||||
|
||||
/** The pufferfish sticker. */
|
||||
PUFFERFISH("pufferfish", Colouring.STICKER) {
|
||||
|
||||
@Override
|
||||
public void addVertices(MobOverlayFace face) {
|
||||
face.addTexturedFace();
|
||||
}
|
||||
};
|
||||
|
||||
public static final MobOverlayStyle DEFAULT = CONNECTED;
|
||||
|
||||
private static final float TINT_ALPHA = 0.15F;
|
||||
// the square and the outline cover a small part of the block and need more opacity than the tint to stay visible
|
||||
private static final float MARK_ALPHA = 0.45F;
|
||||
|
||||
public final int glMode;
|
||||
@Nullable
|
||||
public final ResourceLocation texture;
|
||||
public final Colouring colouring;
|
||||
|
||||
MobOverlayStyle(int glMode) {
|
||||
this.glMode = glMode;
|
||||
this.texture = null;
|
||||
this.colouring = Colouring.OVERLAY;
|
||||
}
|
||||
|
||||
MobOverlayStyle(String textureName, Colouring colouring) {
|
||||
this.glMode = GL11.GL_QUADS;
|
||||
this.texture = new ResourceLocation("nei", "textures/overlay/" + textureName + ".png");
|
||||
this.colouring = colouring;
|
||||
}
|
||||
|
||||
/** Case-insensitive. Returns {@link #DEFAULT} for an unknown name. */
|
||||
public static MobOverlayStyle parseStyle(String rawStyle) {
|
||||
for (MobOverlayStyle candidate : values()) {
|
||||
if (candidate.formatName().equalsIgnoreCase(rawStyle)) return candidate;
|
||||
}
|
||||
return DEFAULT;
|
||||
}
|
||||
|
||||
/** @return the {@link #formatName} of every style, separated by commas */
|
||||
public static String formatAllNames() {
|
||||
final StringJoiner names = new StringJoiner(", ");
|
||||
for (MobOverlayStyle style : values()) {
|
||||
names.add(style.formatName());
|
||||
}
|
||||
return names.toString();
|
||||
}
|
||||
|
||||
public String formatName() {
|
||||
return name().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
public float computeAlpha() {
|
||||
return switch (this) {
|
||||
case CONNECTED -> TINT_ALPHA;
|
||||
case SQUARE -> MARK_ALPHA;
|
||||
// opaque lines for X, and the alpha of the PNG for PUFFERFISH
|
||||
case X, PUFFERFISH -> 1.0F;
|
||||
};
|
||||
}
|
||||
|
||||
public abstract void addVertices(MobOverlayFace face);
|
||||
|
||||
public enum Colouring {
|
||||
/** Yellow where mobs spawn only at night, red where mobs spawn at any time. */
|
||||
OVERLAY,
|
||||
/** The texture's colours, tinted red where mobs spawn at any time. */
|
||||
STICKER
|
||||
}
|
||||
}
|
||||
@@ -199,6 +199,10 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
NEIClientUtils.translate(
|
||||
"recipe.search.tooltip.output",
|
||||
SearchExpressionUtils.HIGHLIGHTS.RECIPE + ">"));
|
||||
tooltip.add(
|
||||
NEIClientUtils.translate(
|
||||
"recipe.search.tooltip.text",
|
||||
SearchExpressionUtils.HIGHLIGHTS.RECIPE + "~"));
|
||||
|
||||
final int patternMode = NEIClientConfig.getIntSetting("inventory.search.patternMode");
|
||||
|
||||
|
||||
@@ -121,6 +121,26 @@ public interface IRecipeHandler {
|
||||
return getResultStack(recipe) != null ? getOtherStacks(recipe) : Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Override it to let the recipe search see stacks that the recipe doesn't draw and doesn't give to the overlay.
|
||||
*
|
||||
* @return The stacks of the role the recipe search looks at; called from the search threads.
|
||||
*/
|
||||
default List<PositionedStack> getSearchStacks(int recipe, RecipeRole role) {
|
||||
return switch (role) {
|
||||
case INPUT -> getIngredientStacks(recipe);
|
||||
case OUTPUT -> getResultStacks(recipe);
|
||||
case AUXILIARY -> getAuxiliaryStacks(recipe);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The text the recipe text search looks at, none by default; called from the search threads.
|
||||
*/
|
||||
default List<String> getSearchText(int recipe) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param recipe The recipe index to get the group id for.
|
||||
* @return An id shared by every recipe in this recipe's group, or {@code null} if this recipe isn't grouped.
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package codechicken.nei.recipe;
|
||||
|
||||
public enum RecipeRole {
|
||||
INPUT,
|
||||
OUTPUT,
|
||||
AUXILIARY
|
||||
}
|
||||
@@ -536,11 +536,7 @@ public class DebugHandlerWidget extends Widget implements IContainerTooltipHandl
|
||||
@Override
|
||||
public boolean handleKeyPress(int keyID, char keyChar) {
|
||||
|
||||
if (NEIClientConfig.getBooleanSetting("inventory.guirecipe.handlerInfo") && keyID == Keyboard.KEY_D
|
||||
&& NEIClientUtils.shiftKey()) {
|
||||
this.showWidget = !this.showWidget;
|
||||
return true;
|
||||
} else if (this.record != null) {
|
||||
if (this.record != null) {
|
||||
|
||||
if (this.container.handleKeyPress(keyID, keyChar)) {
|
||||
return true;
|
||||
@@ -556,6 +552,13 @@ public class DebugHandlerWidget extends Widget implements IContainerTooltipHandl
|
||||
|
||||
@Override
|
||||
public boolean onHotkeyPressed() {
|
||||
|
||||
if (NEIClientConfig.getBooleanSetting("inventory.guirecipe.handlerInfo") && Keyboard.isKeyDown(Keyboard.KEY_D)
|
||||
&& NEIClientUtils.shiftKey()) {
|
||||
this.showWidget = !this.showWidget;
|
||||
return true;
|
||||
}
|
||||
|
||||
return this.record != null && this.container.onHotkeyPressed();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package codechicken.nei.search;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.antlr.v4.runtime.ParserRuleContext;
|
||||
import org.antlr.v4.runtime.tree.ParseTree;
|
||||
@@ -13,17 +12,11 @@ import codechicken.nei.ItemList.AllMultiItemFilter;
|
||||
import codechicken.nei.ItemList.AnyMultiItemFilter;
|
||||
import codechicken.nei.ItemList.NegatedItemFilter;
|
||||
import codechicken.nei.ItemList.NothingItemFilter;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.SearchTokenParser;
|
||||
import codechicken.nei.api.ItemFilter;
|
||||
|
||||
public class ItemFilterVisitor extends AbstractSearchExpressionVisitor<ItemFilter> {
|
||||
|
||||
private static final Pattern REGEX_ESCAPED_SPACE_PATTERN = Pattern.compile("([^\\\\](?:\\\\\\\\)+)?\\\\ ");
|
||||
private static final Pattern ESCAPED_SYMBOL_PATTERN = Pattern.compile("\\\\(.)");
|
||||
private static final Pattern ESCAPED_QUOTE_PATTERN = Pattern.compile("\\\\\"");
|
||||
private static final Pattern ESCAPED_SPACE_PATTERN = Pattern.compile("\\\\ ");
|
||||
|
||||
public ItemFilterVisitor(SearchTokenParser searchParser) {
|
||||
super(searchParser);
|
||||
}
|
||||
@@ -69,7 +62,7 @@ public class ItemFilterVisitor extends AbstractSearchExpressionVisitor<ItemFilte
|
||||
@Override
|
||||
public ItemFilter visitPrefixedExpression(SearchExpressionParser.PrefixedExpressionContext ctx) {
|
||||
if (ctx.token() != null) {
|
||||
final String cleanPattern = getCleanPattern(ctx.token());
|
||||
final String cleanPattern = SearchExpressionUtils.getCleanPattern(ctx.token());
|
||||
final SearchTokenParser.ISearchParserProvider provider = searchParser.getProvider(ctx.token().prefix);
|
||||
if (cleanPattern == null || provider == null) {
|
||||
return defaultResult();
|
||||
@@ -81,7 +74,7 @@ public class ItemFilterVisitor extends AbstractSearchExpressionVisitor<ItemFilte
|
||||
|
||||
@Override
|
||||
public ItemFilter visitToken(SearchExpressionParser.TokenContext ctx) {
|
||||
final String cleanPattern = getCleanPattern(ctx);
|
||||
final String cleanPattern = SearchExpressionUtils.getCleanPattern(ctx);
|
||||
if (cleanPattern != null) {
|
||||
return getAlwaysProvidersFilter(cleanPattern);
|
||||
}
|
||||
@@ -118,38 +111,6 @@ public class ItemFilterVisitor extends AbstractSearchExpressionVisitor<ItemFilte
|
||||
return constructFilter(filters, AllMultiItemFilter::new);
|
||||
}
|
||||
|
||||
private String getCleanPattern(SearchExpressionParser.TokenContext ctx) {
|
||||
String cleanPattern = null;
|
||||
if (ctx.plainText() != null) {
|
||||
cleanPattern = Pattern.quote(
|
||||
ESCAPED_SYMBOL_PATTERN.matcher(ctx.plainText().getText())
|
||||
// Unescape everything in search expression
|
||||
.replaceAll("$1"));
|
||||
} else if (ctx.regex() != null) {
|
||||
if (ctx.regex().REGEX_CONTENT() != null) {
|
||||
cleanPattern = ctx.regex().REGEX_CONTENT().getSymbol().getText();
|
||||
final int spaceModeEnabled = NEIClientConfig.getIntSetting("inventory.search.spaceMode");
|
||||
// Unescape spaces
|
||||
if (spaceModeEnabled == 1) {
|
||||
cleanPattern = REGEX_ESCAPED_SPACE_PATTERN.matcher(cleanPattern).replaceAll("$1 ");
|
||||
}
|
||||
}
|
||||
} else if (ctx.quoted() != null) {
|
||||
if (ctx.quoted().QUOTED_CONTENT() != null) {
|
||||
cleanPattern = ctx.quoted().QUOTED_CONTENT().getSymbol().getText();
|
||||
// Unescape quotes
|
||||
cleanPattern = ESCAPED_QUOTE_PATTERN.matcher(cleanPattern).replaceAll("\"");
|
||||
cleanPattern = Pattern.quote(cleanPattern);
|
||||
final int spaceModeEnabled = NEIClientConfig.getIntSetting("inventory.search.spaceMode");
|
||||
// Unescape spaces
|
||||
if (spaceModeEnabled == 1) {
|
||||
cleanPattern = ESCAPED_SPACE_PATTERN.matcher(cleanPattern).replaceAll(" ");
|
||||
}
|
||||
}
|
||||
}
|
||||
return cleanPattern;
|
||||
}
|
||||
|
||||
private ItemFilter visitChildren(ParserRuleContext node, Function<List<ItemFilter>, ItemFilter> filterConstructor) {
|
||||
if (node.children != null && !node.children.isEmpty()) {
|
||||
// By default return any found rule child filter (there should be only one)
|
||||
|
||||
@@ -2,6 +2,7 @@ package codechicken.nei.search;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import codechicken.nei.ItemList.EverythingItemFilter;
|
||||
import codechicken.nei.SearchTokenParser;
|
||||
@@ -10,6 +11,7 @@ import codechicken.nei.api.ItemFilter;
|
||||
import codechicken.nei.filter.AllMultiRecipeFilter;
|
||||
import codechicken.nei.filter.RecipeFilter;
|
||||
import codechicken.nei.filter.RecipeFilter.FilterContext;
|
||||
import codechicken.nei.filter.RecipeTextFilter;
|
||||
|
||||
public class RecipeFilterVisitor extends AbstractSearchExpressionVisitor<IRecipeFilter> {
|
||||
|
||||
@@ -41,6 +43,10 @@ public class RecipeFilterVisitor extends AbstractSearchExpressionVisitor<IRecipe
|
||||
if (ctx == null) {
|
||||
return defaultResult();
|
||||
}
|
||||
if (ctx.type == 4) {
|
||||
final Predicate<List<String>> text = new RecipeTextVisitor(this.searchParser).visitSearchExpression(ctx);
|
||||
return text == null ? defaultResult() : new RecipeTextFilter(text);
|
||||
}
|
||||
final ItemFilter itemFilter = itemFilterVisitor.visitSearchExpression(ctx);
|
||||
switch (ctx.type) {
|
||||
case 0:
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
package codechicken.nei.search;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.antlr.v4.runtime.ParserRuleContext;
|
||||
import org.antlr.v4.runtime.tree.ParseTree;
|
||||
import org.antlr.v4.runtime.tree.RuleNode;
|
||||
|
||||
import codechicken.nei.SearchField;
|
||||
import codechicken.nei.SearchTokenParser;
|
||||
import codechicken.nei.filter.RecipeTextFilter;
|
||||
|
||||
public class RecipeTextVisitor extends AbstractSearchExpressionVisitor<Predicate<List<String>>> {
|
||||
|
||||
public RecipeTextVisitor(SearchTokenParser searchParser) {
|
||||
super(searchParser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Predicate<List<String>> visitChildren(RuleNode node) {
|
||||
if (!(node instanceof ParserRuleContext context) || context.children == null) return null;
|
||||
|
||||
for (ParseTree child : context.children) {
|
||||
if (child instanceof RuleNode) return visit(child);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Predicate<List<String>> visitOrExpression(SearchExpressionParser.OrExpressionContext ctx) {
|
||||
final List<Predicate<List<String>>> parts = children(ctx);
|
||||
return parts == null ? null : lines -> parts.stream().anyMatch(part -> part.test(lines));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Predicate<List<String>> visitSequenceExpression(SearchExpressionParser.SequenceExpressionContext ctx) {
|
||||
final List<Predicate<List<String>>> parts = children(ctx);
|
||||
return parts == null ? null : lines -> parts.stream().allMatch(part -> part.test(lines));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Predicate<List<String>> visitNegateExpression(SearchExpressionParser.NegateExpressionContext ctx) {
|
||||
final Predicate<List<String>> inner = visitChildren(ctx);
|
||||
return inner == null ? null : inner.negate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Predicate<List<String>> visitPrefixedExpression(SearchExpressionParser.PrefixedExpressionContext ctx) {
|
||||
final String prefix = Pattern.quote(String.valueOf(ctx.prefix));
|
||||
final String cleanPattern = ctx.token() != null ? SearchExpressionUtils.getCleanPattern(ctx.token()) : null;
|
||||
return matcher(cleanPattern == null ? prefix : prefix + cleanPattern);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Predicate<List<String>> visitToken(SearchExpressionParser.TokenContext ctx) {
|
||||
return matcher(SearchExpressionUtils.getCleanPattern(ctx));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Predicate<List<String>> defaultResult() {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Predicate<List<String>> matcher(String cleanPattern) {
|
||||
final Pattern pattern = cleanPattern != null ? SearchField.getPattern(cleanPattern) : null;
|
||||
return pattern == null ? null : RecipeTextFilter.matching(pattern);
|
||||
}
|
||||
|
||||
private List<Predicate<List<String>>> children(ParserRuleContext ctx) {
|
||||
if (ctx.children == null) return null;
|
||||
final List<Predicate<List<String>>> parts = new ArrayList<>();
|
||||
|
||||
for (ParseTree child : ctx.children) {
|
||||
if (!(child instanceof RuleNode)) continue;
|
||||
final Predicate<List<String>> part = visit(child);
|
||||
if (part == null) return null;
|
||||
parts.add(part);
|
||||
}
|
||||
|
||||
return parts.isEmpty() ? null : parts;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package codechicken.nei.search;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
@@ -17,9 +16,6 @@ import codechicken.nei.SearchTokenParser.ISearchParserProvider;
|
||||
|
||||
public class SearchExpressionFormatVisitor extends AbstractSearchExpressionVisitor<String> {
|
||||
|
||||
private static final Pattern REGEX_ESCAPED_SPACE_PATTERN = Pattern.compile("([^\\\\](?:\\\\\\\\)+)?\\\\ ");
|
||||
private static final Pattern ESCAPED_SPACE_PATTERN = Pattern.compile("\\\\ ");
|
||||
|
||||
public SearchExpressionFormatVisitor(SearchTokenParser searchParser) {
|
||||
super(searchParser);
|
||||
}
|
||||
@@ -35,7 +31,7 @@ public class SearchExpressionFormatVisitor extends AbstractSearchExpressionVisit
|
||||
|
||||
@Override
|
||||
public String visitPrefixedExpression(SearchExpressionParser.PrefixedExpressionContext ctx) {
|
||||
final EnumChatFormatting format = getFormatting(ctx.prefix, null);
|
||||
final EnumChatFormatting format = getFormatting(ctx, ctx.prefix, null);
|
||||
return format + String.valueOf(ctx.prefix) + visitToken(ctx.token());
|
||||
}
|
||||
|
||||
@@ -66,19 +62,19 @@ public class SearchExpressionFormatVisitor extends AbstractSearchExpressionVisit
|
||||
cleanText = ctx.plainText().getText();
|
||||
// Unescape spaces
|
||||
if (spaceModeEnabled == 1) {
|
||||
cleanText = ESCAPED_SPACE_PATTERN.matcher(cleanText).replaceAll(" ");
|
||||
cleanText = SearchExpressionUtils.ESCAPED_SPACE_PATTERN.matcher(cleanText).replaceAll(" ");
|
||||
}
|
||||
final EnumChatFormatting format = getFormatting(prefix, EnumChatFormatting.RESET);
|
||||
final EnumChatFormatting format = getFormatting(ctx, prefix, EnumChatFormatting.RESET);
|
||||
return format + cleanText;
|
||||
} else if (ctx.regex() != null) {
|
||||
cleanText = visitRegex(ctx.regex());
|
||||
if (spaceModeEnabled == 1) {
|
||||
cleanText = REGEX_ESCAPED_SPACE_PATTERN.matcher(cleanText).replaceAll("$1 ");
|
||||
cleanText = SearchExpressionUtils.REGEX_ESCAPED_SPACE_PATTERN.matcher(cleanText).replaceAll("$1 ");
|
||||
}
|
||||
} else if (ctx.quoted() != null) {
|
||||
cleanText = visitQuoted(ctx.quoted());
|
||||
if (spaceModeEnabled == 1) {
|
||||
cleanText = ESCAPED_SPACE_PATTERN.matcher(cleanText).replaceAll(" ");
|
||||
cleanText = SearchExpressionUtils.ESCAPED_SPACE_PATTERN.matcher(cleanText).replaceAll(" ");
|
||||
}
|
||||
}
|
||||
return cleanText;
|
||||
@@ -91,7 +87,7 @@ public class SearchExpressionFormatVisitor extends AbstractSearchExpressionVisit
|
||||
// check if highlight is defined for the token
|
||||
Optional.ofNullable(SearchExpressionUtils.getHighlight(type))
|
||||
// check if highlight is defined for the prefix
|
||||
.orElse(getFormatting(prefix, null))
|
||||
.orElse(getFormatting(child, prefix, null))
|
||||
// use default highlight otherwise
|
||||
).map(EnumChatFormatting::toString).orElse("");
|
||||
|
||||
@@ -108,9 +104,16 @@ public class SearchExpressionFormatVisitor extends AbstractSearchExpressionVisit
|
||||
return defaultResult();
|
||||
}
|
||||
|
||||
private EnumChatFormatting getFormatting(Character prefix, EnumChatFormatting defaultFormatting) {
|
||||
private static boolean isRecipeText(ParseTree node) {
|
||||
while (node != null && !(node instanceof SearchExpressionParser.SearchExpressionContext)) {
|
||||
node = node.getParent();
|
||||
}
|
||||
return node != null && ((SearchExpressionParser.SearchExpressionContext) node).type == 4;
|
||||
}
|
||||
|
||||
private EnumChatFormatting getFormatting(ParseTree node, Character prefix, EnumChatFormatting defaultFormatting) {
|
||||
if (prefix != null) {
|
||||
if (prefix == '\0') {
|
||||
if (prefix == '\0' || isRecipeText(node)) {
|
||||
return EnumChatFormatting.RESET;
|
||||
}
|
||||
final ISearchParserProvider provider = searchParser.getProvider(prefix);
|
||||
|
||||
@@ -2,6 +2,7 @@ package codechicken.nei.search;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
|
||||
@@ -14,6 +15,11 @@ import codechicken.nei.SearchTokenParser;
|
||||
|
||||
public class SearchExpressionUtils {
|
||||
|
||||
static final Pattern REGEX_ESCAPED_SPACE_PATTERN = Pattern.compile("([^\\\\](?:\\\\\\\\)+)?\\\\ ");
|
||||
private static final Pattern ESCAPED_SYMBOL_PATTERN = Pattern.compile("\\\\(.)");
|
||||
private static final Pattern ESCAPED_QUOTE_PATTERN = Pattern.compile("\\\\\"");
|
||||
static final Pattern ESCAPED_SPACE_PATTERN = Pattern.compile("\\\\ ");
|
||||
|
||||
private static final Map<Integer, EnumChatFormatting> HIGHLIGHT_MAP = new HashMap<>();
|
||||
static {
|
||||
for (HIGHLIGHTS elem : HIGHLIGHTS.values()) {
|
||||
@@ -26,7 +32,8 @@ public class SearchExpressionUtils {
|
||||
public static enum HIGHLIGHTS {
|
||||
|
||||
RECIPE(EnumChatFormatting.GREEN, SearchExpressionParser.RECIPE_INGREDIENTS,
|
||||
SearchExpressionParser.RECIPE_RESULT, SearchExpressionParser.RECIPE_OTHERS),
|
||||
SearchExpressionParser.RECIPE_RESULT, SearchExpressionParser.RECIPE_OTHERS,
|
||||
SearchExpressionParser.RECIPE_TEXT),
|
||||
OR(EnumChatFormatting.GRAY, SearchExpressionParser.OR),
|
||||
BRACKETS(EnumChatFormatting.GRAY, SearchExpressionParser.LEFT_BRACKET, SearchExpressionParser.RIGHT_BRACKET),
|
||||
NEGATE(EnumChatFormatting.BLUE, SearchExpressionParser.DASH),
|
||||
@@ -67,6 +74,38 @@ public class SearchExpressionUtils {
|
||||
return visitor.visitRecipeSearchExpression(parser.recipeSearchExpression());
|
||||
}
|
||||
|
||||
public static String getCleanPattern(SearchExpressionParser.TokenContext ctx) {
|
||||
String cleanPattern = null;
|
||||
if (ctx.plainText() != null) {
|
||||
cleanPattern = Pattern.quote(
|
||||
ESCAPED_SYMBOL_PATTERN.matcher(ctx.plainText().getText())
|
||||
// Unescape everything in search expression
|
||||
.replaceAll("$1"));
|
||||
} else if (ctx.regex() != null) {
|
||||
if (ctx.regex().REGEX_CONTENT() != null) {
|
||||
cleanPattern = ctx.regex().REGEX_CONTENT().getSymbol().getText();
|
||||
final int spaceModeEnabled = NEIClientConfig.getIntSetting("inventory.search.spaceMode");
|
||||
// Unescape spaces
|
||||
if (spaceModeEnabled == 1) {
|
||||
cleanPattern = REGEX_ESCAPED_SPACE_PATTERN.matcher(cleanPattern).replaceAll("$1 ");
|
||||
}
|
||||
}
|
||||
} else if (ctx.quoted() != null) {
|
||||
if (ctx.quoted().QUOTED_CONTENT() != null) {
|
||||
cleanPattern = ctx.quoted().QUOTED_CONTENT().getSymbol().getText();
|
||||
// Unescape quotes
|
||||
cleanPattern = ESCAPED_QUOTE_PATTERN.matcher(cleanPattern).replaceAll("\"");
|
||||
cleanPattern = Pattern.quote(cleanPattern);
|
||||
final int spaceModeEnabled = NEIClientConfig.getIntSetting("inventory.search.spaceMode");
|
||||
// Unescape spaces
|
||||
if (spaceModeEnabled == 1) {
|
||||
cleanPattern = ESCAPED_SPACE_PATTERN.matcher(cleanPattern).replaceAll(" ");
|
||||
}
|
||||
}
|
||||
}
|
||||
return cleanPattern;
|
||||
}
|
||||
|
||||
private static <T> SearchExpressionParser createSearchExpressionParser(String text, SearchTokenParser searchParser,
|
||||
SearchExpressionParserBaseVisitor<T> visitor) {
|
||||
final boolean doLogExceptions = NEIClientConfig.getBooleanSetting("inventory.search.logSearchExceptions");
|
||||
|
||||
@@ -434,6 +434,30 @@ nei.options.inventory.itemIDs=Item IDs
|
||||
nei.options.inventory.itemIDs.0=Hidden
|
||||
nei.options.inventory.itemIDs.1=Auto
|
||||
nei.options.inventory.itemIDs.2=Shown
|
||||
nei.options.inventory.itemNameOverlay=Icon Name Overlay
|
||||
nei.options.inventory.itemNameOverlay.tip=Configure names displayed on item and fluid icons.
|
||||
nei.options.inventory.itemNameOverlay.mode=Display Name on Icons
|
||||
nei.options.inventory.itemNameOverlay.mode.0=Items Only
|
||||
nei.options.inventory.itemNameOverlay.mode.1=Fluids Only
|
||||
nei.options.inventory.itemNameOverlay.mode.2=Shown
|
||||
nei.options.inventory.itemNameOverlay.mode.3=Hidden
|
||||
nei.options.inventory.itemNameOverlay.mode.tip=Choose which icons display names. Hover over an icon to see its full name.
|
||||
nei.options.inventory.itemNameOverlay.fontScale=Font Scale
|
||||
nei.options.inventory.itemNameOverlay.fontScale.tip=Preferred size for ordinary fonts. 1.0 is normal size; names may shrink to fit.
|
||||
nei.options.inventory.itemNameOverlay.unicodeFontScale=Unicode Font Scale
|
||||
nei.options.inventory.itemNameOverlay.unicodeFontScale.tip=Preferred size for Unicode fonts and text, including Chinese characters. 1.0 is normal size.
|
||||
nei.options.inventory.itemNameOverlay.minimumScale=Minimum Font Scale
|
||||
nei.options.inventory.itemNameOverlay.minimumScale.tip=Lower bound when shrinking names. This takes priority if it exceeds a preferred font scale.
|
||||
nei.options.inventory.itemNameOverlay.width=Label Width
|
||||
nei.options.inventory.itemNameOverlay.width.tip=Total label width in pixels, centered on each icon. Larger values can overlap neighboring icons.
|
||||
nei.options.inventory.itemNameOverlay.maxCharacters=Maximum Characters per Line
|
||||
nei.options.inventory.itemNameOverlay.maxCharacters.tip=0 = automatic. Limits Unicode characters per line, including any ellipsis.
|
||||
nei.options.inventory.itemNameOverlay.maxLines=Maximum Lines
|
||||
nei.options.inventory.itemNameOverlay.maxLines.tip=1 disables wrapping. The available height and minimum scale can reduce the actual number of lines.
|
||||
nei.options.inventory.itemNameOverlay.outline=Text Outline
|
||||
nei.options.inventory.itemNameOverlay.outline.true=Shown
|
||||
nei.options.inventory.itemNameOverlay.outline.false=Hidden
|
||||
nei.options.inventory.itemNameOverlay.outline.tip=Draw a one-screen-pixel black outline to keep names readable against the icon.
|
||||
nei.options.inventory.utilities=Utilities
|
||||
nei.options.inventory.utilities.tip=Select features for utility mode
|
||||
nei.options.inventory.utilities.time=Time
|
||||
@@ -563,6 +587,15 @@ nei.options.world.overlays=Overlays Settings
|
||||
nei.options.world.overlays.lock=Lock overlays between dimensions
|
||||
nei.options.world.overlays.lock.true=Enabled
|
||||
nei.options.world.overlays.lock.false=Disabled
|
||||
nei.options.world.overlays.mobOverlayStyle=Mob Spawn Overlay Style
|
||||
nei.options.world.overlays.mobOverlayStyle.x=X
|
||||
nei.options.world.overlays.mobOverlayStyle.connected=Connected
|
||||
nei.options.world.overlays.mobOverlayStyle.square=Square
|
||||
nei.options.world.overlays.mobOverlayStyle.pufferfish=Pufferfish
|
||||
nei.options.world.overlays.mobOverlayRadius=Mob Spawn Overlay Horizontal Radius
|
||||
nei.options.world.overlays.mobOverlayRadius.tip=Horizontal block radius scanned around you. Range 8-64 blocks
|
||||
nei.options.world.overlays.mobOverlayVerticalRadius=Mob Spawn Overlay Vertical Radius
|
||||
nei.options.world.overlays.mobOverlayVerticalRadius.tip=Blocks scanned above and below you. Range 4-64 blocks
|
||||
|
||||
nei.options.tools=Tools
|
||||
nei.options.tools.export_configs=Default Config Files
|
||||
@@ -646,7 +679,8 @@ nei.recipe.search.tooltip.name=Filter Syntax
|
||||
nei.recipe.search.tooltip.shift=§7Hold §6Shift§7 for more info
|
||||
nei.recipe.search.tooltip.input=%s§ftext§8 - §7search in inputs
|
||||
nei.recipe.search.tooltip.output=%s§ftext§8 - §7search in outputs
|
||||
nei.recipe.search.tooltip.auxiliary=%s§ftext§8 - §7search in other stacks (fuel, catalysts)
|
||||
nei.recipe.search.tooltip.text=%s§ftext§8 - §7search in recipe text
|
||||
nei.recipe.search.tooltip.auxiliary=%s§ftext§8 - §7search in other stacks
|
||||
nei.recipe.search.tooltip.all=%s§ftext§8 - §7all inputs must match (same with > and ^)
|
||||
nei.recipe.search.tooltip.prefix=%stext§8 - §7%s
|
||||
|
||||
|
||||
@@ -153,6 +153,30 @@ nei.options.inventory.itemIDs=物品ID
|
||||
nei.options.inventory.itemIDs.0=隐藏
|
||||
nei.options.inventory.itemIDs.1=自动
|
||||
nei.options.inventory.itemIDs.2=显示
|
||||
nei.options.inventory.itemNameOverlay=图标名称显示
|
||||
nei.options.inventory.itemNameOverlay.tip=调整物品和流体图标上的名称显示。
|
||||
nei.options.inventory.itemNameOverlay.mode=显示名称
|
||||
nei.options.inventory.itemNameOverlay.mode.0=仅物品
|
||||
nei.options.inventory.itemNameOverlay.mode.1=仅流体
|
||||
nei.options.inventory.itemNameOverlay.mode.2=显示
|
||||
nei.options.inventory.itemNameOverlay.mode.3=隐藏
|
||||
nei.options.inventory.itemNameOverlay.mode.tip=选择哪些图标显示名称,悬停可查看完整名称。
|
||||
nei.options.inventory.itemNameOverlay.fontScale=普通字体缩放
|
||||
nei.options.inventory.itemNameOverlay.fontScale.tip=普通字体的首选大小,1.0 表示正常字号;名称放不下时可自动缩小。
|
||||
nei.options.inventory.itemNameOverlay.unicodeFontScale=Unicode 字体缩放
|
||||
nei.options.inventory.itemNameOverlay.unicodeFontScale.tip=汉字等字符和 Unicode 字体的首选大小,1.0 表示正常字号。
|
||||
nei.options.inventory.itemNameOverlay.minimumScale=最小字体缩放
|
||||
nei.options.inventory.itemNameOverlay.minimumScale.tip=自动缩小名称时的下限;若大于首选缩放,则优先采用此下限。
|
||||
nei.options.inventory.itemNameOverlay.width=标签宽度
|
||||
nei.options.inventory.itemNameOverlay.width.tip=标签的总宽度(像素),始终以图标居中;较大值可能覆盖相邻图标。
|
||||
nei.options.inventory.itemNameOverlay.maxCharacters=每行最多字符数
|
||||
nei.options.inventory.itemNameOverlay.maxCharacters.tip=0 表示自动;限制每行的 Unicode 字符数,包括省略号。
|
||||
nei.options.inventory.itemNameOverlay.maxLines=最多行数
|
||||
nei.options.inventory.itemNameOverlay.maxLines.tip=设为 1 可关闭换行;实际行数还取决于可用高度和最小缩放。
|
||||
nei.options.inventory.itemNameOverlay.outline=文字描边
|
||||
nei.options.inventory.itemNameOverlay.outline.true=显示
|
||||
nei.options.inventory.itemNameOverlay.outline.false=隐藏
|
||||
nei.options.inventory.itemNameOverlay.outline.tip=在文字外绘制 1 个屏幕像素的黑色描边,方便辨认名称。
|
||||
nei.options.inventory.search.patternMode=搜索模式
|
||||
nei.options.inventory.search.patternMode.0=简单
|
||||
nei.options.inventory.search.patternMode.1=扩展
|
||||
|
||||
@@ -91,6 +91,30 @@ nei.options.inventory.itemIDs=物品ID
|
||||
nei.options.inventory.itemIDs.0=隱藏
|
||||
nei.options.inventory.itemIDs.1=自動
|
||||
nei.options.inventory.itemIDs.2=顯示
|
||||
nei.options.inventory.itemNameOverlay=圖示名稱顯示
|
||||
nei.options.inventory.itemNameOverlay.tip=調整物品和流體圖示上的名稱顯示。
|
||||
nei.options.inventory.itemNameOverlay.mode=顯示名稱
|
||||
nei.options.inventory.itemNameOverlay.mode.0=僅物品
|
||||
nei.options.inventory.itemNameOverlay.mode.1=僅流體
|
||||
nei.options.inventory.itemNameOverlay.mode.2=顯示
|
||||
nei.options.inventory.itemNameOverlay.mode.3=隱藏
|
||||
nei.options.inventory.itemNameOverlay.mode.tip=選擇哪些圖示顯示名稱,懸停可查看完整名稱。
|
||||
nei.options.inventory.itemNameOverlay.fontScale=普通字型縮放
|
||||
nei.options.inventory.itemNameOverlay.fontScale.tip=普通字型的首選大小,1.0 表示正常字級;名稱放不下時可自動縮小。
|
||||
nei.options.inventory.itemNameOverlay.unicodeFontScale=Unicode 字型縮放
|
||||
nei.options.inventory.itemNameOverlay.unicodeFontScale.tip=漢字等字元和 Unicode 字型的首選大小,1.0 表示正常字級。
|
||||
nei.options.inventory.itemNameOverlay.minimumScale=最小字型縮放
|
||||
nei.options.inventory.itemNameOverlay.minimumScale.tip=自動縮小名稱時的下限;若大於首選縮放,則優先採用此下限。
|
||||
nei.options.inventory.itemNameOverlay.width=標籤寬度
|
||||
nei.options.inventory.itemNameOverlay.width.tip=標籤的總寬度(像素),始終以圖示置中;較大值可能覆蓋相鄰圖示。
|
||||
nei.options.inventory.itemNameOverlay.maxCharacters=每行最多字元數
|
||||
nei.options.inventory.itemNameOverlay.maxCharacters.tip=0 表示自動;限制每行的 Unicode 字元數,包括省略號。
|
||||
nei.options.inventory.itemNameOverlay.maxLines=最多行數
|
||||
nei.options.inventory.itemNameOverlay.maxLines.tip=設為 1 可關閉換行;實際行數還取決於可用高度和最小縮放。
|
||||
nei.options.inventory.itemNameOverlay.outline=文字描邊
|
||||
nei.options.inventory.itemNameOverlay.outline.true=顯示
|
||||
nei.options.inventory.itemNameOverlay.outline.false=隱藏
|
||||
nei.options.inventory.itemNameOverlay.outline.tip=在文字外繪製 1 個螢幕像素的黑色描邊,方便辨認名稱。
|
||||
nei.options.inventory.search.patternMode=搜索模式
|
||||
nei.options.inventory.search.patternMode.0=簡單
|
||||
nei.options.inventory.search.patternMode.1=擴展
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.9 KiB |
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"texture": {
|
||||
"blur": false,
|
||||
"clamp": true
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import static org.junit.jupiter.api.Named.named;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -35,6 +36,7 @@ import codechicken.nei.SearchField.SearchParserProvider;
|
||||
import codechicken.nei.api.ItemFilter;
|
||||
import codechicken.nei.api.ItemInfo;
|
||||
import codechicken.nei.recipe.IRecipeHandler;
|
||||
import codechicken.nei.recipe.RecipeRole;
|
||||
import codechicken.nei.search.IdentifierFilter;
|
||||
|
||||
@DisplayName("Search expression")
|
||||
@@ -152,6 +154,10 @@ public class SearchTokenParserTest {
|
||||
spaceModes,
|
||||
nonRegexPatternModes);
|
||||
|
||||
private static final List<Arguments> regexAllSpaceModesTestProvider = combinationsProvider(
|
||||
spaceModes,
|
||||
new ModeValue[] { patternModes[2] });
|
||||
|
||||
private static final List<Arguments> spaceIsAndExtendedPlusModeTestProvider = combinationsProvider(
|
||||
spaceIsAndMode,
|
||||
extendedPlusPatternMode);
|
||||
@@ -379,9 +385,9 @@ public class SearchTokenParserTest {
|
||||
SearchTokenParser searchParser = new SearchTokenParser();
|
||||
searchParser.addProvider(defaultParserProvider);
|
||||
IRecipeHandler handler = mock(IRecipeHandler.class);
|
||||
when(handler.getIngredientStacks(0)).thenReturn(positionedStacks(itemA));
|
||||
when(handler.getResultStacks(0)).thenReturn(positionedStacks(itemB));
|
||||
when(handler.getAuxiliaryStacks(0)).thenReturn(positionedStacks(itemC));
|
||||
when(handler.getSearchStacks(0, RecipeRole.INPUT)).thenReturn(positionedStacks(itemA));
|
||||
when(handler.getSearchStacks(0, RecipeRole.OUTPUT)).thenReturn(positionedStacks(itemB));
|
||||
when(handler.getSearchStacks(0, RecipeRole.AUXILIARY)).thenReturn(positionedStacks(itemC));
|
||||
|
||||
assertTrue(testRecipeFilter(spaceMode, patternMode, searchParser, "<" + itemA.getDisplayName(), handler));
|
||||
assertTrue(testRecipeFilter(spaceMode, patternMode, searchParser, ">" + itemB.getDisplayName(), handler));
|
||||
@@ -390,6 +396,84 @@ public class SearchTokenParserTest {
|
||||
assertFalse(testRecipeFilter(spaceMode, patternMode, searchParser, ">" + itemC.getDisplayName(), handler));
|
||||
}
|
||||
|
||||
@DisplayName("Recipe text")
|
||||
@ParameterizedTest(name = "{argumentsWithNames}")
|
||||
@FieldSource("nonRegexAllSpaceModesTestProvider")
|
||||
public void testRecipeText(int spaceMode, int patternMode) {
|
||||
SearchTokenParser searchParser = new SearchTokenParser();
|
||||
searchParser.addProvider(defaultParserProvider);
|
||||
IRecipeHandler handler = recipeTextHandler(Arrays.asList("Foo", "xyz"));
|
||||
|
||||
assertTrue(testRecipeFilter(spaceMode, patternMode, searchParser, "~foo", handler));
|
||||
assertTrue(testRecipeFilter(spaceMode, patternMode, searchParser, "~xyz", handler));
|
||||
assertFalse(testRecipeFilter(spaceMode, patternMode, searchParser, "~zzz", handler));
|
||||
// the text search does not look at the stacks
|
||||
assertFalse(testRecipeFilter(spaceMode, patternMode, searchParser, "~a", handler));
|
||||
assertTrue(testRecipeFilter(spaceMode, patternMode, searchParser, "a", handler));
|
||||
// the plain search does not look at the text
|
||||
assertFalse(testRecipeFilter(spaceMode, patternMode, searchParser, "foo", handler));
|
||||
assertFalse(testRecipeFilter(spaceMode, patternMode, searchParser, "~-foo", handler));
|
||||
assertTrue(testRecipeFilter(spaceMode, patternMode, searchParser, "~-zzz", handler));
|
||||
assertTrue(testRecipeFilter(spaceMode, patternMode, searchParser, "<a~foo", handler));
|
||||
assertFalse(testRecipeFilter(spaceMode, patternMode, searchParser, "<a~zzz", handler));
|
||||
assertFalse(testRecipeFilter(spaceMode, patternMode, searchParser, "<b~foo", handler));
|
||||
assertTrue(testRecipeFilter(spaceMode, patternMode, searchParser, ">b~xyz", handler));
|
||||
}
|
||||
|
||||
@DisplayName("Recipe text of a recipe without text")
|
||||
@ParameterizedTest(name = "{argumentsWithNames}")
|
||||
@FieldSource("nonRegexAllSpaceModesTestProvider")
|
||||
public void testRecipeTextWithoutText(int spaceMode, int patternMode) {
|
||||
SearchTokenParser searchParser = new SearchTokenParser();
|
||||
searchParser.addProvider(defaultParserProvider);
|
||||
IRecipeHandler handler = recipeTextHandler(Collections.emptyList());
|
||||
|
||||
assertFalse(testRecipeFilter(spaceMode, patternMode, searchParser, "~a", handler));
|
||||
assertFalse(testRecipeFilter(spaceMode, patternMode, searchParser, "~-a", handler));
|
||||
}
|
||||
|
||||
@DisplayName("Recipe text with wildcards and regex in Extended mode")
|
||||
@ParameterizedTest(name = "{argumentsWithNames}")
|
||||
@FieldSource("extendedOnlyAllSpaceModesTestProvider")
|
||||
public void testRecipeTextExtended(int spaceMode, int patternMode) {
|
||||
SearchTokenParser searchParser = new SearchTokenParser();
|
||||
searchParser.addProvider(defaultParserProvider);
|
||||
IRecipeHandler handler = recipeTextHandler(Arrays.asList("Foo", "xyz"));
|
||||
|
||||
assertTrue(testRecipeFilter(spaceMode, patternMode, searchParser, "~f?o", handler));
|
||||
assertTrue(testRecipeFilter(spaceMode, patternMode, searchParser, "~x*z", handler));
|
||||
assertFalse(testRecipeFilter(spaceMode, patternMode, searchParser, "~x?z?", handler));
|
||||
assertTrue(testRecipeFilter(spaceMode, patternMode, searchParser, "~r/^fo+$/", handler));
|
||||
assertFalse(testRecipeFilter(spaceMode, patternMode, searchParser, "~r/^o+$/", handler));
|
||||
}
|
||||
|
||||
@DisplayName("Recipe text in Regex mode")
|
||||
@ParameterizedTest(name = "{argumentsWithNames}")
|
||||
@FieldSource("regexAllSpaceModesTestProvider")
|
||||
public void testRecipeTextRegex(int spaceMode, int patternMode) {
|
||||
SearchTokenParser searchParser = new SearchTokenParser();
|
||||
searchParser.addProvider(defaultParserProvider);
|
||||
IRecipeHandler handler = recipeTextHandler(Arrays.asList("Foo", "xyz"));
|
||||
|
||||
assertTrue(testRecipeFilter(spaceMode, patternMode, searchParser, "~f.o", handler));
|
||||
assertTrue(testRecipeFilter(spaceMode, patternMode, searchParser, "~x[y]z", handler));
|
||||
assertFalse(testRecipeFilter(spaceMode, patternMode, searchParser, "~x[^y]z", handler));
|
||||
}
|
||||
|
||||
@DisplayName("Recipe text with brackets in Extended+ mode")
|
||||
@ParameterizedTest(name = "{argumentsWithNames}")
|
||||
@FieldSource("extendedPlusAllSpaceModesTestProvider")
|
||||
public void testRecipeTextBrackets(int spaceMode, int patternMode) {
|
||||
SearchTokenParser searchParser = new SearchTokenParser();
|
||||
searchParser.addProvider(defaultParserProvider);
|
||||
IRecipeHandler handler = recipeTextHandler(Arrays.asList("Foo", "xyz"));
|
||||
|
||||
assertTrue(testRecipeFilter(spaceMode, patternMode, searchParser, "~{foo|zzz}", handler));
|
||||
assertFalse(testRecipeFilter(spaceMode, patternMode, searchParser, "~{zzz|qqq}", handler));
|
||||
assertTrue(testRecipeFilter(spaceMode, patternMode, searchParser, "~-{zzz|qqq}", handler));
|
||||
assertFalse(testRecipeFilter(spaceMode, patternMode, searchParser, "~-{foo|qqq}", handler));
|
||||
}
|
||||
|
||||
// Extended+ specific tests
|
||||
|
||||
@DisplayName("Sequence")
|
||||
@@ -488,6 +572,15 @@ public class SearchTokenParserTest {
|
||||
return matchedItems;
|
||||
}
|
||||
|
||||
private static IRecipeHandler recipeTextHandler(List<String> text) {
|
||||
IRecipeHandler handler = mock(IRecipeHandler.class);
|
||||
when(handler.getSearchStacks(0, RecipeRole.INPUT)).thenReturn(positionedStacks(itemA));
|
||||
when(handler.getSearchStacks(0, RecipeRole.OUTPUT)).thenReturn(positionedStacks(itemB));
|
||||
when(handler.getSearchStacks(0, RecipeRole.AUXILIARY)).thenReturn(Collections.emptyList());
|
||||
when(handler.getSearchText(0)).thenReturn(text);
|
||||
return handler;
|
||||
}
|
||||
|
||||
private static boolean testRecipeFilter(int spaceMode, int patternMode, SearchTokenParser searchParser,
|
||||
String search, IRecipeHandler handler) {
|
||||
setModes(spaceMode, patternMode);
|
||||
|
||||
Reference in new issue
Block a user