2018-04-25 12:59:18 +02:00
|
|
|
package com.minelittlepony.model.components;
|
2018-04-25 09:48:28 +02:00
|
|
|
|
|
|
|
import net.minecraft.client.model.ModelBase;
|
|
|
|
import net.minecraft.util.math.MathHelper;
|
|
|
|
|
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 13:02:10 +02:00
|
|
|
import com.minelittlepony.pony.data.TailLengths;
|
2018-04-25 16:40:47 +02:00
|
|
|
import com.minelittlepony.render.plane.PlaneRenderer;
|
2018-04-25 13:02:10 +02:00
|
|
|
|
2018-04-25 12:59:18 +02:00
|
|
|
public class PonyTail extends PlaneRenderer {
|
2018-04-25 09:48:28 +02:00
|
|
|
|
|
|
|
private final TailSegment[] segments = new TailSegment[4];
|
|
|
|
|
2018-04-25 16:40:47 +02:00
|
|
|
private final AbstractPonyModel theModel;
|
2018-04-25 09:48:28 +02:00
|
|
|
|
2018-04-25 16:40:47 +02:00
|
|
|
public PonyTail(AbstractPonyModel model) {
|
2018-04-25 09:48:28 +02:00
|
|
|
super(model);
|
|
|
|
theModel = model;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void init(float yOffset, float stretch) {
|
|
|
|
for (int i = 0; i < segments.length; i++) {
|
|
|
|
addChild(segments[i] = new TailSegment(theModel, i, yOffset, stretch));
|
|
|
|
}
|
|
|
|
}
|
2018-04-25 16:40:47 +02:00
|
|
|
|
|
|
|
public void setRotationAndAngles(boolean rainboom, float limbSwing, float limbSwingAmount, float bodySwing, float ticks) {
|
|
|
|
swingZ(rainboom, limbSwing, limbSwingAmount);
|
|
|
|
rotateAngleY = bodySwing;
|
|
|
|
|
|
|
|
if (theModel.isSneak && !theModel.isFlying && !rainboom) {
|
|
|
|
rotateSneak();
|
|
|
|
} else if (theModel.isRiding) {
|
|
|
|
rotationPointZ = 13;
|
|
|
|
rotationPointY = 3;
|
2018-04-26 23:53:22 +02:00
|
|
|
rotateAngleX = PI / 5;
|
2018-04-25 16:40:47 +02:00
|
|
|
} else {
|
|
|
|
setRotationPoint(TAIL_RP_X, TAIL_RP_Y, TAIL_RP_Z_NOTSNEAK);
|
|
|
|
if (rainboom) {
|
2018-04-26 23:53:22 +02:00
|
|
|
rotateAngleX = ROTATE_90 + MathHelper.sin(limbSwing) / 10;
|
2018-04-25 16:40:47 +02:00
|
|
|
} else {
|
2018-04-26 23:53:22 +02:00
|
|
|
rotateAngleX = limbSwingAmount / 2;
|
2018-04-25 16:40:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!rainboom) {
|
|
|
|
swingX(ticks);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rainboom) {
|
2018-04-26 23:53:22 +02:00
|
|
|
rotationPointY += 6;
|
2018-04-25 16:40:47 +02:00
|
|
|
rotationPointZ++;
|
|
|
|
}
|
|
|
|
}
|
2018-04-25 09:48:28 +02:00
|
|
|
|
|
|
|
public void swingZ(boolean rainboom, float move, float swing) {
|
2018-04-26 23:53:22 +02:00
|
|
|
rotateAngleZ = rainboom ? 0 : MathHelper.cos(move * 0.8F) * 0.2f * swing;
|
2018-04-25 09:48:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void swingX(float tick) {
|
2018-04-26 23:53:22 +02:00
|
|
|
float sinTickFactor = MathHelper.sin(tick * 0.067f) * 0.05f;
|
2018-04-25 09:48:28 +02:00
|
|
|
rotateAngleX += sinTickFactor;
|
2018-04-26 17:22:09 +02:00
|
|
|
rotateAngleY += sinTickFactor;
|
2018-04-25 09:48:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void rotateSneak() {
|
|
|
|
setRotationPoint(TAIL_RP_X, TAIL_RP_Y, TAIL_RP_Z_SNEAK);
|
|
|
|
rotateAngleX = -BODY_ROTATE_ANGLE_X_SNEAK + 0.1F;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void render(TailLengths tail, float scale) {
|
|
|
|
int tailStop = tail.ordinal();
|
|
|
|
|
|
|
|
for (int i = 0; i < segments.length; i++) {
|
|
|
|
segments[i].isHidden = i >= tailStop;
|
|
|
|
}
|
|
|
|
|
|
|
|
super.render(scale);
|
|
|
|
}
|
|
|
|
|
|
|
|
private class TailSegment extends PlaneRenderer {
|
|
|
|
|
|
|
|
public TailSegment(ModelBase model, int index, float yOffset, float stretch) {
|
|
|
|
super(model);
|
|
|
|
|
|
|
|
this.offsetY = ((float)index)/4 + 0.063f;
|
|
|
|
|
|
|
|
init(index, yOffset, stretch);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void init(int index, float yOffset, float stretch) {
|
|
|
|
int texX = (index % 2) * 4;
|
|
|
|
|
|
|
|
if (index == 0) {
|
2018-04-26 23:53:22 +02:00
|
|
|
tex(32, 0).addTopPlane(-2, 0, 2, 4, 4, stretch);
|
2018-04-25 09:48:28 +02:00
|
|
|
}
|
|
|
|
|
2018-04-26 23:53:22 +02:00
|
|
|
around(TAIL_RP_X, TAIL_RP_Y + yOffset, TAIL_RP_Z);
|
|
|
|
tex(36, texX)
|
|
|
|
.addEastPlane(2, 0, 2, 4, 4, stretch)
|
|
|
|
.addWestPlane(-2, 0, 2, 4, 4, stretch);
|
|
|
|
tex(32, texX)
|
|
|
|
.addBackPlane(-2, 0, 2, 4, 4, stretch)
|
|
|
|
.addFrontPlane(-2, 0, 6, 4, 4, stretch);
|
|
|
|
tex(32, 0)
|
|
|
|
.addBottomPlane(-2, 4, 2, 4, 4, stretch);
|
2018-04-25 09:48:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|