-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ModelTexturesSerializer & other RP stuff
- Loading branch information
Showing
4 changed files
with
50 additions
and
0 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
39 changes: 39 additions & 0 deletions
39
...alizers/src/main/kotlin/com/mineinabyss/idofront/serialization/ModelTexturesSerializer.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,39 @@ | ||
package com.mineinabyss.idofront.serialization | ||
|
||
import com.charleskorn.kaml.* | ||
import kotlinx.serialization.* | ||
import kotlinx.serialization.descriptors.SerialDescriptor | ||
import kotlinx.serialization.encoding.Decoder | ||
import kotlinx.serialization.encoding.Encoder | ||
import net.kyori.adventure.key.Key | ||
import team.unnamed.creative.model.ModelTexture | ||
import team.unnamed.creative.model.ModelTextures | ||
|
||
@Serializable | ||
@SerialName("ModelTextures") | ||
class ModelTexturesSurrogate( | ||
val layers: List<@Serializable(KeySerializer::class) Key> = emptyList(), | ||
val particle: @Serializable(KeySerializer::class) Key? = null, | ||
val variables: Map<String, @Serializable(KeySerializer::class) Key> = emptyMap(), | ||
) { | ||
@Transient val modelTextures = ModelTextures.of(layers.map(ModelTexture::ofKey), particle?.let(ModelTexture::ofKey), variables.mapValues { ModelTexture.ofKey(it.value) }.toMap()) | ||
} | ||
|
||
object ModelTexturesSerializer : KSerializer<ModelTexturesSurrogate> { | ||
override val descriptor: SerialDescriptor = ContextualSerializer(ModelTexturesSurrogate::class).descriptor | ||
|
||
override fun deserialize(decoder: Decoder): ModelTexturesSurrogate { | ||
val node = (decoder as? YamlInput)?.node?.yamlMap?.get<YamlNode>("textures") ?: return ModelTexturesSurrogate.serializer().deserialize(decoder) | ||
|
||
return when (node) { | ||
is YamlScalar -> ModelTexturesSurrogate(mutableListOf(Key.key(node.content))) | ||
is YamlList -> ModelTexturesSurrogate(node.items.mapNotNull { (it as? YamlScalar)?.content?.let(Key::key) }.toMutableList()) | ||
is YamlMap -> ModelTexturesSurrogate(variables = node.entries.mapNotNull { it.key.content to ((it.value as? YamlScalar)?.content?.let(Key::key) ?: return@mapNotNull null) }.toMap()) | ||
else -> ModelTexturesSurrogate() | ||
} | ||
} | ||
|
||
override fun serialize(encoder: Encoder, value: ModelTexturesSurrogate) { | ||
ModelTexturesSurrogate.serializer().serialize(encoder, value) | ||
} | ||
} |
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
9 changes: 9 additions & 0 deletions
9
idofront-util/src/main/kotlin/com/mineinabyss/idofront/resourcepacks/ResourcePacks.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,9 @@ | ||
package com.mineinabyss.idofront.resourcepacks | ||
|
||
import team.unnamed.creative.serialize.minecraft.MinecraftResourcePackReader | ||
import team.unnamed.creative.serialize.minecraft.MinecraftResourcePackWriter | ||
|
||
object ResourcePacks { | ||
val resourcePackWriter = MinecraftResourcePackWriter.builder().prettyPrinting(true).build() | ||
val resourcePackReader = MinecraftResourcePackReader.builder().lenient(true).build() | ||
} |