Skip to content
This repository was archived by the owner on Feb 28, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {

allprojects {
group = "io.github.solid-resourcepack"
version = "1.21-1.0.2"
version = "1.21-1.1.0"

repositories {
mavenCentral()
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package io.github.solid.resourcepack.material

import kotlin.Lazy
import kotlin.String
import kotlin.collections.List
import net.kyori.adventure.key.Key

public enum class SolidBuiltinMaterialParent(
public val key: Lazy<Key>,
public val textureIds: Lazy<List<String>>,
) {
ENTITY(lazy { Key.key("minecraft:builtin/entity") }),
ENTITY(lazy { Key.key("minecraft:builtin/entity") }, lazy { listOf("particle") }),
;

public fun toGeneric(): SolidMaterialParent = SolidMaterialParent(key.value)
public fun toGeneric(): SolidMaterialParent = SolidMaterialParent(key.value, textureIds.value)
}
Original file line number Diff line number Diff line change
@@ -1,36 +1,46 @@
package io.github.solid.resourcepack.material

import kotlin.Lazy
import kotlin.String
import kotlin.collections.List
import net.kyori.adventure.key.Key

public enum class SolidItemMaterialParent(
public val key: Lazy<Key>,
public val textureIds: Lazy<List<String>>,
) {
GENERATED(lazy { Key.key("minecraft:item/generated") }),
TEMPLATE_SPAWN_EGG(lazy { Key.key("minecraft:item/template_spawn_egg") }),
HANDHELD(lazy { Key.key("minecraft:item/handheld") }),
TEMPLATE_BANNER(lazy { Key.key("minecraft:item/template_banner") }),
TEMPLATE_BED(lazy { Key.key("minecraft:item/template_bed") }),
TEMPLATE_SHULKER_BOX(lazy { Key.key("minecraft:item/template_shulker_box") }),
HANDHELD_ROD(lazy { Key.key("minecraft:item/handheld_rod") }),
TEMPLATE_SKULL(lazy { Key.key("minecraft:item/template_skull") }),
CHEST(lazy { Key.key("minecraft:item/chest") }),
AMETHYST_BUD(lazy { Key.key("minecraft:item/amethyst_bud") }),
HANDHELD_MACE(lazy { Key.key("minecraft:item/handheld_mace") }),
TEMPLATE_MUSIC_DISC(lazy { Key.key("minecraft:item/template_music_disc") }),
COPPER_BULB(lazy { Key.key("minecraft:item/copper_bulb") }),
COPPER_DOOR(lazy { Key.key("minecraft:item/copper_door") }),
COPPER_TRAPDOOR(lazy { Key.key("minecraft:item/copper_trapdoor") }),
EXPOSED_COPPER_BULB(lazy { Key.key("minecraft:item/exposed_copper_bulb") }),
EXPOSED_COPPER_DOOR(lazy { Key.key("minecraft:item/exposed_copper_door") }),
EXPOSED_COPPER_TRAPDOOR(lazy { Key.key("minecraft:item/exposed_copper_trapdoor") }),
OXIDIZED_COPPER_BULB(lazy { Key.key("minecraft:item/oxidized_copper_bulb") }),
OXIDIZED_COPPER_DOOR(lazy { Key.key("minecraft:item/oxidized_copper_door") }),
OXIDIZED_COPPER_TRAPDOOR(lazy { Key.key("minecraft:item/oxidized_copper_trapdoor") }),
WEATHERED_COPPER_BULB(lazy { Key.key("minecraft:item/weathered_copper_bulb") }),
WEATHERED_COPPER_DOOR(lazy { Key.key("minecraft:item/weathered_copper_door") }),
WEATHERED_COPPER_TRAPDOOR(lazy { Key.key("minecraft:item/weathered_copper_trapdoor") }),
GENERATED(lazy { Key.key("minecraft:item/generated") }, lazy { listOf("layer0") }),
TEMPLATE_SPAWN_EGG(lazy { Key.key("minecraft:item/template_spawn_egg") }, lazy { listOf() }),
HANDHELD(lazy { Key.key("minecraft:item/handheld") }, lazy { listOf("layer0") }),
TEMPLATE_BANNER(lazy { Key.key("minecraft:item/template_banner") }, lazy { listOf() }),
TEMPLATE_BED(lazy { Key.key("minecraft:item/template_bed") }, lazy { listOf("particle") }),
TEMPLATE_SHULKER_BOX(lazy { Key.key("minecraft:item/template_shulker_box") }, lazy {
listOf("particle") }),
HANDHELD_ROD(lazy { Key.key("minecraft:item/handheld_rod") }, lazy { listOf("layer0") }),
TEMPLATE_SKULL(lazy { Key.key("minecraft:item/template_skull") }, lazy { listOf() }),
CHEST(lazy { Key.key("minecraft:item/chest") }, lazy { listOf() }),
AMETHYST_BUD(lazy { Key.key("minecraft:item/amethyst_bud") }, lazy { listOf("layer0") }),
HANDHELD_MACE(lazy { Key.key("minecraft:item/handheld_mace") }, lazy { listOf("layer0") }),
TEMPLATE_MUSIC_DISC(lazy { Key.key("minecraft:item/template_music_disc") }, lazy {
listOf("layer0") }),
COPPER_BULB(lazy { Key.key("minecraft:item/copper_bulb") }, lazy { listOf() }),
COPPER_DOOR(lazy { Key.key("minecraft:item/copper_door") }, lazy { listOf() }),
COPPER_TRAPDOOR(lazy { Key.key("minecraft:item/copper_trapdoor") }, lazy { listOf() }),
EXPOSED_COPPER_BULB(lazy { Key.key("minecraft:item/exposed_copper_bulb") }, lazy { listOf() }),
EXPOSED_COPPER_DOOR(lazy { Key.key("minecraft:item/exposed_copper_door") }, lazy { listOf() }),
EXPOSED_COPPER_TRAPDOOR(lazy { Key.key("minecraft:item/exposed_copper_trapdoor") }, lazy {
listOf() }),
OXIDIZED_COPPER_BULB(lazy { Key.key("minecraft:item/oxidized_copper_bulb") }, lazy { listOf() }),
OXIDIZED_COPPER_DOOR(lazy { Key.key("minecraft:item/oxidized_copper_door") }, lazy { listOf() }),
OXIDIZED_COPPER_TRAPDOOR(lazy { Key.key("minecraft:item/oxidized_copper_trapdoor") }, lazy {
listOf() }),
WEATHERED_COPPER_BULB(lazy { Key.key("minecraft:item/weathered_copper_bulb") }, lazy { listOf()
}),
WEATHERED_COPPER_DOOR(lazy { Key.key("minecraft:item/weathered_copper_door") }, lazy { listOf()
}),
WEATHERED_COPPER_TRAPDOOR(lazy { Key.key("minecraft:item/weathered_copper_trapdoor") }, lazy {
listOf() }),
;

public fun toGeneric(): SolidMaterialParent = SolidMaterialParent(key.value)
public fun toGeneric(): SolidMaterialParent = SolidMaterialParent(key.value, textureIds.value)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package io.github.solid.resourcepack.material
import net.kyori.adventure.key.Key

data class SolidMaterialParent(
val key: Key
val key: Key,
val textureIds: List<String>
) {
companion object {
fun exists(key: Key): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import io.github.solid.resourcepack.material.SolidMaterial
import io.github.solid.resourcepack.material.SolidMaterialParent
import io.github.solid.resourcepack.material.SolidMaterialTexture
import net.kyori.adventure.key.Key
import org.bukkit.Material
import team.unnamed.creative.model.Model
import team.unnamed.creative.serialize.minecraft.MinecraftResourcePackReader
import java.io.File
Expand All @@ -15,7 +16,7 @@ import java.io.File
fun main() {
val input = File("pack")
if (!input.exists()) throw NullPointerException("pack was not found")
/**input.walk(FileWalkDirection.BOTTOM_UP).forEach {
input.walk(FileWalkDirection.BOTTOM_UP).forEach {
if (it.isDirectory && it.listFiles()?.isEmpty() != false) {
println("${it.name} is an empty directory")
it.delete()
Expand All @@ -34,7 +35,7 @@ fun main() {
it.delete()
return@forEach
}
} */
}
val pack = MinecraftResourcePackReader.builder().lenient(true).build().readFromDirectory(input)
println(pack.models().size.toString() + " models found")

Expand All @@ -44,12 +45,31 @@ fun main() {

pack.models().forEach {
createSolidMaterialEnum(it, materialBuilders)
createSolidKeyCollection(it.parent(), parentBuilders, ::createParentBuilder)
val textures = mutableListOf<String>()
it.textures().variables().map { it.key }.forEach { key ->
if (key != null) textures.add(key)
}

it.textures().particle()?.let {
textures.add("particle")
}
it.textures().layers().forEachIndexed { index, modelTexture ->
textures.add("layer$index")
}
createSolidKeyCollection(it.parent(), parentBuilders, ::createParentBuilder,
Pair(", lazy { listOf(${
textures.joinToString { "\"$it\"" }
}) }", arrayOf()))

}

pack.textures().forEach {
println(it.key())
createSolidKeyCollection(Key.key(it.key().key(), it.key().value().replace(".png", "")), textureBuilders, ::createTextureBuilder)
createSolidKeyCollection(
Key.key(it.key().key(), it.key().value().replace(".png", "")),
textureBuilders,
::createTextureBuilder
)
}

parentBuilders.forEach {
Expand All @@ -74,10 +94,17 @@ fun main() {
}
}

private fun createSolidKeyCollection(nullableKey: Key?, builders: MutableMap<String, TypeSpec.Builder>, builderFun: (String) -> TypeSpec.Builder) {
private fun createSolidKeyCollection(
nullableKey: Key?,
builders: MutableMap<String, TypeSpec.Builder>,
builderFun: (String) -> TypeSpec.Builder,
vararg args: Pair<String, Array<out Any>>
) {
nullableKey?.let { key ->

val block = CodeBlock.builder()
block.add("lazy { %T.key(%S) }", Key::class, key.key())
args.forEach { block.add(it.first, it.second) }
val split = key.value().split("/")
val type = split.first().replaceFirstChar { it.uppercase() }
val prefix = split.last().uppercase()
Expand All @@ -89,6 +116,7 @@ private fun createSolidKeyCollection(nullableKey: Key?, builders: MutableMap<Str
}
}


private fun createSolidMaterialEnum(model: Model, builders: MutableMap<String, TypeSpec.Builder>) {
val parent = model.parent()
val textures = model.textures().variables().map { it.key to it.value.key() }.toMap().toMutableMap()
Expand Down Expand Up @@ -144,11 +172,15 @@ private fun createParentBuilder(type: String): TypeSpec.Builder {
return TypeSpec.enumBuilder("Solid${type}MaterialParent").primaryConstructor(
FunSpec.constructorBuilder()
.addParameter("key", typeNameOf<Lazy<Key>>())
.addParameter("textureIds", typeNameOf<Lazy<List<String>>>())
.build()
).addFunction(
FunSpec.builder("toGeneric").returns(typeNameOf<SolidMaterialParent>())
.addCode("return %T(key.value)", typeNameOf<SolidMaterialParent>()).build()
.addCode("return %T(key.value, textureIds.value)", typeNameOf<SolidMaterialParent>()).build()
).addProperty(PropertySpec.builder("key", typeNameOf<Lazy<Key>>()).initializer("key").build())
.addProperty(
PropertySpec.builder("textureIds", typeNameOf<Lazy<List<String>>>()).initializer("textureIds").build()
)
}

private fun createTextureBuilder(type: String): TypeSpec.Builder {
Expand Down