diff options
Diffstat (limited to 'src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt')
-rw-r--r-- | src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt | 14 |
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() |