2018-04-25 12:59:18 +02:00
|
|
|
package com.minelittlepony.model.components;
|
|
|
|
|
2016-11-25 05:40:19 +01:00
|
|
|
import net.minecraft.client.model.ModelBase;
|
|
|
|
import net.minecraft.entity.Entity;
|
2016-05-04 03:23:57 +02:00
|
|
|
import net.minecraft.util.math.MathHelper;
|
2015-12-14 09:29:10 +01:00
|
|
|
|
2018-04-25 12:59:18 +02:00
|
|
|
import static com.minelittlepony.model.PonyModelConstants.*;
|
|
|
|
|
2018-04-25 16:40:47 +02:00
|
|
|
import com.minelittlepony.model.AbstractPonyModel;
|
|
|
|
|
2018-04-25 12:59:18 +02:00
|
|
|
public class PegasusWings extends ModelBase {
|
2016-11-25 05:40:19 +01:00
|
|
|
|
2016-04-09 08:24:15 +02:00
|
|
|
private final AbstractPonyModel pony;
|
2018-04-24 17:12:23 +02:00
|
|
|
|
2018-04-26 23:53:03 +02:00
|
|
|
public final ModelWing leftWing;
|
|
|
|
public final ModelWing rightWing;
|
2018-04-24 17:12:23 +02:00
|
|
|
|
2018-04-27 13:49:33 +02:00
|
|
|
public PegasusWings(AbstractPonyModel model, float yOffset, float stretch) {
|
|
|
|
pony = model;
|
|
|
|
|
2018-04-24 16:46:53 +02:00
|
|
|
leftWing = new ModelWing(pony, false, 4f, yOffset, stretch, 32);
|
|
|
|
rightWing = new ModelWing(pony, true, -6f, yOffset, stretch, 16);
|
2015-12-14 09:29:10 +01:00
|
|
|
}
|
2018-04-24 17:12:23 +02:00
|
|
|
|
2015-12-14 09:29:10 +01:00
|
|
|
@Override
|
2018-04-27 13:49:33 +02:00
|
|
|
public void setRotationAngles(float move, float swing, float ticks, float headYaw, float headPitch, float scale, Entity entity) {
|
2018-04-26 17:20:02 +02:00
|
|
|
if (!isVisible()) return;
|
2018-04-27 13:49:33 +02:00
|
|
|
|
|
|
|
float flap = 0;
|
|
|
|
|
2018-04-26 17:20:02 +02:00
|
|
|
if (pony.swingProgress > 0) {
|
2018-04-27 13:49:33 +02:00
|
|
|
flap = MathHelper.sin(MathHelper.sqrt(pony.swingProgress) * PI * 2);
|
2018-04-26 17:20:02 +02:00
|
|
|
} else {
|
2018-04-27 13:49:33 +02:00
|
|
|
float pi = PI * (float) Math.pow(swing, 16);
|
|
|
|
|
|
|
|
float mve = move * 0.6662f; // magic number ahoy
|
|
|
|
float srt = swing / 4;
|
|
|
|
|
|
|
|
flap = MathHelper.cos(mve + pi) * srt;
|
2018-04-26 17:20:02 +02:00
|
|
|
}
|
2018-04-27 13:49:33 +02:00
|
|
|
|
|
|
|
leftWing.rotateWalking(flap);
|
|
|
|
rightWing.rotateWalking(-flap);
|
|
|
|
|
2018-04-26 17:20:02 +02:00
|
|
|
if (isExtended()) {
|
|
|
|
float flapAngle = getWingRotationFactor(ticks);
|
|
|
|
leftWing.rotateFlying(flapAngle);
|
|
|
|
rightWing.rotateFlying(-flapAngle);
|
2015-12-14 09:29:10 +01:00
|
|
|
}
|
2018-04-27 13:49:33 +02:00
|
|
|
|
2018-04-26 17:20:02 +02:00
|
|
|
}
|
2018-04-27 13:49:33 +02:00
|
|
|
|
2018-04-26 17:20:02 +02:00
|
|
|
public float getWingRotationFactor(float ticks) {
|
|
|
|
if (pony.isFlying) {
|
2018-04-26 23:53:03 +02:00
|
|
|
return (MathHelper.sin(ticks * 0.536f) * 1) + ROTATE_270 + 0.4f;
|
2018-04-26 17:20:02 +02:00
|
|
|
}
|
|
|
|
return LEFT_WING_ROTATE_ANGLE_Z_SNEAK;
|
|
|
|
}
|
2018-04-27 13:49:33 +02:00
|
|
|
|
2018-04-26 17:20:02 +02:00
|
|
|
public boolean isVisible() {
|
|
|
|
return pony.metadata.getRace().hasWings();
|
|
|
|
}
|
2018-04-27 13:49:33 +02:00
|
|
|
|
2018-04-26 17:20:02 +02:00
|
|
|
public boolean isExtended() {
|
2018-04-27 23:22:37 +02:00
|
|
|
return pony.isFlying || pony.isCrouching();
|
2015-12-14 09:29:10 +01:00
|
|
|
}
|
2018-04-24 17:12:23 +02:00
|
|
|
|
2015-12-14 09:29:10 +01:00
|
|
|
@Override
|
2018-04-27 13:49:33 +02:00
|
|
|
public void render(Entity entity, float move, float swing, float age, float headYaw, float headPitch, float scale) {
|
2018-04-26 17:20:02 +02:00
|
|
|
if (!isVisible()) return;
|
|
|
|
boolean standing = isExtended();
|
|
|
|
leftWing.render(standing, scale);
|
|
|
|
rightWing.render(standing, scale);
|
2015-12-14 09:29:10 +01:00
|
|
|
}
|
|
|
|
}
|