Skip to content

Commit 0c473dc

Browse files
Merge branch 'dev' into ver/2.x
2 parents a08074a + 35c436e commit 0c473dc

3 files changed

Lines changed: 76 additions & 15 deletions

File tree

buildSrc/src/main/kotlin/invui.common-conventions.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ plugins {
99
val libs = the<LibrariesForLibs>()
1010

1111
group = "xyz.xenondevs.invui"
12-
version = "2.0.0-alpha.7"
12+
version = "2.0.0-alpha.8"
1313

1414
repositories {
1515
mavenCentral()

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[versions]
22
kotlin = "2.1.0"
3-
paper = "1.21.4-R0.1-SNAPSHOT"
3+
paper = "1.21.5-no-moonrise-SNAPSHOT"
44

55
[libraries]
66
commons-provider = { module = "xyz.xenondevs.commons:commons-provider", version = "1.25" }

invui/src/main/java/xyz/xenondevs/invui/item/ItemBuilder.java

Lines changed: 74 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package xyz.xenondevs.invui.item;
22

3+
import com.google.common.collect.Sets;
34
import io.papermc.paper.datacomponent.DataComponentBuilder;
45
import io.papermc.paper.datacomponent.DataComponentType;
56
import io.papermc.paper.datacomponent.DataComponentTypes;
67
import io.papermc.paper.datacomponent.item.ItemLore;
8+
import io.papermc.paper.datacomponent.item.TooltipDisplay;
79
import it.unimi.dsi.fastutil.booleans.BooleanArrayList;
810
import it.unimi.dsi.fastutil.booleans.BooleanList;
911
import it.unimi.dsi.fastutil.floats.FloatArrayList;
@@ -24,6 +26,7 @@
2426
import org.bukkit.inventory.ItemStack;
2527
import org.jspecify.annotations.Nullable;
2628
import xyz.xenondevs.invui.i18n.Languages;
29+
import xyz.xenondevs.invui.internal.util.ArrayUtils;
2730
import xyz.xenondevs.invui.internal.util.ComponentUtils;
2831

2932
import java.util.*;
@@ -433,7 +436,7 @@ public ItemBuilder setCustomName(Component customName) {
433436
this.customName = new DirectComponentHolder(customName);
434437
this.name = null;
435438
unset(DataComponentTypes.ITEM_NAME);
436-
unset(DataComponentTypes.HIDE_TOOLTIP);
439+
hideTooltip(false);
437440
return this;
438441
}
439442

@@ -451,7 +454,7 @@ public ItemBuilder setCustomName(String customName) {
451454
this.customName = new MiniMessageComponentHolder(customName);
452455
this.name = null;
453456
unset(DataComponentTypes.ITEM_NAME);
454-
unset(DataComponentTypes.HIDE_TOOLTIP);
457+
hideTooltip(false);
455458
return this;
456459
}
457460

@@ -511,7 +514,7 @@ public ItemBuilder setLore(List<Component> lore) {
511514
this.lore = lore.stream()
512515
.map(DirectComponentHolder::new)
513516
.collect(Collectors.toCollection(ArrayList::new));
514-
unset(DataComponentTypes.HIDE_TOOLTIP);
517+
hideTooltip(false);
515518
return this;
516519
}
517520

@@ -529,7 +532,7 @@ public ItemBuilder setLegacyLore(List<String> lore) {
529532
.map(line -> legacySection().deserialize(line))
530533
.map(DirectComponentHolder::new)
531534
.collect(Collectors.toCollection(ArrayList::new));
532-
unset(DataComponentTypes.HIDE_TOOLTIP);
535+
hideTooltip(false);
533536
return this;
534537
}
535538

@@ -572,7 +575,7 @@ public ItemBuilder addLoreLines(Component... lines) {
572575
lore.add(new DirectComponentHolder(line));
573576
}
574577

575-
unset(DataComponentTypes.HIDE_TOOLTIP);
578+
hideTooltip(false);
576579

577580
return this;
578581
}
@@ -594,7 +597,7 @@ public ItemBuilder addLoreLines(List<Component> lines) {
594597
lore.add(new DirectComponentHolder(line));
595598
}
596599

597-
unset(DataComponentTypes.HIDE_TOOLTIP);
600+
hideTooltip(false);
598601

599602
return this;
600603
}
@@ -616,7 +619,7 @@ public ItemBuilder addMiniMessageLoreLines(List<String> lines) {
616619
lore.add(new MiniMessageComponentHolder(line));
617620
}
618621

