From 25f8d0bacf274870c512cb6b867a55af57714fb5 Mon Sep 17 00:00:00 2001 From: isXander Date: Fri, 21 Apr 2023 22:59:08 +0100 Subject: prioritise tooltip rendering above & filter empty tooltips --- .../java/dev/isxander/yacl/impl/ConfigCategoryImpl.java | 4 ++++ .../java/dev/isxander/yacl/impl/OptionGroupImpl.java | 4 ++++ src/client/java/dev/isxander/yacl/impl/OptionImpl.java | 14 +++++++++++--- 3 files changed, 19 insertions(+), 3 deletions(-) (limited to 'src/client/java/dev/isxander/yacl/impl') diff --git a/src/client/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java b/src/client/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java index b3d28b3..2d39eb9 100644 --- a/src/client/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java +++ b/src/client/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java @@ -7,6 +7,7 @@ import dev.isxander.yacl.api.Option; import dev.isxander.yacl.api.OptionGroup; import dev.isxander.yacl.impl.utils.YACLConstants; import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.ComponentContents; import net.minecraft.network.chat.MutableComponent; import org.apache.commons.lang3.Validate; import org.jetbrains.annotations.ApiStatus; @@ -121,6 +122,9 @@ public final class ConfigCategoryImpl implements ConfigCategory { MutableComponent concatenatedTooltip = Component.empty(); boolean first = true; for (Component line : tooltipLines) { + if (line.getContents() == ComponentContents.EMPTY) + continue; + if (!first) concatenatedTooltip.append("\n"); first = false; diff --git a/src/client/java/dev/isxander/yacl/impl/OptionGroupImpl.java b/src/client/java/dev/isxander/yacl/impl/OptionGroupImpl.java index 0f883d9..68f53a0 100644 --- a/src/client/java/dev/isxander/yacl/impl/OptionGroupImpl.java +++ b/src/client/java/dev/isxander/yacl/impl/OptionGroupImpl.java @@ -5,6 +5,7 @@ import dev.isxander.yacl.api.ListOption; import dev.isxander.yacl.api.Option; import dev.isxander.yacl.api.OptionGroup; import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.ComponentContents; import net.minecraft.network.chat.MutableComponent; import org.apache.commons.lang3.Validate; import org.jetbrains.annotations.ApiStatus; @@ -113,6 +114,9 @@ public final class OptionGroupImpl implements OptionGroup { MutableComponent concatenatedTooltip = Component.empty(); boolean first = true; for (Component line : tooltipLines) { + if (line.getContents() == ComponentContents.EMPTY) + continue; + if (!first) concatenatedTooltip.append("\n"); first = false; diff --git a/src/client/java/dev/isxander/yacl/impl/OptionImpl.java b/src/client/java/dev/isxander/yacl/impl/OptionImpl.java index 35ad620..644abc9 100644 --- a/src/client/java/dev/isxander/yacl/impl/OptionImpl.java +++ b/src/client/java/dev/isxander/yacl/impl/OptionImpl.java @@ -7,6 +7,7 @@ import dev.isxander.yacl.api.Option; import dev.isxander.yacl.api.OptionFlag; import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.ComponentContents; import net.minecraft.network.chat.MutableComponent; import org.apache.commons.lang3.Validate; import org.jetbrains.annotations.ApiStatus; @@ -195,9 +196,11 @@ public final class OptionImpl implements Option { @Override public Option.Builder tooltip(@NotNull Component... tooltips) { - Validate.notNull(tooltips, "`tooltips` cannot be empty"); + var tooltipFunctions = Arrays.stream(tooltips) + .map(t -> (Function) opt -> t) + .toList(); - this.tooltipGetters.addAll(Stream.of(tooltips).map(Component -> (Function) t -> Component).toList()); + this.tooltipGetters.addAll(tooltipFunctions); return this; } @@ -277,10 +280,15 @@ public final class OptionImpl implements Option { MutableComponent concatenatedTooltip = Component.empty(); boolean first = true; for (Function line : tooltipGetters) { + Component lineComponent = line.apply(value); + + if (lineComponent.getContents() == ComponentContents.EMPTY) + continue; + if (!first) concatenatedTooltip.append("\n"); first = false; - concatenatedTooltip.append(line.apply(value)); + concatenatedTooltip.append(lineComponent); } return concatenatedTooltip; -- cgit