-
-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improvement: CF Stray Filter (#2907)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
- Loading branch information
1 parent
88bb2a0
commit 0da7414
Showing
5 changed files
with
135 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/HoppityRabbitTexturesJson.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package at.hannibal2.skyhanni.data.jsonobjects.repo | ||
|
||
import com.google.gson.annotations.Expose | ||
import com.google.gson.annotations.SerializedName | ||
|
||
data class HoppityRabbitTexturesJson( | ||
@Expose @SerializedName("textures") val textures: Map<String, List<HoppityRabbitTextureEntry>>, | ||
) | ||
|
||
data class HoppityRabbitTextureEntry( | ||
@Expose @SerializedName("rabbits") val rabbits: List<String>, | ||
@Expose @SerializedName("texture_value_b64") val textureValueB64: String, | ||
@Expose @SerializedName("skull_id") val skullId: String, | ||
@Expose @SerializedName("texture_id") val textureId: String, | ||
) |
57 changes: 57 additions & 0 deletions
57
src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityTextureHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package at.hannibal2.skyhanni.features.event.hoppity | ||
|
||
import at.hannibal2.skyhanni.data.jsonobjects.repo.HoppityRabbitTextureEntry | ||
import at.hannibal2.skyhanni.data.jsonobjects.repo.HoppityRabbitTexturesJson | ||
import at.hannibal2.skyhanni.events.RepositoryReloadEvent | ||
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule | ||
import at.hannibal2.skyhanni.utils.LorenzRarity | ||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent | ||
|
||
@SkyHanniModule | ||
object HoppityTextureHandler { | ||
|
||
private var hoppityRabbitTextures = mutableMapOf<LorenzRarity, List<HoppityRabbitTextureEntry>>() | ||
|
||
@SubscribeEvent | ||
fun onRepoReload(event: RepositoryReloadEvent) { | ||
val data = event.getConstant<HoppityRabbitTexturesJson>("HoppityRabbitTextures") | ||
hoppityRabbitTextures = data.textures.mapNotNull { (key, entries) -> | ||
val rarity = LorenzRarity.getByName(key) ?: return@mapNotNull null | ||
rarity to entries | ||
}.toMap().toMutableMap() | ||
} | ||
|
||
/** | ||
* Get the rarity for a given Skull ID. | ||
* @param skullId The Skull ID to search for. | ||
* @return The rarity or null if no rabbit was found. | ||
*/ | ||
fun getRarityBySkullId(skullId: String): LorenzRarity? { | ||
return hoppityRabbitTextures.entries.firstOrNull { (_, entries) -> | ||
entries.any { it.skullId == skullId } | ||
}?.key | ||
} | ||
|
||
/** | ||
* Get the rabbit for a given Skull ID. If more than one rabbit is found, null is returned. | ||
* @param skullId The Skull ID to search for. | ||
* @return The rabbit name or null if no rabbit was found or more than one rabbit was found. | ||
*/ | ||
fun getRabbitBySkullId(skullId: String): String? = | ||
hoppityRabbitTextures.values.flatten().firstOrNull { | ||
it.skullId == skullId | ||
}?.rabbits?.takeIf { | ||
it.size == 1 | ||
}?.firstOrNull() | ||
|
||
/** | ||
* Get the Texture ID for a given Rabbit name. | ||
* @param rabbit The Rabbit name to search for. | ||
* @return The Texture ID or null if no rabbit was found. | ||
*/ | ||
fun getTextureIdByRabbit(rabbit: String): String? = | ||
hoppityRabbitTextures.values.flatten().firstOrNull { | ||
rabbit in it.rabbits | ||
}?.textureId | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters