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

88 lines
3.1 KiB
Java
Raw Normal View History

package com.minelittlepony.model.components;
2018-04-26 23:53:49 +02:00
import com.minelittlepony.render.PonyRenderer;
import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.math.Vec3d;
2018-04-27 09:46:44 +02:00
import static com.minelittlepony.model.PonyModelConstants.*;
/**
* Modified from ModelElytra.
*/
public class PonyElytra extends ModelBase {
2018-04-26 23:53:49 +02:00
private PonyRenderer rightWing = new PonyRenderer(this, 22, 0);
private PonyRenderer leftWing = new PonyRenderer(this, 22, 0);
public PonyElytra() {
leftWing .box(-10, 0, 0, 10, 20, 2, 1);
rightWing.flipX().box( 0, 0, 0, 10, 20, 2, 1);
}
@Override
public void render(Entity entity, float move, float swing, float age, float headYaw, float headPitch, float scale) {
GlStateManager.disableRescaleNormal();
GlStateManager.disableCull();
2018-04-26 23:53:49 +02:00
leftWing.render(scale);
rightWing.render(scale);
}
@Override
public void setRotationAngles(float move, float swing, float age, float headYaw, float headPitch, float scale, Entity entity) {
super.setRotationAngles(move, swing, age, headYaw, headPitch, scale, entity);
2018-04-26 23:53:49 +02:00
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;
if (entity instanceof EntityLivingBase && ((EntityLivingBase) entity).isElytraFlying()) {
float velY = 1;
if (entity.motionY < 0) {
Vec3d motion = (new Vec3d(entity.motionX, entity.motionY, entity.motionZ)).normalize();
velY = 1 - (float) Math.pow(-motion.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 (entity.isSneaking()) {
rotateX = PI * 1.175F;
rotateY = PI / 2;
2018-04-27 09:46:44 +02:00
rotateZ = PI / 4;
rpY = BODY_RP_Y_SNEAK;
}
2018-04-27 09:46:44 +02:00
leftWing.rotationPointX = 5;
leftWing.rotationPointY = rpY;
if (entity instanceof AbstractClientPlayer) {
AbstractClientPlayer player = (AbstractClientPlayer) entity;
player.rotateElytraX += (rotateX - player.rotateElytraX) / 10;
player.rotateElytraY += (rotateY - player.rotateElytraY) / 10;
player.rotateElytraZ += (rotateZ - player.rotateElytraZ) / 10;
leftWing.rotateAngleX = player.rotateElytraX;
leftWing.rotateAngleY = player.rotateElytraY;
leftWing.rotateAngleZ = player.rotateElytraZ;
} else {
2018-04-27 09:46:44 +02:00
leftWing.rotateAngleX = rotateX;
leftWing.rotateAngleZ = rotateZ;
leftWing.rotateAngleY = rotateY;
}
2018-04-27 09:46:44 +02:00
rightWing.rotationPointX = -leftWing.rotationPointX;
rightWing.rotationPointY = leftWing.rotationPointY;
rightWing.rotateAngleX = leftWing.rotateAngleX;
rightWing.rotateAngleY = -leftWing.rotateAngleY;
rightWing.rotateAngleZ = -leftWing.rotateAngleZ;
}
2016-11-25 05:40:19 +01:00
}