aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-12-17 23:07:06 +0100
committerLinnea Gräf <nea@nea.moe>2024-12-17 23:07:06 +0100
commita046b198645811fe1b7db129942505c379aabb03 (patch)
treed97e68b1cf3a272aec5d8dd863b82fb0c9b0dc82 /src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt
parenta2f73de90fb9c9d0ea7a5e7e9e6b9e445a8094ee (diff)
downloadLocalTransactionLedger-a046b198645811fe1b7db129942505c379aabb03.tar.gz
LocalTransactionLedger-a046b198645811fe1b7db129942505c379aabb03.tar.bz2
LocalTransactionLedger-a046b198645811fe1b7db129942505c379aabb03.zip
feat: Add name prefetchingHEADmaster
Diffstat (limited to 'src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt')
-rw-r--r--src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt b/src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt
index 121586e..a84aac8 100644
--- a/src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt
+++ b/src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt
@@ -3,6 +3,8 @@ package moe.nea.ledger
import moe.nea.ledger.events.BeforeGuiAction
import moe.nea.ledger.events.ExtraSupplyIdEvent
import moe.nea.ledger.events.RegistrationFinishedEvent
+import moe.nea.ledger.events.SupplyDebugInfo
+import moe.nea.ledger.modules.ExternalDataProvider
import net.minecraft.client.Minecraft
import net.minecraft.item.ItemStack
import net.minecraft.nbt.NBTTagCompound
@@ -28,6 +30,13 @@ class ItemIdProvider {
private val knownNames = mutableMapOf<String, ItemId>()
@SubscribeEvent
+ fun onDataLoaded(event: ExternalDataProvider.DataLoaded) {
+ event.provider.itemNames.forEach { (itemId, itemName) ->
+ knownNames[itemName.unformattedString().trim()] = ItemId(itemId)
+ }
+ }
+
+ @SubscribeEvent
fun onRegistrationFinished(event: RegistrationFinishedEvent) {
MinecraftForge.EVENT_BUS.post(ExtraSupplyIdEvent(knownNames::put))
}
@@ -40,6 +49,11 @@ class ItemIdProvider {
inventory.armorInventory?.forEach { saveFromSlot(it) }
}
+ @SubscribeEvent
+ fun onDebugData(event: SupplyDebugInfo) {
+ event.record("knownItemNames", knownNames.size)
+ }
+
fun saveFromSlot(stack: ItemStack?, preprocessName: (String) -> String = { it }) {
if (stack == null) return
val nbt = stack.tagCompound ?: NBTTagCompound()