619-
unset(DataComponentTypes.HIDE_TOOLTIP);
622+
hideTooltip(false);
620623

621624
return this;
622625
}
@@ -638,7 +641,7 @@ public ItemBuilder addLegacyLoreLines(List<String> lines) {
638641
lore.add(new DirectComponentHolder(legacySection().deserialize(line)));
639642
}
640643

641-
unset(DataComponentTypes.HIDE_TOOLTIP);
644+
hideTooltip(false);
642645

643646
return this;
644647
}
@@ -1058,11 +1061,69 @@ public ItemBuilder clearCustomModelData() {
10581061
public ItemBuilder hideTooltip(boolean hide) {
10591062
buildCache.clear();
10601063

1061-
if (hide) {
1062-
itemStack.setData(DataComponentTypes.HIDE_TOOLTIP);
1063-
} else {
1064-
itemStack.unsetData(DataComponentTypes.HIDE_TOOLTIP);
1065-
}
1064+
TooltipDisplay display = itemStack.getData(DataComponentTypes.TOOLTIP_DISPLAY);
1065+
itemStack.setData(
1066+
DataComponentTypes.TOOLTIP_DISPLAY,
1067+
TooltipDisplay.tooltipDisplay()
1068+
.hideTooltip(hide)
1069+
.hiddenComponents(display != null ? display.hiddenComponents() : Set.of())
1070+
.build()
1071+
);
1072+
1073+
return this;
1074+
}
1075+
1076+
/**
1077+
* Hides the tooltip for the given data components.
1078+
*
1079+
* @param type The first data component type to hide the tooltip for
1080+
* @param types Additional data component types to hide the tooltip for
1081+
* @return The builder instance
1082+
* @see #showTooltip(DataComponentType, DataComponentType...)
1083+
* @see #hideTooltip(boolean)
1084+
*/
1085+
public ItemBuilder hideTooltip(DataComponentType type, DataComponentType... types) {
1086+
buildCache.clear();
1087+
1088+
TooltipDisplay display = itemStack.getData(DataComponentTypes.TOOLTIP_DISPLAY);
1089+
itemStack.setData(
1090+
DataComponentTypes.TOOLTIP_DISPLAY,
1091+
TooltipDisplay.tooltipDisplay()
1092+
.hideTooltip(display != null && display.hideTooltip())
1093+
.hiddenComponents(display != null ? display.hiddenComponents() : Set.of())
1094+
.hiddenComponents(Set.of(ArrayUtils.concat(DataComponentType[]::new, type, types)))
1095+
.build()
1096+
);
1097+
1098+
return this;
1099+
}
1100+
1101+
/**
1102+
* Un-hides the tooltip for the given data components that were previously hidden.
1103+
*
1104+
* @param type The first data component type to un-hide the tooltip for
1105+
* @param types Additional data component types to un-hide the tooltip for
1106+
* @return The builder instance
1107+
* @see #hideTooltip(DataComponentType, DataComponentType...)
1108+
* @see #hideTooltip(boolean)
1109+
*/
1110+
public ItemBuilder showTooltip(DataComponentType type, DataComponentType... types) {
1111+
TooltipDisplay display = itemStack.getData(DataComponentTypes.TOOLTIP_DISPLAY);
1112+
if (display == null)
1113+
return this;
1114+
1115+
buildCache.clear();
1116+
1117+
itemStack.setData(
1118+
DataComponentTypes.TOOLTIP_DISPLAY,
1119+
TooltipDisplay.tooltipDisplay()
1120+
.hideTooltip(display.hideTooltip())
1121+
.hiddenComponents(Sets.difference(
1122+
display.hiddenComponents(),
1123+
Set.of(ArrayUtils.concat(DataComponentType[]::new, type, types))
1124+
))
1125+
.build()
1126+
);
10661127

10671128
return this;
10681129
}

0 commit comments

Comments
 (0)