Fix up most of the remaining event handlers

[no changelog]
This commit is contained in:
Linnea Gräf
2024-05-07 21:11:09 +02:00
parent 8f3cc34740
commit 93e6e0ab16
25 changed files with 760 additions and 713 deletions

View File

@@ -16,6 +16,7 @@ import net.minecraft.client.render.RenderLayer
import net.minecraft.client.util.ModelIdentifier
import net.minecraft.component.type.ProfileComponent
import net.minecraft.util.Identifier
import moe.nea.firmament.annotations.Subscribe
import moe.nea.firmament.events.CustomItemModelEvent
import moe.nea.firmament.events.TickEvent
import moe.nea.firmament.features.FirmamentFeature
@@ -38,20 +39,21 @@ object CustomSkyBlockTextures : FirmamentFeature {
override val config: ManagedConfig
get() = TConfig
override fun onLoad() {
CustomItemModelEvent.subscribe {
if (!TConfig.enabled) return@subscribe
val id = it.itemStack.skyBlockId ?: return@subscribe
it.overrideModel = ModelIdentifier("firmskyblock", id.identifier.path, "inventory")
}
TickEvent.subscribe {
if (TConfig.cacheDuration < 1 || it.tickCount % TConfig.cacheDuration == 0) {
CustomItemModelEvent.clearCache()
skullTextureCache.clear()
}
@Subscribe
fun onTick(it: TickEvent) {
if (TConfig.cacheDuration < 1 || it.tickCount % TConfig.cacheDuration == 0) {
CustomItemModelEvent.clearCache()
skullTextureCache.clear()
}
}
@Subscribe
fun onCustomModelId(it: CustomItemModelEvent) {
if (!TConfig.enabled) return
val id = it.itemStack.skyBlockId ?: return
it.overrideModel = ModelIdentifier("firmskyblock", id.identifier.path, "inventory")
}
private val skullTextureCache = mutableMapOf<IdentityCharacteristics<ProfileComponent>, Any>()
private val sentinelPresentInvalid = Object()