From dd00689b76172a0791d4701f33dcafe62ed73f1f Mon Sep 17 00:00:00 2001 From: Bixilon Date: Sun, 1 May 2022 14:30:32 +0200 Subject: [PATCH] don't extract block models --- .../bixilon/pixlyzer/generator/Generators.kt | 1 - .../generator/generators/BlockGenerator.kt | 131 ------------------ .../generator/generators/ModelsGenerator.kt | 46 ------ 3 files changed, 178 deletions(-) delete mode 100644 src/main/kotlin/de/bixilon/pixlyzer/generator/generators/ModelsGenerator.kt diff --git a/src/main/kotlin/de/bixilon/pixlyzer/generator/Generators.kt b/src/main/kotlin/de/bixilon/pixlyzer/generator/Generators.kt index f2118c2..c9d2d8f 100644 --- a/src/main/kotlin/de/bixilon/pixlyzer/generator/Generators.kt +++ b/src/main/kotlin/de/bixilon/pixlyzer/generator/Generators.kt @@ -46,6 +46,5 @@ object Generators { VoxelShapeGenerator, - ModelsGenerator, ) } diff --git a/src/main/kotlin/de/bixilon/pixlyzer/generator/generators/BlockGenerator.kt b/src/main/kotlin/de/bixilon/pixlyzer/generator/generators/BlockGenerator.kt index ffbe2e3..94b102d 100644 --- a/src/main/kotlin/de/bixilon/pixlyzer/generator/generators/BlockGenerator.kt +++ b/src/main/kotlin/de/bixilon/pixlyzer/generator/generators/BlockGenerator.kt @@ -7,10 +7,7 @@ import de.bixilon.pixlyzer.util.ReflectionUtil.getClass import de.bixilon.pixlyzer.util.ReflectionUtil.getField import de.bixilon.pixlyzer.util.ReflectionUtil.getGetter import de.bixilon.pixlyzer.util.ReflectionUtil.variable -import de.bixilon.pixlyzer.util.Util import de.bixilon.pixlyzer.util.Util.compound -import de.bixilon.pixlyzer.util.Util.listCast -import de.bixilon.pixlyzer.util.Util.mapCast import de.bixilon.pixlyzer.util.Util.nullCast import de.bixilon.pixlyzer.util.Util.of import de.bixilon.pixlyzer.util.Util.realName @@ -100,69 +97,6 @@ object BlockGenerator : Generator( } } - val render = Util.readJsonMinecraftResource("assets/${resourceLocation.namespace}/blockstates/${resourceLocation.path}.json") - - val multipartVariants: MutableMap>, MutableList> = mutableMapOf() - - - render["multipart"]?.listCast()?.let { - for (condition in it) { - check(condition is Map<*, *>) - val properties: MutableSet>> = mutableSetOf() - - fun addPropertyMap(json: Any) { - val singlePropertyMap: MutableMap> = mutableMapOf() - for ((property, propertyValue) in json.mapCast()!!) { - check(property is String) - val valueSet: MutableSet = mutableSetOf() - val propertyValues = propertyValue.toString().split("|") - for (value in propertyValues) { - valueSet.add(value) - } - singlePropertyMap[property.lowercase(Locale.getDefault())] = valueSet - } - properties.add(singlePropertyMap) - } - - condition["when"]?.mapCast()?.let letWhen@{ - it["OR"]?.listCast()?.let { - for (or in it) { - addPropertyMap(or) - } - return@letWhen - } - addPropertyMap(it) - } - if (properties.isEmpty()) { - properties.add(mutableMapOf()) - } - addBlockModel(condition["apply"]!!) - for (propertyMap in properties) { - multipartVariants.getOrPut(propertyMap) { mutableListOf() }.add(condition["apply"]!!) - } - } - } - - val renderVariants: MutableMap, Any> = mutableMapOf() - render["variants"]?.mapCast()?.let { - for ((property, variant) in it) { - check(property is String) - - addBlockModel(variant) - if (property.isBlank()) { - renderVariants[mutableMapOf()] = variant - continue - } - - val propertiesOut: MutableMap = mutableMapOf() - for (split in property.split(",")) { - val splitProperty = split.split("=") - propertiesOut[splitProperty[0].lowercase(Locale.getDefault())] = splitProperty[1].lowercase(Locale.getDefault()) - } - renderVariants[propertiesOut] = variant - } - } - val hasColorProperties = (TINT_PROPERTIES_METHOD?.invoke(DEFAULT_BLOCK_COLORS, block) as Set<*>?)?.size?.let { it > 0 } ?: let { val blockColorProviderList = BLOCK_COLORS_PROVIDERS_ID_LIST!!.get(DEFAULT_BLOCK_COLORS) ID_LIST_GET_METHOD.invoke(blockColorProviderList, Registry.BLOCK.getRawId(block)) != null @@ -260,55 +194,6 @@ object BlockGenerator : Generator( stateData["properties"] = propertyData } - for ((propertyMap, variant) in renderVariants) { - var valid = true - for ((propertyName, propertyValue) in propertyMap) { - if (propertyData[propertyName]?.toString() != propertyValue) { - valid = false - break - } - } - if (valid) { - stateData["render"] = variant - } - } - val multipart = mutableListOf() - for ((properties, elementList) in multipartVariants) { - var valid = true - for ((propertyName, values) in properties) { - if (propertyData[propertyName] == null) { - valid = false - break - } - if (!values.contains(propertyData[propertyName]?.toString())) { - valid = false - break - } - } - if (valid) { - for (element in elementList) { - if (element is List<*>) { - for (apply in element) { - if (!multipart.contains(apply)) { - multipart.add(apply!!) - } - } - } else if (element is Map<*, *>) { - if (!multipart.contains(element)) { - multipart.add(element) - } - } - } - } - } - - if (multipart.size > 0 && !stateData.contains("render")) { - val multipartWrapper = mutableListOf() - multipartWrapper.add(multipart) - stateData["render"] = multipartWrapper - } - - state.initShapeCache() val positionOffset = BLOCK_STATE_GET_OFFSET.invoke(state, EntitySpawner.CLIENT_LEVEL, EMPTY_BLOCK_POSITION) as Vec3d @@ -570,21 +455,5 @@ object BlockGenerator : Generator( output[name] = input } - - private fun addBlockModel(json: Any) { - when (json) { - is Map<*, *> -> { - ModelsGenerator.MODELS_TO_GENERATE.add(json["model"]!!.toString()) - } - is List<*> -> { - for (element in json) { - ModelsGenerator.MODELS_TO_GENERATE.add(element!!.mapCast()!!["model"]!!.toString()) - } - } - else -> { - error("Invalid variant json") - } - } - } } diff --git a/src/main/kotlin/de/bixilon/pixlyzer/generator/generators/ModelsGenerator.kt b/src/main/kotlin/de/bixilon/pixlyzer/generator/generators/ModelsGenerator.kt deleted file mode 100644 index d783034..0000000 --- a/src/main/kotlin/de/bixilon/pixlyzer/generator/generators/ModelsGenerator.kt +++ /dev/null @@ -1,46 +0,0 @@ -package de.bixilon.pixlyzer.generator.generators - -import de.bixilon.pixlyzer.generator.Generator -import de.bixilon.pixlyzer.util.Util -import de.bixilon.pixlyzer.util.Util.listCast -import de.bixilon.pixlyzer.util.Util.mapCast -import net.minecraft.util.Identifier -import net.minecraft.util.registry.Registry - -object ModelsGenerator : Generator( - "models" -) { - val MODELS_TO_GENERATE: MutableList = mutableListOf() - override fun generate() { - for (model in MODELS_TO_GENERATE) { - val resourceLocation = Identifier(model) - loadModel(resourceLocation) - } - for (item in Registry.ITEM) { - val itemIdentifier = Registry.ITEM.getId(item) - loadModel(Identifier(itemIdentifier.namespace, "item/" + itemIdentifier.path)) - } - } - - private fun loadModel(resourceLocation: Identifier) { - if (data.containsKey(resourceLocation.toString())) { - return - } - data[resourceLocation.toString()] = Util.readJsonMinecraftResource("assets/${resourceLocation.namespace}/models/${resourceLocation.path}.json") - - val modelJson = Util.readJsonMinecraftResource("assets/${resourceLocation.namespace}/models/${resourceLocation.path}.json") - modelJson["parent"]?.let { - if (!it.toString().startsWith("builtin/")) { - loadModel(Identifier(it as String)) - } - } - modelJson["overrides"]?.listCast()?.let { - for (override in it) { - override.mapCast()!!["model"]?.let { - loadModel(Identifier(it as String)) - } - } - } - } - -}