aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java
diff options
context:
space:
mode:
authorKevin <92656833+kevinthegreat1@users.noreply.github.com>2023-10-17 18:15:19 -0400
committerGitHub <noreply@github.com>2023-10-17 18:15:19 -0400
commitbf10b5a1337d887886f2490927951a5f82532b3a (patch)
tree6f514dcd172dfc63086724d6837569e9aa25e34d /src/main/java/de/hysky/skyblocker/utils/ItemUtils.java
parent7c572db73914cbdbfbd5e38325a8c09a27935e33 (diff)
downloadSkyblocker-bf10b5a1337d887886f2490927951a5f82532b3a.tar.gz
Skyblocker-bf10b5a1337d887886f2490927951a5f82532b3a.tar.bz2
Skyblocker-bf10b5a1337d887886f2490927951a5f82532b3a.zip
Optimize drill fuel and picko durability with caching (#366)
Diffstat (limited to 'src/main/java/de/hysky/skyblocker/utils/ItemUtils.java')
-rw-r--r--src/main/java/de/hysky/skyblocker/utils/ItemUtils.java26
1 files changed, 10 insertions, 16 deletions
diff --git a/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java b/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java
index fa04acf8..50a9bcd1 100644
--- a/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java
+++ b/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java
@@ -1,7 +1,7 @@
package de.hysky.skyblocker.utils;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
-import de.hysky.skyblocker.config.SkyblockerConfigManager;
+import it.unimi.dsi.fastutil.ints.IntIntPair;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.item.ItemStack;
@@ -105,21 +105,18 @@ public class ItemUtils {
return extraAttributes != null ? extraAttributes.getString(UUID) : "";
}
- @Nullable
- public static Durability getDurability(@NotNull ItemStack stack) {
- if (!Utils.isOnSkyblock() || !SkyblockerConfigManager.get().locations.dwarvenMines.enableDrillFuel || stack.isEmpty()) {
- return null;
- }
-
- if (getExtraAttributesOptional(stack).filter(extraAttributes -> extraAttributes.contains("drill_fuel") || extraAttributes.getString(ItemUtils.ID).equals("PICKONIMBUS")).isEmpty()) {
- return null;
- }
+ public static boolean hasCustomDurability(@NotNull ItemStack stack) {
+ NbtCompound extraAttributes = getExtraAttributes(stack);
+ return extraAttributes != null && (extraAttributes.contains("drill_fuel") || extraAttributes.getString(ID).equals("PICKONIMBUS"));
+ }
+ @Nullable
+ public static IntIntPair getDurability(@NotNull ItemStack stack) {
int current = 0;
int max = 0;
String clearFormatting;
- for (String line : ItemUtils.getTooltipStrings(stack)) {
+ for (String line : getTooltipStrings(stack)) {
clearFormatting = Formatting.strip(line);
if (line.contains("Fuel: ")) {
if (clearFormatting != null) {
@@ -127,7 +124,7 @@ public class ItemUtils {
String[] split = clear.split("/");
current = Integer.parseInt(split[0]);
max = Integer.parseInt(split[1]) * 1000;
- return new Durability(current, max);
+ return IntIntPair.of(current, max);
}
} else if (line.contains("uses.")) {
if (clearFormatting != null) {
@@ -138,7 +135,7 @@ public class ItemUtils {
current = Integer.parseInt(usesString);
max = 5000;
}
- return new Durability(current, max);
+ return IntIntPair.of(current, max);
}
}
}
@@ -153,7 +150,4 @@ public class ItemUtils {
throw new RuntimeException(e);
}
}
-
- public record Durability(int current, int max) {
- }
}