2018-07-27 00:10:18 +02:00
|
|
|
package com.minelittlepony.render;
|
|
|
|
|
2018-09-19 19:43:23 +02:00
|
|
|
import com.minelittlepony.MineLittlePony;
|
2018-07-27 00:10:18 +02:00
|
|
|
import com.minelittlepony.ducks.IRenderPony;
|
|
|
|
import com.minelittlepony.model.AbstractPonyModel;
|
|
|
|
import com.minelittlepony.model.ModelWrapper;
|
2018-08-30 16:12:21 +02:00
|
|
|
import com.minelittlepony.pony.data.IPony;
|
2018-07-27 00:10:18 +02:00
|
|
|
import com.minelittlepony.transform.PonyPosture;
|
|
|
|
|
|
|
|
import net.minecraft.client.renderer.GlStateManager;
|
2018-09-19 19:43:23 +02:00
|
|
|
import net.minecraft.entity.Entity;
|
2018-07-27 00:10:18 +02:00
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
|
|
|
|
|
|
public class RenderPony<T extends EntityLivingBase> {
|
|
|
|
|
|
|
|
public ModelWrapper playerModel;
|
|
|
|
|
2018-08-10 08:32:09 +02:00
|
|
|
protected AbstractPonyModel ponyModel;
|
2018-07-27 00:10:18 +02:00
|
|
|
|
2018-08-30 16:12:21 +02:00
|
|
|
private IPony pony;
|
2018-07-27 00:10:18 +02:00
|
|
|
|
|
|
|
private IRenderPony<T> renderer;
|
|
|
|
|
2018-08-20 21:25:11 +02:00
|
|
|
public static void enableModelRenderProfile() {
|
|
|
|
GlStateManager.enableBlend();
|
|
|
|
GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
|
|
|
|
GlStateManager.alphaFunc(516, 0.003921569F);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void disableModelRenderProfile() {
|
|
|
|
GlStateManager.disableBlend();
|
|
|
|
}
|
|
|
|
|
2018-07-27 00:10:18 +02:00
|
|
|
public RenderPony(IRenderPony<T> renderer) {
|
|
|
|
this.renderer = renderer;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void preRenderCallback(T entity, float ticks) {
|
|
|
|
updateModel(entity);
|
|
|
|
|
|
|
|
ponyModel.updateLivingState(entity, pony);
|
|
|
|
|
|
|
|
float s = getScaleFactor();
|
|
|
|
GlStateManager.scale(s, s, s);
|
2018-08-20 21:25:11 +02:00
|
|
|
enableModelRenderProfile();
|
2018-09-19 19:43:23 +02:00
|
|
|
|
|
|
|
if (entity.isRiding()) {
|
|
|
|
Entity ridingEntity = entity.getRidingEntity();
|
|
|
|
|
|
|
|
if (ridingEntity instanceof EntityLivingBase) {
|
|
|
|
|
|
|
|
IRenderPony<EntityLivingBase> renderer = MineLittlePony.getInstance().getRenderManager().getPonyRenderer((EntityLivingBase)ridingEntity);
|
|
|
|
|
|
|
|
if (renderer != null) {
|
|
|
|
// negate vanilla translations so the rider begins at the ridees feet.
|
|
|
|
GlStateManager.translate(0, entity.getYOffset() + ridingEntity.getMountedYOffset(), 0);
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
IPony riderPony = renderer.getEntityPony((EntityLivingBase)ridingEntity);
|
|
|
|
|
|
|
|
renderer.translateRider((EntityLivingBase)ridingEntity, riderPony, entity, pony, ticks);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-27 00:10:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
public void applyPostureTransform(T player, float pitch, float yaw, float ticks) {
|
|
|
|
PonyPosture<?> posture = getPosture(player);
|
|
|
|
if (posture != null && posture.applies(player)) {
|
|
|
|
double motionX = player.posX - player.prevPosX;
|
|
|
|
double motionY = player.onGround ? 0 : player.posY - player.prevPosY;
|
|
|
|
double motionZ = player.posZ - player.prevPosZ;
|
|
|
|
((PonyPosture<EntityLivingBase>)posture).transform(ponyModel, player, motionX, motionY, motionZ, pitch, yaw, ticks);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-19 19:43:23 +02:00
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
public void applyPostureRiding(T player, float pitch, float yaw, float ticks) {
|
|
|
|
PonyPosture<?> posture = getPosture(player);
|
|
|
|
if (posture != null && posture.applies(player)) {
|
|
|
|
double motionX = player.posX - player.prevPosX;
|
|
|
|
double motionY = player.onGround ? 0 : player.posY - player.prevPosY;
|
|
|
|
double motionZ = player.posZ - player.prevPosZ;
|
|
|
|
|
|
|
|
((PonyPosture<EntityLivingBase>)posture).transform(ponyModel, player, motionX, -motionY, motionZ, pitch, yaw, ticks);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-27 00:10:18 +02:00
|
|
|
private PonyPosture<?> getPosture(T entity) {
|
|
|
|
if (entity.isElytraFlying()) {
|
|
|
|
return PonyPosture.ELYTRA;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (entity.isEntityAlive() && entity.isPlayerSleeping()) return null;
|
|
|
|
|
|
|
|
if (ponyModel.isSwimming()) {
|
|
|
|
return PonyPosture.SWIMMING;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ponyModel.isGoingFast()) {
|
|
|
|
return PonyPosture.FLIGHT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PonyPosture.FALLING;
|
|
|
|
}
|
|
|
|
|
|
|
|
public AbstractPonyModel setPonyModel(ModelWrapper model) {
|
|
|
|
playerModel = model;
|
|
|
|
ponyModel = playerModel.getBody();
|
|
|
|
|
|
|
|
return ponyModel;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void updateModel(T entity) {
|
|
|
|
pony = renderer.getEntityPony(entity);
|
|
|
|
playerModel.apply(pony.getMetadata());
|
|
|
|
}
|
|
|
|
|
2018-08-30 16:12:21 +02:00
|
|
|
public IPony getPony(T entity) {
|
2018-07-27 00:10:18 +02:00
|
|
|
updateModel(entity);
|
|
|
|
return pony;
|
|
|
|
}
|
|
|
|
|
|
|
|
public float getShadowScale() {
|
|
|
|
return ponyModel.getSize().getShadowSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
public float getScaleFactor() {
|
|
|
|
return ponyModel.getSize().getScaleFactor();
|
|
|
|
}
|
2018-09-05 11:33:48 +02:00
|
|
|
|
|
|
|
public double getNamePlateYOffset(T entity, double initial) {
|
|
|
|
|
|
|
|
// We start by negating the height calculation done by mohjong.
|
|
|
|
float y = -(entity.height + 0.5F - (entity.isSneaking() ? 0.25F : 0));
|
|
|
|
|
|
|
|
// Then we add our own offsets.
|
2018-09-05 13:56:07 +02:00
|
|
|
y += ponyModel.getModelHeight() * getScaleFactor() + 0.25F;
|
2018-09-05 11:33:48 +02:00
|
|
|
|
|
|
|
if (entity.isSneaking()) {
|
2018-09-05 13:56:07 +02:00
|
|
|
y -= 0.25F;
|
2018-09-05 11:33:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return initial + y;
|
|
|
|
}
|
2018-07-27 00:10:18 +02:00
|
|
|
}
|