aboutsummaryrefslogtreecommitdiff
path: root/src/client/java/dev/isxander/yacl/impl
diff options
context:
space:
mode:
authorisXander <xandersmith2008@gmail.com>2023-04-21 22:59:08 +0100
committerisXander <xandersmith2008@gmail.com>2023-04-21 22:59:08 +0100
commit25f8d0bacf274870c512cb6b867a55af57714fb5 (patch)
treeb772d3ca4103eef7544c44b7248088b3a10e18ff /src/client/java/dev/isxander/yacl/impl
parent74bcc11c74f864eda2f5e48a3c038846c20065ba (diff)
downloadYetAnotherConfigLib-25f8d0bacf274870c512cb6b867a55af57714fb5.tar.gz
YetAnotherConfigLib-25f8d0bacf274870c512cb6b867a55af57714fb5.tar.bz2
YetAnotherConfigLib-25f8d0bacf274870c512cb6b867a55af57714fb5.zip
prioritise tooltip rendering above & filter empty tooltips
Diffstat (limited to 'src/client/java/dev/isxander/yacl/impl')
-rw-r--r--src/client/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java4
-rw-r--r--src/client/java/dev/isxander/yacl/impl/OptionGroupImpl.java4
-rw-r--r--src/client/java/dev/isxander/yacl/impl/OptionImpl.java14
3 files changed, 19 insertions, 3 deletions
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<T> implements Option<T> {
@Override
public Option.Builder<T> tooltip(@NotNull Component... tooltips) {
- Validate.notNull(tooltips, "`tooltips` cannot be empty");
+ var tooltipFunctions = Arrays.stream(tooltips)
+ .map(t -> (Function<T, Component>) opt -> t)
+ .toList();
- this.tooltipGetters.addAll(Stream.of(tooltips).map(Component -> (Function<T, Component>) t -> Component).toList());
+ this.tooltipGetters.addAll(tooltipFunctions);
return this;
}
@@ -277,10 +280,15 @@ public final class OptionImpl<T> implements Option<T> {
MutableComponent concatenatedTooltip = Component.empty();
boolean first = true;
for (Function<T, Component> 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;