10
10
import com .mojang .serialization .Codec ;
11
11
import com .mojang .serialization .JsonOps ;
12
12
import com .mojang .serialization .codecs .RecordCodecBuilder ;
13
- import de .hysky .skyblocker .skyblock .item .tooltip .adders .ObtainedDateTooltip ;
14
13
import de .hysky .skyblocker .SkyblockerMod ;
15
14
import de .hysky .skyblocker .skyblock .item .tooltip .TooltipInfoType ;
15
+ import de .hysky .skyblocker .skyblock .item .tooltip .adders .ObtainedDateTooltip ;
16
16
import it .unimi .dsi .fastutil .doubles .DoubleBooleanPair ;
17
17
import it .unimi .dsi .fastutil .ints .IntIntPair ;
18
18
import it .unimi .dsi .fastutil .longs .LongBooleanPair ;
@@ -62,8 +62,13 @@ public static LiteralArgumentBuilder<FabricClientCommandSource> dumpHeldItemComm
62
62
});
63
63
}
64
64
65
+ /**
66
+ * Gets the nbt in the custom data component of the item stack.
67
+ * @return The {@link DataComponentTypes#CUSTOM_DATA custom data} of the itemstack,
68
+ * or an empty {@link NbtCompound} if the itemstack is missing a custom data component
69
+ */
65
70
@ SuppressWarnings ("deprecation" )
66
- public static NbtCompound getCustomData (@ NotNull ComponentHolder stack ) {
71
+ public static @ NotNull NbtCompound getCustomData (@ NotNull ComponentHolder stack ) {
67
72
return stack .getOrDefault (DataComponentTypes .CUSTOM_DATA , NbtComponent .DEFAULT ).getNbt ();
68
73
}
69
74
@@ -73,7 +78,7 @@ public static NbtCompound getCustomData(@NotNull ComponentHolder stack) {
73
78
* @param stack the item stack to get the internal name from
74
79
* @return an optional containing the internal name of the item stack
75
80
*/
76
- public static Optional <String > getItemIdOptional (@ NotNull ItemStack stack ) {
81
+ public static @ NotNull Optional <String > getItemIdOptional (@ NotNull ItemStack stack ) {
77
82
NbtCompound customData = getCustomData (stack );
78
83
return customData .contains (ID ) ? Optional .of (customData .getString (ID )) : Optional .empty ();
79
84
}
@@ -84,7 +89,7 @@ public static Optional<String> getItemIdOptional(@NotNull ItemStack stack) {
84
89
* @param stack the item stack to get the internal name from
85
90
* @return the internal name of the item stack, or an empty string if the item stack is null or does not have an internal name
86
91
*/
87
- public static String getItemId (@ NotNull ItemStack stack ) {
92
+ public static @ NotNull String getItemId (@ NotNull ItemStack stack ) {
88
93
return getCustomData (stack ).getString (ID );
89
94
}
90
95
@@ -94,7 +99,7 @@ public static String getItemId(@NotNull ItemStack stack) {
94
99
* @param stack the item stack to get the UUID from
95
100
* @return an optional containing the UUID of the item stack
96
101
*/
97
- public static Optional <String > getItemUuidOptional (@ NotNull ItemStack stack ) {
102
+ public static @ NotNull Optional <String > getItemUuidOptional (@ NotNull ItemStack stack ) {
98
103
NbtCompound customData = getCustomData (stack );
99
104
return customData .contains (UUID ) ? Optional .of (customData .getString (UUID )) : Optional .empty ();
100
105
}
@@ -105,7 +110,7 @@ public static Optional<String> getItemUuidOptional(@NotNull ItemStack stack) {
105
110
* @param stack the item stack to get the UUID from
106
111
* @return the UUID of the item stack, or an empty string if the item stack is null or does not have a UUID
107
112
*/
108
- public static String getItemUuid (@ NotNull ComponentHolder stack ) {
113
+ public static @ NotNull String getItemUuid (@ NotNull ComponentHolder stack ) {
109
114
return getCustomData (stack ).getString (UUID );
110
115
}
111
116
@@ -115,7 +120,7 @@ public static String getItemUuid(@NotNull ComponentHolder stack) {
115
120
* @return An {@link LongBooleanPair} with the {@code left long} representing the item's price,
116
121
* and the {@code right boolean} indicating if the price was based on complete data.
117
122
*/
118
- public static DoubleBooleanPair getItemPrice (@ NotNull ItemStack stack ) {
123
+ public static @ NotNull DoubleBooleanPair getItemPrice (@ NotNull ItemStack stack ) {
119
124
return getItemPrice (getItemId (stack ));
120
125
}
121
126
@@ -125,7 +130,7 @@ public static DoubleBooleanPair getItemPrice(@NotNull ItemStack stack) {
125
130
* @return An {@link LongBooleanPair} with the {@code left long} representing the item's price,
126
131
* and the {@code right boolean} indicating if the price was based on complete data.
127
132
*/
128
- public static DoubleBooleanPair getItemPrice (@ Nullable String id ) {
133
+ public static @ NotNull DoubleBooleanPair getItemPrice (@ Nullable String id ) {
129
134
JsonObject bazaarPrices = TooltipInfoType .BAZAAR .getData ();
130
135
JsonObject lowestBinPrices = TooltipInfoType .LOWEST_BINS .getData ();
131
136
@@ -168,15 +173,15 @@ public static String getTimestamp(ItemStack stack) {
168
173
169
174
public static boolean hasCustomDurability (@ NotNull ItemStack stack ) {
170
175
NbtCompound customData = getCustomData (stack );
171
- return customData != null && (customData .contains ("drill_fuel" ) || customData .getString (ID ).equals ("PICKONIMBUS" ));
176
+ return ! customData . isEmpty () && (customData .contains ("drill_fuel" ) || customData .getString (ID ).equals ("PICKONIMBUS" ));
172
177
}
173
178
174
179
@ Nullable
175
180
public static IntIntPair getDurability (@ NotNull ItemStack stack ) {
176
181
NbtCompound customData = getCustomData (stack );
177
- if (customData == null ) return null ;
182
+ if (customData . isEmpty () ) return null ;
178
183
179
- // TODO Calculate drill durability based on the drill_fuel flag, fuel_tank flag, and hotm level
184
+ // TODO Calculate drill durability based on the drill_fuel flag, fuel_tank flag, and hotm level
180
185
// TODO Cache the max durability and only update the current durability on inventory tick
181
186
182
187
int pickonimbusDurability = customData .getInt ("pickonimbus_durability" );
@@ -218,15 +223,15 @@ public static Matcher getLoreLineIfMatch(ItemStack item, Pattern pattern) {
218
223
return null ;
219
224
}
220
225
221
- public static List <Text > getLore (ItemStack item ) {
226
+ public static @ NotNull List <Text > getLore (ItemStack item ) {
222
227
return item .getOrDefault (DataComponentTypes .LORE , LoreComponent .DEFAULT ).styledLines ();
223
228
}
224
229
225
- public static PropertyMap propertyMapWithTexture (String textureValue ) {
230
+ public static @ NotNull PropertyMap propertyMapWithTexture (String textureValue ) {
226
231
return Codecs .GAME_PROFILE_PROPERTY_MAP .parse (JsonOps .INSTANCE , JsonParser .parseString ("[{\" name\" :\" textures\" ,\" value\" :\" " + textureValue + "\" }]" )).getOrThrow ();
227
232
}
228
233
229
- public static String getHeadTexture (ItemStack stack ) {
234
+ public static @ NotNull String getHeadTexture (@ NotNull ItemStack stack ) {
230
235
if (!stack .isOf (Items .PLAYER_HEAD ) || !stack .contains (DataComponentTypes .PROFILE )) return "" ;
231
236
232
237
ProfileComponent profile = stack .get (DataComponentTypes .PROFILE );
@@ -238,13 +243,13 @@ public static String getHeadTexture(ItemStack stack) {
238
243
.orElse ("" );
239
244
}
240
245
241
- public static Optional <String > getHeadTextureOptional (ItemStack stack ) {
246
+ public static @ NotNull Optional <String > getHeadTextureOptional (ItemStack stack ) {
242
247
String texture = getHeadTexture (stack );
243
248
if (texture .isBlank ()) return Optional .empty ();
244
249
return Optional .of (texture );
245
250
}
246
251
247
- public static ItemStack getSkyblockerStack () {
252
+ public static @ NotNull ItemStack getSkyblockerStack () {
248
253
try {
249
254
ItemStack stack = new ItemStack (Items .PLAYER_HEAD );
250
255
stack .set (DataComponentTypes .PROFILE , new ProfileComponent (Optional .of ("SkyblockerStack" ), Optional .of (java .util .UUID .randomUUID ()), propertyMapWithTexture ("e3RleHR1cmVzOntTS0lOOnt1cmw6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDdjYzY2ODc0MjNkMDU3MGQ1NTZhYzUzZTA2NzZjYjU2M2JiZGQ5NzE3Y2Q4MjY5YmRlYmVkNmY2ZDRlN2JmOCJ9fX0=" )));
0 commit comments