|
7 | 7 | import dev.isxander.yacl.api.OptionFlag; |
8 | 8 | import net.minecraft.ChatFormatting; |
9 | 9 | import net.minecraft.network.chat.Component; |
| 10 | +import net.minecraft.network.chat.ComponentContents; |
10 | 11 | import net.minecraft.network.chat.MutableComponent; |
11 | 12 | import org.apache.commons.lang3.Validate; |
12 | 13 | import org.jetbrains.annotations.ApiStatus; |
@@ -195,9 +196,11 @@ public final Option.Builder<T> tooltip(@NotNull Function<T, Component>... toolti |
195 | 196 |
|
196 | 197 | @Override |
197 | 198 | public Option.Builder<T> tooltip(@NotNull Component... tooltips) { |
198 | | - Validate.notNull(tooltips, "`tooltips` cannot be empty"); |
| 199 | + var tooltipFunctions = Arrays.stream(tooltips) |
| 200 | + .map(t -> (Function<T, Component>) opt -> t) |
| 201 | + .toList(); |
199 | 202 |
|
200 | | - this.tooltipGetters.addAll(Stream.of(tooltips).map(Component -> (Function<T, Component>) t -> Component).toList()); |
| 203 | + this.tooltipGetters.addAll(tooltipFunctions); |
201 | 204 | return this; |
202 | 205 | } |
203 | 206 |
|
@@ -277,10 +280,15 @@ public Option<T> build() { |
277 | 280 | MutableComponent concatenatedTooltip = Component.empty(); |
278 | 281 | boolean first = true; |
279 | 282 | for (Function<T, Component> line : tooltipGetters) { |
| 283 | + Component lineComponent = line.apply(value); |
| 284 | + |
| 285 | + if (lineComponent.getContents() == ComponentContents.EMPTY) |
| 286 | + continue; |
| 287 | + |
280 | 288 | if (!first) concatenatedTooltip.append("\n"); |
281 | 289 | first = false; |
282 | 290 |
|
283 | | - concatenatedTooltip.append(line.apply(value)); |
| 291 | + concatenatedTooltip.append(lineComponent); |
284 | 292 | } |
285 | 293 |
|
286 | 294 | return concatenatedTooltip; |
|
0 commit comments