Skip to content

Commit 2e6be45

Browse files
committed
fix: move inventory button cache around
1 parent a46fc56 commit 2e6be45

File tree

1 file changed

+29
-22
lines changed

1 file changed

+29
-22
lines changed

src/main/kotlin/features/inventory/buttons/InventoryButton.kt

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -50,33 +50,40 @@ data class InventoryButton(
5050
val dimensions = Dimension(18, 18)
5151
val gap = 2
5252
val bigDimension = Dimension(dimensions.width * 2 + gap, dimensions.height * 2 + gap)
53-
val getItemForName = ::getItemForName0.memoize(1024)
53+
val getCustomItem = ::getCustomItem0.memoize(500)
54+
55+
56+
57+
fun getCustomItem0(icon: String): ItemStack? {
58+
when {
59+
icon.startsWith("skull:") -> {
60+
return createSkullItem(
61+
arbitraryUUID,
62+
"https://textures.minecraft.net/texture/${icon.substring("skull:".length)}"
63+
)
64+
}
65+
66+
else -> {
67+
val giveSyntaxItem = if (icon.startsWith("/give") || icon.startsWith("give"))
68+
icon.split(" ", limit = 3).getOrNull(2) ?: icon
69+
else icon
70+
val componentItem =
71+
runCatching {
72+
itemStackParser.parse(StringReader(giveSyntaxItem)).createItemStack(1, false)
73+
}.getOrNull()
74+
return componentItem
75+
}
76+
}
77+
}
5478

5579
@OptIn(ExpensiveItemCacheApi::class)
56-
fun getItemForName0(icon: String): ItemStack {
80+
fun getItemForName(icon: String): ItemStack {
5781
val repoItem = RepoManager.getNEUItem(SkyblockId(icon))
5882
var itemStack = repoItem.asItemStack(idHint = SkyblockId(icon))
5983
if (repoItem == null) {
60-
when {
61-
icon.startsWith("skull:") -> {
62-
itemStack = createSkullItem(
63-
arbitraryUUID,
64-
"https://textures.minecraft.net/texture/${icon.substring("skull:".length)}"
65-
)
66-
}
67-
68-
else -> {
69-
val giveSyntaxItem = if (icon.startsWith("/give") || icon.startsWith("give"))
70-
icon.split(" ", limit = 3).getOrNull(2) ?: icon
71-
else icon
72-
val componentItem =
73-
runCatching {
74-
itemStackParser.parse(StringReader(giveSyntaxItem)).createItemStack(1, false)
75-
}.getOrNull()
76-
if (componentItem != null)
77-
itemStack = componentItem
78-
}
79-
}
84+
val customItem = getCustomItem(icon)
85+
if (customItem != null)
86+
itemStack = customItem
8087
}
8188
if (itemStack.item == Items.PAINTING)
8289
ErrorUtil.logError("created broken itemstack for inventory button $icon: $itemStack")

0 commit comments

Comments
 (0)