Skip to content

Commit

Permalink
chore: add ResourcePacks#sortItemOverrides
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Aug 7, 2024
1 parent 5ae8882 commit 29a67ec
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,19 @@ object ResourcePacks {

if (originalPack.packMeta()?.description().isNullOrEmpty()) mergePack.packMeta()?.let { originalPack.packMeta(it) }
if (originalPack.icon() == null) mergePack.icon()?.let { originalPack.icon(it) }
sortItemOverrides(originalPack)
}

/**
* Ensures that the ResourcePack's models all have their ItemOverrides sorted based on their CustomModelData
*/
fun sortItemOverrides(resourcePack: ResourcePack) {
resourcePack.models().toHashSet().forEach { model ->
val sortedOverrides = model.overrides().sortedBy { override ->
// value() is a LazilyParsedNumber so convert it to an Int
override.predicate().find { it.name() == "custom_model_data" }?.value()?.toString()?.toIntOrNull() ?: 0
}
resourcePack.model(model.toBuilder().overrides(sortedOverrides).build())
}
}
}

0 comments on commit 29a67ec

Please sign in to comment.