Skip to content

Commit 288151a

Browse files
Merge pull request SkyblockerMod#817 from Emirlol/fix-pet-slot-text
Fix PetLevelAdder working incorrectly in the sea creatures guide
2 parents 7b02937 + a004952 commit 288151a

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/PetLevelAdder.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
import de.hysky.skyblocker.skyblock.item.slottext.SlotText;
44
import de.hysky.skyblocker.skyblock.item.slottext.SlotTextAdder;
5+
import de.hysky.skyblocker.utils.ItemUtils;
56
import net.minecraft.item.ItemStack;
67
import net.minecraft.item.Items;
78
import net.minecraft.screen.slot.Slot;
89
import net.minecraft.text.Text;
9-
import net.minecraft.util.Formatting;
1010
import org.apache.commons.lang3.math.NumberUtils;
1111
import org.jetbrains.annotations.NotNull;
1212

@@ -22,8 +22,8 @@ public PetLevelAdder() {
2222
ItemStack itemStack = slot.getStack();
2323
if (!itemStack.isOf(Items.PLAYER_HEAD)) return List.of();
2424
String level = CatacombsLevelAdder.getBracketedLevelFromName(itemStack);
25-
if (!NumberUtils.isDigits(level)) return List.of();
26-
if ("100".equals(level) || "200".equals(level)) return List.of();
25+
if (!NumberUtils.isDigits(level) || "100".equals(level) || "200".equals(level)) return List.of();
26+
if (!ItemUtils.getItemId(itemStack).equals("PET")) return List.of();
2727
return List.of(SlotText.topLeft(Text.literal(level).withColor(0xFFDDC1)));
2828
}
2929
}

src/main/java/de/hysky/skyblocker/utils/ItemUtils.java

+21-16
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
import com.mojang.serialization.Codec;
1111
import com.mojang.serialization.JsonOps;
1212
import com.mojang.serialization.codecs.RecordCodecBuilder;
13-
import de.hysky.skyblocker.skyblock.item.tooltip.adders.ObtainedDateTooltip;
1413
import de.hysky.skyblocker.SkyblockerMod;
1514
import de.hysky.skyblocker.skyblock.item.tooltip.TooltipInfoType;
15+
import de.hysky.skyblocker.skyblock.item.tooltip.adders.ObtainedDateTooltip;
1616
import it.unimi.dsi.fastutil.doubles.DoubleBooleanPair;
1717
import it.unimi.dsi.fastutil.ints.IntIntPair;
1818
import it.unimi.dsi.fastutil.longs.LongBooleanPair;
@@ -62,8 +62,13 @@ public static LiteralArgumentBuilder<FabricClientCommandSource> dumpHeldItemComm
6262
});
6363
}
6464

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+
*/
6570
@SuppressWarnings("deprecation")
66-
public static NbtCompound getCustomData(@NotNull ComponentHolder stack) {
71+
public static @NotNull NbtCompound getCustomData(@NotNull ComponentHolder stack) {
6772
return stack.getOrDefault(DataComponentTypes.CUSTOM_DATA, NbtComponent.DEFAULT).getNbt();
6873
}
6974

@@ -73,7 +78,7 @@ public static NbtCompound getCustomData(@NotNull ComponentHolder stack) {
7378
* @param stack the item stack to get the internal name from
7479
* @return an optional containing the internal name of the item stack
7580
*/
76-
public static Optional<String> getItemIdOptional(@NotNull ItemStack stack) {
81+
public static @NotNull Optional<String> getItemIdOptional(@NotNull ItemStack stack) {
7782
NbtCompound customData = getCustomData(stack);
7883
return customData.contains(ID) ? Optional.of(customData.getString(ID)) : Optional.empty();
7984
}
@@ -84,7 +89,7 @@ public static Optional<String> getItemIdOptional(@NotNull ItemStack stack) {
8489
* @param stack the item stack to get the internal name from
8590
* @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
8691
*/
87-
public static String getItemId(@NotNull ItemStack stack) {
92+
public static @NotNull String getItemId(@NotNull ItemStack stack) {
8893
return getCustomData(stack).getString(ID);
8994
}
9095

@@ -94,7 +99,7 @@ public static String getItemId(@NotNull ItemStack stack) {
9499
* @param stack the item stack to get the UUID from
95100
* @return an optional containing the UUID of the item stack
96101
*/
97-
public static Optional<String> getItemUuidOptional(@NotNull ItemStack stack) {
102+
public static @NotNull Optional<String> getItemUuidOptional(@NotNull ItemStack stack) {
98103
NbtCompound customData = getCustomData(stack);
99104
return customData.contains(UUID) ? Optional.of(customData.getString(UUID)) : Optional.empty();
100105
}
@@ -105,7 +110,7 @@ public static Optional<String> getItemUuidOptional(@NotNull ItemStack stack) {
105110
* @param stack the item stack to get the UUID from
106111
* @return the UUID of the item stack, or an empty string if the item stack is null or does not have a UUID
107112
*/
108-
public static String getItemUuid(@NotNull ComponentHolder stack) {
113+
public static @NotNull String getItemUuid(@NotNull ComponentHolder stack) {
109114
return getCustomData(stack).getString(UUID);
110115
}
111116

@@ -115,7 +120,7 @@ public static String getItemUuid(@NotNull ComponentHolder stack) {
115120
* @return An {@link LongBooleanPair} with the {@code left long} representing the item's price,
116121
* and the {@code right boolean} indicating if the price was based on complete data.
117122
*/
118-
public static DoubleBooleanPair getItemPrice(@NotNull ItemStack stack) {
123+
public static @NotNull DoubleBooleanPair getItemPrice(@NotNull ItemStack stack) {
119124
return getItemPrice(getItemId(stack));
120125
}
121126

@@ -125,7 +130,7 @@ public static DoubleBooleanPair getItemPrice(@NotNull ItemStack stack) {
125130
* @return An {@link LongBooleanPair} with the {@code left long} representing the item's price,
126131
* and the {@code right boolean} indicating if the price was based on complete data.
127132
*/
128-
public static DoubleBooleanPair getItemPrice(@Nullable String id) {
133+
public static @NotNull DoubleBooleanPair getItemPrice(@Nullable String id) {
129134
JsonObject bazaarPrices = TooltipInfoType.BAZAAR.getData();
130135
JsonObject lowestBinPrices = TooltipInfoType.LOWEST_BINS.getData();
131136

@@ -168,15 +173,15 @@ public static String getTimestamp(ItemStack stack) {
168173

169174
public static boolean hasCustomDurability(@NotNull ItemStack stack) {
170175
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"));
172177
}
173178

174179
@Nullable
175180
public static IntIntPair getDurability(@NotNull ItemStack stack) {
176181
NbtCompound customData = getCustomData(stack);
177-
if (customData == null) return null;
182+
if (customData.isEmpty()) return null;
178183

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
180185
// TODO Cache the max durability and only update the current durability on inventory tick
181186

182187
int pickonimbusDurability = customData.getInt("pickonimbus_durability");
@@ -218,15 +223,15 @@ public static Matcher getLoreLineIfMatch(ItemStack item, Pattern pattern) {
218223
return null;
219224
}
220225

221-
public static List<Text> getLore(ItemStack item) {
226+
public static @NotNull List<Text> getLore(ItemStack item) {
222227
return item.getOrDefault(DataComponentTypes.LORE, LoreComponent.DEFAULT).styledLines();
223228
}
224229

225-
public static PropertyMap propertyMapWithTexture(String textureValue) {
230+
public static @NotNull PropertyMap propertyMapWithTexture(String textureValue) {
226231
return Codecs.GAME_PROFILE_PROPERTY_MAP.parse(JsonOps.INSTANCE, JsonParser.parseString("[{\"name\":\"textures\",\"value\":\"" + textureValue + "\"}]")).getOrThrow();
227232
}
228233

229-
public static String getHeadTexture(ItemStack stack) {
234+
public static @NotNull String getHeadTexture(@NotNull ItemStack stack) {
230235
if (!stack.isOf(Items.PLAYER_HEAD) || !stack.contains(DataComponentTypes.PROFILE)) return "";
231236

232237
ProfileComponent profile = stack.get(DataComponentTypes.PROFILE);
@@ -238,13 +243,13 @@ public static String getHeadTexture(ItemStack stack) {
238243
.orElse("");
239244
}
240245

241-
public static Optional<String> getHeadTextureOptional(ItemStack stack) {
246+
public static @NotNull Optional<String> getHeadTextureOptional(ItemStack stack) {
242247
String texture = getHeadTexture(stack);
243248
if (texture.isBlank()) return Optional.empty();
244249
return Optional.of(texture);
245250
}
246251

247-
public static ItemStack getSkyblockerStack() {
252+
public static @NotNull ItemStack getSkyblockerStack() {
248253
try {
249254
ItemStack stack = new ItemStack(Items.PLAYER_HEAD);
250255
stack.set(DataComponentTypes.PROFILE, new ProfileComponent(Optional.of("SkyblockerStack"), Optional.of(java.util.UUID.randomUUID()), propertyMapWithTexture("e3RleHR1cmVzOntTS0lOOnt1cmw6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDdjYzY2ODc0MjNkMDU3MGQ1NTZhYzUzZTA2NzZjYjU2M2JiZGQ5NzE3Y2Q4MjY5YmRlYmVkNmY2ZDRlN2JmOCJ9fX0=")));

0 commit comments

Comments
 (0)