mirror of
https://gitlab.com/cable-mc/cobblemon.git
synced 2026-10-20 14:16:26 -04:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a7526bc8e9 |
+1
-16
@@ -13,7 +13,6 @@ import com.cobblemon.mod.common.api.tags.CobblemonItemTags.WEARABLE_FACE_ITEMS
|
||||
import com.cobblemon.mod.common.api.tags.CobblemonItemTags.WEARABLE_HAT_ITEMS
|
||||
import com.cobblemon.mod.common.client.entity.PokemonClientDelegate
|
||||
import com.cobblemon.mod.common.client.render.MatrixWrapper
|
||||
import com.cobblemon.mod.common.client.render.models.blockbench.NullObjectParser
|
||||
import com.cobblemon.mod.common.client.render.models.blockbench.PosableModel
|
||||
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity
|
||||
import com.mojang.blaze3d.vertex.PoseStack
|
||||
@@ -64,10 +63,8 @@ class HeldItemRenderer() {
|
||||
poseStack.scale(.68f * scale, .68f * scale, .68f * scale)
|
||||
}
|
||||
(locators.containsKey("item")) -> {
|
||||
updateModifiers("item",locators)
|
||||
poseStack.mulPose(locators["item"]!!.matrix)
|
||||
|
||||
displayContext = model.getLocatorDisplayContext(ITEM) ?: ItemDisplayContext.FIXED
|
||||
poseStack.mulPose(locators["item"]!!.matrix)
|
||||
|
||||
when (displayContext) {
|
||||
ItemDisplayContext.FIXED -> {
|
||||
@@ -120,16 +117,4 @@ class HeldItemRenderer() {
|
||||
|
||||
render(entity, model, shownItem, locators, poseStack, buffer, light, 0)
|
||||
}
|
||||
|
||||
private fun updateModifiers(name: String, locators: Map<String, MatrixWrapper>) {
|
||||
locators.forEach { (locator: String, m: MatrixWrapper) ->
|
||||
val modifiers: Map<String, Float>
|
||||
if (locator.startsWith("_null_$name[")) {
|
||||
modifiers = NullObjectParser.parseNullObject(locator).modifiers
|
||||
if (modifiers.containsKey("scale")) scale = modifiers["scale"]!!
|
||||
if (modifiers.containsKey("mode")) displayContext = ItemDisplayContext.entries[((modifiers["mode"]!!).toInt()) % 9]
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+16
-9
@@ -64,22 +64,29 @@ class JsonPose(model: PosableModel, json: JsonObject) {
|
||||
it as JsonObject
|
||||
val partName = it.get("part").asString
|
||||
val part = model.getPart(partName).createTransformation()
|
||||
val rotation = it.get("rotation")?.asJsonArray?.let {
|
||||
val rotation = it.get("rotation")?.asJsonArray?.let { v ->
|
||||
Vec3(
|
||||
it[0].asDouble,
|
||||
it[1].asDouble,
|
||||
it[2].asDouble
|
||||
v[0].asDouble,
|
||||
v[1].asDouble,
|
||||
v[2].asDouble
|
||||
)
|
||||
} ?: Vec3.ZERO
|
||||
val position = it.get("position")?.asJsonArray?.let {
|
||||
val position = it.get("position")?.asJsonArray?.let { v ->
|
||||
Vec3(
|
||||
it[0].asDouble,
|
||||
it[1].asDouble,
|
||||
it[2].asDouble
|
||||
v[0].asDouble,
|
||||
v[1].asDouble,
|
||||
v[2].asDouble
|
||||
)
|
||||
} ?: Vec3.ZERO
|
||||
val scale = it.get("scale")?.asJsonArray?.let { v ->
|
||||
Vec3(
|
||||
v[0].asDouble,
|
||||
v[1].asDouble,
|
||||
v[2].asDouble
|
||||
)
|
||||
} ?: Vec3(1.0,1.0,1.0)
|
||||
val isVisible = it.get("isVisible")?.asString?.asExpressionLike()
|
||||
return@map part.withPosition(position.x, position.y, position.z).withRotationDegrees(rotation.x, rotation.y, rotation.z).also { if (isVisible != null) it.withVisibility(isVisible) }
|
||||
return@map part.withPosition(position.x, position.y, position.z).withRotationDegrees(rotation.x, rotation.y, rotation.z).withScale(scale.x, scale.y, scale.z).also { if (isVisible != null) it.withVisibility(isVisible) }
|
||||
}?.toTypedArray() ?: arrayOf()
|
||||
|
||||
val idleAnimations = (json.get("animations")?.asJsonArray ?: JsonArray()).asJsonArray.mapNotNull {
|
||||
|
||||
-50
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Cobblemon Contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package com.cobblemon.mod.common.client.render.models.blockbench
|
||||
|
||||
/**
|
||||
* Uses the name of null objects in a model to get modifier values for a locator.
|
||||
* @author Josh
|
||||
*/
|
||||
object NullObjectParser {
|
||||
fun parseNullObject(input: String): NullObjectModifier {
|
||||
// Extract modifiedLocator
|
||||
val modifiedLocator = input.replaceFirst("^_null_".toRegex(), "").replace("\\[.*\\]$".toRegex(), "")
|
||||
|
||||
// Extract modifiers
|
||||
val modifiers: MutableMap<String, Float> = HashMap()
|
||||
val start = input.indexOf('[')
|
||||
val end = input.indexOf(']')
|
||||
|
||||
if (start != -1 && end != -1 && end > start) {
|
||||
val modifierPart = input.substring(start + 1, end)
|
||||
val modifierPairs = modifierPart.split(",".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
|
||||
|
||||
for (pair in modifierPairs) {
|
||||
val keyValue = pair.split("=".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
|
||||
if (keyValue.size == 2) {
|
||||
val key = keyValue[0].trim { it <= ' ' }
|
||||
try {
|
||||
val value = keyValue[1].trim { it <= ' ' }.toFloat()
|
||||
modifiers[key] = value
|
||||
} catch (e: NumberFormatException) {
|
||||
System.err.println("Invalid number format for: " + keyValue[1])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NullObjectModifier(modifiedLocator, modifiers)
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores modifiers for a particular locator.
|
||||
*/
|
||||
class NullObjectModifier(val locatorName: String, val modifiers: Map<String, Float>)
|
||||
}
|
||||
+9
@@ -4,6 +4,15 @@
|
||||
"profileScale": 0.61,
|
||||
"profileTranslation": [-0.01, 0.86, 0],
|
||||
"rootBone": "charmander",
|
||||
"properties": {
|
||||
"item_display_context": "THIRD_PERSON_RIGHT_HAND"
|
||||
},
|
||||
"transformedParts": [
|
||||
{
|
||||
"part": "locator_item",
|
||||
"scale": [2.5, 2.5, 2.5]
|
||||
}
|
||||
],
|
||||
"animations": {
|
||||
"cry": "q.bedrock_stateful('charmander', 'cry')",
|
||||
"special": "q.bedrock_primary('charmander', 'special', q.curve('symmetrical_wide'))"
|
||||
|
||||
Reference in New Issue
Block a user