Compare commits

...
5 changed files with 117 additions and 17 deletions
@@ -12,6 +12,7 @@ import com.cobblemon.mod.common.client.render.player.MountedPlayerRenderer;
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity;
import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.model.geom.PartPose;
import net.minecraft.client.player.AbstractClientPlayer;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
@@ -39,8 +40,10 @@ public class HumanoidModelMixin {
public ModelPart rightLeg;
@Shadow @Final
public ModelPart leftLeg;
@Shadow @Final
public ModelPart body;
@Inject(method = "setupAnim*", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/model/geom/ModelPart;copyFrom(Lnet/minecraft/client/model/geom/ModelPart;)V", shift = At.Shift.BEFORE))
@Inject(method = "setupAnim*", at = @At("TAIL"))//@At(value = "INVOKE", target = "Lnet/minecraft/client/model/geom/ModelPart;copyFrom(Lnet/minecraft/client/model/geom/ModelPart;)V", shift = At.Shift.BEFORE))
public void cobblemon$animateRiders(
LivingEntity entity,
float limbSwing,
@@ -56,6 +59,7 @@ public class HumanoidModelMixin {
relevantPartsByName.put("leg_left", leftLeg);
relevantPartsByName.put("leg_right", rightLeg);
relevantPartsByName.put("head", head);
relevantPartsByName.put("torso", body);
}
Entity vehicle = entity.getVehicle();
@@ -64,6 +68,7 @@ public class HumanoidModelMixin {
return behaviour.shouldRotatePlayerHead(settings, state, pokemonEntity);
});
if (!shouldRotatePlayerHead) {
netHeadYaw = 0f;
headPitch = 0f;
@@ -13,7 +13,10 @@ import com.cobblemon.mod.common.api.riding.Rideable
import com.cobblemon.mod.common.client.MountedPokemonAnimationRenderController
import com.cobblemon.mod.common.client.entity.PokemonClientDelegate
import com.cobblemon.mod.common.client.render.models.blockbench.bedrock.animation.BedrockAnimationRepository
import com.cobblemon.mod.common.client.render.models.blockbench.getRotation
import com.cobblemon.mod.common.client.render.models.blockbench.pose.ModelPartTransformation.Companion.defaultRuntime
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity
import com.cobblemon.mod.common.util.resolveBoolean
import com.mojang.blaze3d.vertex.PoseStack
import com.mojang.math.Axis
import net.minecraft.client.model.geom.ModelPart
@@ -27,6 +30,10 @@ import org.joml.Vector3f
* @author landonjw
*/
object MountedPlayerRenderer {
// Dummy part to hold animation data
var bodyPart: ModelPart = ModelPart(emptyList(),mutableMapOf())
fun render(player: AbstractClientPlayer, entity: PokemonEntity, stack: PoseStack, bob: Float, yBodyRot: Float, partialTicks: Float, i: Float) {
if(player.vehicle !is Rideable) return
val matrix = stack.last().pose()
@@ -53,23 +60,35 @@ object MountedPlayerRenderer {
Mth.lerp(partialTicks.toDouble(), entity.zOld, entity.z),
)
matrix.translate(playerPos.subtract(entityPos).toVector3f().negate())
matrix.translate(locator.matrix.getTranslation(Vector3f()))
val offset = Vector3f(0f, player.bbHeight / 2, 0f).mul(-1f)
//val offset = Vector3f(0f, player.bbHeight / 2, 0f).mul(-1f)
matrix.rotate(locator.matrix.getRotation(AxisAngle4f()))
matrix.rotate(Axis.YP.rotationDegrees(180 + yBodyRot))
matrix.translate(offset)
matrix.translate(Vector3f(0f, 0.35f, 0f))
matrix.translate(
bodyPart.x / 16.0f,
-bodyPart.y / 16.0f,
bodyPart.z / 16.0f
)
matrix.rotateXYZ(
-bodyPart.xRot,
-bodyPart.yRot,
-bodyPart.zRot
)
matrix.rotate(Axis.YP.rotationDegrees(180 + yBodyRot))
//matrix.translate(offset)
//matrix.translate(Vector3f(0f, 0.35f, 0f))
}
}
fun animate(
pokemonEntity: PokemonEntity,
player: AbstractClientPlayer,
relevantPartsByName: Map<String, ModelPart>,
relevantPartsByName: MutableMap<String, ModelPart>,
headYaw: Float,
headPitch: Float,
ageInTicks: Float,
@@ -82,10 +101,24 @@ object MountedPlayerRenderer {
?: return
val state = pokemonEntity.delegate as PokemonClientDelegate
// Add in the dummy body part to gather body animation data
relevantPartsByName["body"] = bodyPart
bodyPart.x = 0.0f
bodyPart.y = 0.0f
bodyPart.z = 0.0f
var rotation = floatArrayOf(0F, 0F, 0F)
val scale = floatArrayOf(1F, 1F, 1F)
// Reset all relevant parts to their base values
relevantPartsByName.values.forEach {
it.xRot = 0F
it.yRot = 0F
it.zRot = 0F
it.xRot = rotation[0]
it.yRot = rotation[1]
it.zRot = rotation[2]
it.xScale = scale[0]
it.yScale = scale[1]
it.zScale = scale[2]
}
state.runtime.environment.setSimpleVariable("age_in_ticks", DoubleValue(ageInTicks.toDouble()))
@@ -1,26 +1,68 @@
{
"format_version": "1.8.0",
"animations": {
"animation.ride_test.arm_swing": {
"loop": true,
"bones": {
"torso": {
"rotation": ["q.anim_time * 90 * -0.5 ", 0, 0]
},
"arm_right": {
"rotation": ["q.anim_time * 90 ", 0, 0]
},
"arm_left": {
"rotation": ["q.anim_time * 90 ", 0, 0]
},
"body": {
"rotation": ["q.anim_time * 90 ", 0, 0]
}
}
},
"animation.ride_test.sitting": {
"loop": true,
"bones": {
"body": {
"position": [0, -9, 0]
},
"torso": {
"rotation": [25, 0, 0]
"rotation": [25, 0, 0],
"position": [0, -8, 7.4]
},
"arm_right": {
"rotation": [0, 0, 22.5]
"rotation": [-42.5, 0, 22.5]
},
"arm_left": {
"rotation": [0, 0, -27.5]
"rotation": [-40, 0, -27.5]
},
"leg_right": {
"rotation": [-90, 20, 0]
"rotation": [-117.23657, 16.69387, -7.09426]
},
"leg_left": {
"rotation": [-90, -20, 0]
"rotation": [-117.23657, -16.69387, 7.09426]
},
"head": {
"rotation": [-12.5, 0, 0]
}
}
},
"animation.ride_test.laying": {
"loop": true,
"bones": {
"body": {
"rotation": [80, 0, 0],
"position": [0, 0, 20]
},
"arm_right": {
"rotation": [-77.5, 60, 20]
},
"arm_left": {
"rotation": [-77.5, -60, -20]
},
"leg_right": {
"rotation": [9.92442, -0.86717, 9.96271]
},
"leg_left": {
"rotation": [9.92442, 0.86717, -9.96271]
},
"head": {
"rotation": [-60, 0, 0]
}
}
}
@@ -123,6 +123,16 @@
"y": 1.5,
"z": -0.5
},
"poseAnimations": [
{
"animations": [
{
"fileName": "ride_test",
"animationName": "animation.ride_test.laying"
}
]
}
],
"poseOffsets": [
{
"poseTypes": [
@@ -103,6 +103,16 @@
"y": 0.4,
"z": 0
},
"poseAnimations": [
{
"animations": [
{
"fileName": "ride_test",
"animationName": "animation.ride_test.sitting"
}
]
}
],
"poseOffsets": [
{
"poseTypes": [