MineLittlePony/src/main/java/com/minelittlepony/client/model/PonyElytra.java

97 lines
3 KiB
Java
Raw Normal View History

package com.minelittlepony.client.model;
2019-11-23 18:28:42 +01:00
import net.minecraft.client.model.ModelPart;
2019-05-27 17:59:15 +02:00
import net.minecraft.client.network.AbstractClientPlayerEntity;
2019-11-23 18:28:42 +01:00
import net.minecraft.client.render.entity.model.AnimalModel;
2019-05-27 17:59:15 +02:00
import net.minecraft.entity.LivingEntity;
import net.minecraft.util.math.Vec3d;
2019-11-23 18:28:42 +01:00
import com.google.common.collect.ImmutableList;
2019-11-27 13:09:53 +01:00
import com.minelittlepony.mson.api.ModelContext;
import com.minelittlepony.mson.api.MsonModel;
import static com.minelittlepony.model.PonyModelConstants.*;
2018-04-27 09:46:44 +02:00
/**
* Modified from ModelElytra.
*/
2019-11-27 13:09:53 +01:00
public class PonyElytra<T extends LivingEntity> extends AnimalModel<T> implements MsonModel {
public boolean isSneaking;
2019-11-23 22:59:33 +01:00
private ModelPart rightWing;
private ModelPart leftWing;
2019-11-27 13:09:53 +01:00
@Override
public void init(ModelContext context) {
rightWing = context.findByName("right_wing");
leftWing = context.findByName("left_wing");
}
@Override
2019-11-23 18:28:42 +01:00
protected Iterable<ModelPart> getHeadParts() {
return ImmutableList.of();
}
@Override
protected Iterable<ModelPart> getBodyParts() {
return ImmutableList.of(leftWing, rightWing);
}
/**
* Sets the model's various rotation angles.
*
* See {@link AbstractPonyModel.setRotationAngles} for an explanation of the various parameters.
*/
@Override
2019-11-23 18:28:42 +01:00
public void setAngles(T entity, float limbDistance, float limbAngle, float age, float headYaw, float headPitch) {
2018-04-27 09:46:44 +02:00
float rotateX = PI / 2;
float rotateY = PI / 8;
float rotateZ = PI / 12;
2018-04-27 09:46:44 +02:00
float rpY = BODY_RP_Y_NOTSNEAK;
2019-05-27 17:59:15 +02:00
if (entity.isFallFlying()) {
2018-04-27 09:46:44 +02:00
float velY = 1;
2019-05-27 17:59:15 +02:00
Vec3d motion = entity.getVelocity();
if (motion.y < 0) {
velY = 1 - (float) Math.pow(-motion.normalize().y, 1.5);
}
2018-04-27 09:46:44 +02:00
rotateX = velY * PI * (2 / 3F) + (1 - velY) * rotateX;
rotateY = velY * (PI / 2) + (1 - velY) * rotateY;
} else if (isSneaking) {
2018-04-27 09:46:44 +02:00
rotateX = PI * 1.175F;
rotateY = PI / 2;
2018-04-27 09:46:44 +02:00
rotateZ = PI / 4;
rpY = BODY_RP_Y_SNEAK;
}
2019-11-22 18:24:22 +01:00
leftWing.pivotX = 5;
leftWing.pivotY = rpY;
2018-04-27 09:46:44 +02:00
2019-05-27 17:59:15 +02:00
if (entity instanceof AbstractClientPlayerEntity) {
AbstractClientPlayerEntity player = (AbstractClientPlayerEntity) entity;
2018-04-27 09:46:44 +02:00
2019-05-27 17:59:15 +02:00
player.elytraPitch += (rotateX - player.elytraPitch) / 10;
player.elytraYaw += (rotateY - player.elytraYaw) / 10;
player.elytraRoll += (rotateZ - player.elytraRoll) / 10;
2018-04-27 09:46:44 +02:00
2019-05-27 17:59:15 +02:00
leftWing.pitch = player.elytraPitch;
leftWing.yaw = player.elytraYaw;
leftWing.roll = player.elytraRoll;
} else {
2019-05-27 17:59:15 +02:00
leftWing.pitch = rotateX;
leftWing.yaw = rotateZ;
leftWing.roll = rotateY;
}
2019-11-22 18:24:22 +01:00
rightWing.pivotX = -leftWing.pivotX;
rightWing.pivotY = leftWing.pivotY;
2019-05-27 17:59:15 +02:00
rightWing.pitch = leftWing.pitch;
rightWing.yaw = -leftWing.yaw;
rightWing.roll = -leftWing.roll;
}
2016-11-25 05:40:19 +01:00
}