mirror of
https://gitlab.bixilon.de/bixilon/pixlyzer.git
synced 2025-09-28 14:41:57 -04:00
generate block models
This commit is contained in:
parent
8dca0bd5b4
commit
6569ad770d
@ -65,6 +65,9 @@ object PixLyzer {
|
|||||||
println("Starting ${generator.name}...")
|
println("Starting ${generator.name}...")
|
||||||
|
|
||||||
generator.generate()
|
generator.generate()
|
||||||
|
if (generator.data.size() == 0) {
|
||||||
|
error("${generator.fileName} has 0 entries!")
|
||||||
|
}
|
||||||
|
|
||||||
println("Saving to ${outputDirectory.absolutePath}/${generator.fileName}.json")
|
println("Saving to ${outputDirectory.absolutePath}/${generator.fileName}.json")
|
||||||
|
|
||||||
|
@ -28,5 +28,7 @@ object Generators {
|
|||||||
SoundEventGenerator,
|
SoundEventGenerator,
|
||||||
BiomeCategoryGenerator,
|
BiomeCategoryGenerator,
|
||||||
BiomePrecipationsGenerator,
|
BiomePrecipationsGenerator,
|
||||||
|
|
||||||
|
ModelsGenerator,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
package de.bixilon.pixlyzer.generator.generators
|
package de.bixilon.pixlyzer.generator.generators
|
||||||
|
|
||||||
|
import com.google.gson.JsonArray
|
||||||
|
import com.google.gson.JsonElement
|
||||||
import com.google.gson.JsonObject
|
import com.google.gson.JsonObject
|
||||||
import de.bixilon.pixlyzer.generator.Generator
|
import de.bixilon.pixlyzer.generator.Generator
|
||||||
|
import de.bixilon.pixlyzer.util.Util
|
||||||
import net.minecraft.client.color.block.BlockColors
|
import net.minecraft.client.color.block.BlockColors
|
||||||
import net.minecraft.core.IdMapper
|
import net.minecraft.core.IdMapper
|
||||||
import net.minecraft.core.Registry
|
import net.minecraft.core.Registry
|
||||||
@ -47,10 +50,100 @@ object BlockGenerator : Generator(
|
|||||||
blockData.addProperty("has_collision", BLOCK_HAS_COLLISION_FIELD.getBoolean(block))
|
blockData.addProperty("has_collision", BLOCK_HAS_COLLISION_FIELD.getBoolean(block))
|
||||||
blockData.addProperty("has_dynamic_shape", block.hasDynamicShape())
|
blockData.addProperty("has_dynamic_shape", block.hasDynamicShape())
|
||||||
|
|
||||||
val states = JsonObject()
|
|
||||||
|
val render = Util.readJsonMinecraftResource("assets/${resourceIdentifier.namespace}/blockstates/${resourceIdentifier.path}.json")
|
||||||
|
|
||||||
|
|
||||||
|
render["multipart"]?.asJsonArray?.let {
|
||||||
|
val multipart = JsonArray()
|
||||||
|
for (condition in it) {
|
||||||
|
check(condition is JsonObject)
|
||||||
|
val conditionOut = JsonObject()
|
||||||
|
condition["when"]?.asJsonObject?.let letWhen@{
|
||||||
|
it["OR"]?.asJsonArray?.let {
|
||||||
|
val propertiesOr = JsonArray()
|
||||||
|
for (or in it) {
|
||||||
|
val propertyOr = JsonObject()
|
||||||
|
for ((property, propertyValue) in or.asJsonObject.entrySet()) {
|
||||||
|
addJsonWithType(propertyValue.asString, propertyOr, property.toLowerCase())
|
||||||
|
}
|
||||||
|
propertiesOr.add(propertyOr)
|
||||||
|
}
|
||||||
|
conditionOut.add("properties", propertiesOr)
|
||||||
|
return@letWhen
|
||||||
|
}
|
||||||
|
val properties = JsonObject()
|
||||||
|
for ((property, propertyValue) in it.entrySet()) {
|
||||||
|
addJsonWithType(propertyValue.asString, properties, property.toLowerCase())
|
||||||
|
}
|
||||||
|
conditionOut.add("properties", properties)
|
||||||
|
|
||||||
|
}
|
||||||
|
condition["apply"].let {
|
||||||
|
when (it) {
|
||||||
|
is JsonObject -> {
|
||||||
|
ModelsGenerator.MODELS_TO_GENERATE.add(it["model"].asString)
|
||||||
|
}
|
||||||
|
is JsonArray -> {
|
||||||
|
for (apply in it) {
|
||||||
|
ModelsGenerator.MODELS_TO_GENERATE.add(apply.asJsonObject["model"].asString)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
error("Invalid variant json")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
conditionOut.add("apply", it)
|
||||||
|
}
|
||||||
|
|
||||||
|
multipart.add(conditionOut)
|
||||||
|
}
|
||||||
|
|
||||||
|
val renderOut = JsonObject()
|
||||||
|
renderOut.add("multipart", multipart)
|
||||||
|
|
||||||
|
blockData.add("render", renderOut)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
val renderVariants: MutableMap<HashMap<String, String>, JsonElement> = mutableMapOf()
|
||||||
|
|
||||||
|
render["variants"]?.asJsonObject?.entrySet()?.let {
|
||||||
|
for ((properties, variant) in it) {
|
||||||
|
|
||||||
|
if (properties.isBlank()) {
|
||||||
|
renderVariants[HashMap()] = variant
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
val propertiesOut: HashMap<String, String> = HashMap()
|
||||||
|
for (split in properties.split(",")) {
|
||||||
|
val splitProperty = split.split("=")
|
||||||
|
propertiesOut[splitProperty[0].toLowerCase()] = splitProperty[1].toLowerCase()
|
||||||
|
}
|
||||||
|
renderVariants[propertiesOut] = variant
|
||||||
|
when (variant) {
|
||||||
|
is JsonObject -> {
|
||||||
|
ModelsGenerator.MODELS_TO_GENERATE.add(variant["model"].asString)
|
||||||
|
}
|
||||||
|
is JsonArray -> {
|
||||||
|
for (element in variant) {
|
||||||
|
ModelsGenerator.MODELS_TO_GENERATE.add(element.asJsonObject["model"].asString)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
error("Invalid variant json")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val colorProperties = DEFAULT_BLOCK_COLORS.getColoringProperties(block)
|
val colorProperties = DEFAULT_BLOCK_COLORS.getColoringProperties(block)
|
||||||
|
|
||||||
|
val states = JsonObject()
|
||||||
|
|
||||||
|
|
||||||
// tints
|
// tints
|
||||||
when (block) {
|
when (block) {
|
||||||
Blocks.LARGE_FERN, Blocks.TALL_GRASS -> {
|
Blocks.LARGE_FERN, Blocks.TALL_GRASS -> {
|
||||||
@ -135,30 +228,28 @@ object BlockGenerator : Generator(
|
|||||||
val propertyData = JsonObject()
|
val propertyData = JsonObject()
|
||||||
|
|
||||||
for ((property, stateProperty) in state.values) {
|
for ((property, stateProperty) in state.values) {
|
||||||
val propertyValueName = stateProperty.toString()
|
addJsonWithType(stateProperty.toString(), propertyData, property.name.toLowerCase())
|
||||||
|
|
||||||
try {
|
|
||||||
val int = propertyValueName.toInt()
|
|
||||||
propertyData.addProperty(property.name.toLowerCase(), int)
|
|
||||||
continue
|
|
||||||
} catch (exception: Exception) {
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
val boolean = propertyValueName.toBoolean()
|
|
||||||
propertyData.addProperty(property.name.toLowerCase(), boolean)
|
|
||||||
continue
|
|
||||||
} catch (exception: Exception) {
|
|
||||||
}
|
|
||||||
|
|
||||||
propertyData.addProperty(property.name.toLowerCase(), propertyValueName)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (propertyData.size() > 0) {
|
if (propertyData.size() > 0) {
|
||||||
stateData.add("properties", propertyData)
|
stateData.add("properties", propertyData)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ToDo: Block models
|
||||||
|
|
||||||
|
for ((propertyMap, variant) in renderVariants) {
|
||||||
|
var valid = true
|
||||||
|
for ((propertyName, propertyValue) in propertyMap) {
|
||||||
|
if (propertyData[propertyName]?.asString != propertyValue) {
|
||||||
|
valid = false
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (valid) {
|
||||||
|
stateData.add("render", variant)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
states.add(Block.getId(state).toString(), stateData)
|
states.add(Block.getId(state).toString(), stateData)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,6 +276,27 @@ object BlockGenerator : Generator(
|
|||||||
private val DEFAULT_BLOCK_COLORS = BlockColors.createDefault()
|
private val DEFAULT_BLOCK_COLORS = BlockColors.createDefault()
|
||||||
|
|
||||||
|
|
||||||
|
fun addJsonWithType(input: String, output: JsonObject, name: String) {
|
||||||
|
try {
|
||||||
|
output.addProperty(name, Integer.parseInt(input))
|
||||||
|
return
|
||||||
|
} catch (exception: Exception) {
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
val boolean = when (input) {
|
||||||
|
"true" -> true
|
||||||
|
"false" -> false
|
||||||
|
else -> throw Exception("Not a boolean")
|
||||||
|
}
|
||||||
|
output.addProperty(name, boolean)
|
||||||
|
return
|
||||||
|
} catch (exception: Exception) {
|
||||||
|
}
|
||||||
|
|
||||||
|
output.addProperty(name, input)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -136,6 +136,9 @@ object ItemGenerator : Generator(
|
|||||||
|
|
||||||
itemData.addProperty("class", item::class.java.simpleName)
|
itemData.addProperty("class", item::class.java.simpleName)
|
||||||
|
|
||||||
|
|
||||||
|
// ToDo Item models
|
||||||
|
|
||||||
data.add(resourceIdentifier.toString(), itemData)
|
data.add(resourceIdentifier.toString(), itemData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,19 @@
|
|||||||
|
package de.bixilon.pixlyzer.generator.generators
|
||||||
|
|
||||||
|
import de.bixilon.pixlyzer.generator.Generator
|
||||||
|
import de.bixilon.pixlyzer.util.Util
|
||||||
|
import net.minecraft.resources.ResourceLocation
|
||||||
|
|
||||||
|
object ModelsGenerator : Generator(
|
||||||
|
"models"
|
||||||
|
) {
|
||||||
|
val MODELS_TO_GENERATE: MutableList<String> = mutableListOf()
|
||||||
|
override fun generate() {
|
||||||
|
for (model in MODELS_TO_GENERATE) {
|
||||||
|
val resourceLocation = ResourceLocation(model)
|
||||||
|
|
||||||
|
data.add(resourceLocation.toString(), Util.readJsonMinecraftResource("assets/${resourceLocation.namespace}/models/${resourceLocation.path}.json"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -2,6 +2,7 @@ package de.bixilon.pixlyzer.generator.generators
|
|||||||
|
|
||||||
import com.google.gson.JsonObject
|
import com.google.gson.JsonObject
|
||||||
import de.bixilon.pixlyzer.generator.Generator
|
import de.bixilon.pixlyzer.generator.Generator
|
||||||
|
import de.bixilon.pixlyzer.util.Util
|
||||||
import net.minecraft.core.Registry
|
import net.minecraft.core.Registry
|
||||||
|
|
||||||
object ParticleGenerator : Generator(
|
object ParticleGenerator : Generator(
|
||||||
@ -12,6 +13,10 @@ object ParticleGenerator : Generator(
|
|||||||
val resourceIdentifier = Registry.PARTICLE_TYPE.getKey(particleType)
|
val resourceIdentifier = Registry.PARTICLE_TYPE.getKey(particleType)
|
||||||
val particleData = JsonObject()
|
val particleData = JsonObject()
|
||||||
particleData.addProperty("id", Registry.PARTICLE_TYPE.getId(particleType))
|
particleData.addProperty("id", Registry.PARTICLE_TYPE.getId(particleType))
|
||||||
|
|
||||||
|
// load render model
|
||||||
|
particleData.add("render", Util.readJsonMinecraftResource("assets/${resourceIdentifier!!.namespace}/particles/${resourceIdentifier.path}.json"))
|
||||||
|
|
||||||
if (particleType.overrideLimiter) {
|
if (particleType.overrideLimiter) {
|
||||||
particleData.addProperty("override_limiter", particleType.overrideLimiter)
|
particleData.addProperty("override_limiter", particleType.overrideLimiter)
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package de.bixilon.pixlyzer.util
|
|||||||
|
|
||||||
import com.google.gson.JsonObject
|
import com.google.gson.JsonObject
|
||||||
import com.google.gson.JsonParser
|
import com.google.gson.JsonParser
|
||||||
|
import net.minecraft.client.Minecraft
|
||||||
import java.io.FileInputStream
|
import java.io.FileInputStream
|
||||||
import java.io.InputStreamReader
|
import java.io.InputStreamReader
|
||||||
|
|
||||||
@ -36,4 +37,12 @@ object Util {
|
|||||||
return result.toString()
|
return result.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun readJsonMinecraftResource(path: String): JsonObject {
|
||||||
|
val reader = InputStreamReader(Minecraft::class.java.getResourceAsStream("/$path"))
|
||||||
|
val json: JsonObject = JsonParser().parse(reader).asJsonObject
|
||||||
|
reader.close()
|
||||||
|
return json
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user