diff options
author | Linnea Gräf <nea@nea.moe> | 2024-12-19 22:13:32 +0100 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-12-19 22:13:32 +0100 |
commit | 175379be77dd530bc019e34d3937950df22e4f8a (patch) | |
tree | 26667fda120efefa857655583f622f170856bd38 /src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt | |
parent | 7c4b2e089fa23622799bc06a08f6932197365368 (diff) | |
download | LocalTransactionLedger-175379be77dd530bc019e34d3937950df22e4f8a.tar.gz LocalTransactionLedger-175379be77dd530bc019e34d3937950df22e4f8a.tar.bz2 LocalTransactionLedger-175379be77dd530bc019e34d3937950df22e4f8a.zip |
feat: Items bought for other items at NPCs
Diffstat (limited to 'src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt')
-rw-r--r-- | src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt b/src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt index 30610e9..72f1d09 100644 --- a/src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt +++ b/src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt @@ -29,16 +29,24 @@ class ItemIdProvider { private val knownNames = mutableMapOf<String, ItemId>() + fun createLookupTagFromDisplayName(itemName: String): String { + return itemName.unformattedString().trim().lowercase() + } + + fun saveKnownItem(itemName: String, itemId: ItemId) { + knownNames[createLookupTagFromDisplayName(itemName)] = itemId + } + @SubscribeEvent fun onDataLoaded(event: ExternalDataProvider.DataLoaded) { event.provider.itemNames.forEach { (itemId, itemName) -> - knownNames[itemName.unformattedString().trim()] = ItemId(itemId) + saveKnownItem(itemName, ItemId(itemId)) } } @SubscribeEvent fun onRegistrationFinished(event: RegistrationFinishedEvent) { - MinecraftForge.EVENT_BUS.post(ExtraSupplyIdEvent(knownNames::put)) + MinecraftForge.EVENT_BUS.post(ExtraSupplyIdEvent(::saveKnownItem)) } @SubscribeEvent(priority = EventPriority.HIGH) @@ -63,7 +71,7 @@ class ItemIdProvider { name = name.trim() val id = stack.getInternalId() if (id != null && name.isNotBlank()) { - knownNames[name] = id + saveKnownItem(name, id) } } @@ -84,7 +92,7 @@ class ItemIdProvider { // TODO: make use of colour fun findForName(name: String, fallbackToGenerated: Boolean = true): ItemId? { - var id = knownNames[name] + var id = knownNames[createLookupTagFromDisplayName(name)] if (id == null && fallbackToGenerated) { id = generateName(name) } |