2019-03-23 20:49:34 +01:00
|
|
|
package com.minelittlepony.client.render;
|
|
|
|
|
|
|
|
import com.minelittlepony.client.PonyRenderManager;
|
2019-06-24 11:25:39 +02:00
|
|
|
import com.minelittlepony.client.model.IPonyModel;
|
2019-03-23 20:49:34 +01:00
|
|
|
import com.minelittlepony.client.model.ModelWrapper;
|
|
|
|
import com.minelittlepony.client.transform.PonyPosture;
|
2019-03-23 20:58:50 +01:00
|
|
|
import com.minelittlepony.pony.IPony;
|
2019-05-28 10:26:26 +02:00
|
|
|
import com.minelittlepony.settings.PonySettings;
|
2018-10-29 16:57:43 +01:00
|
|
|
import com.minelittlepony.util.math.MathUtil;
|
2019-05-27 17:59:15 +02:00
|
|
|
import com.mojang.blaze3d.platform.GlStateManager;
|
2018-07-27 00:10:18 +02:00
|
|
|
|
2019-05-28 01:50:45 +02:00
|
|
|
import javax.annotation.Nonnull;
|
2019-03-24 18:55:15 +01:00
|
|
|
|
2019-05-27 17:59:15 +02:00
|
|
|
import net.minecraft.client.render.VisibleRegion;
|
|
|
|
import net.minecraft.client.render.entity.model.EntityModel;
|
2018-09-19 19:43:23 +02:00
|
|
|
import net.minecraft.entity.Entity;
|
2019-05-27 17:59:15 +02:00
|
|
|
import net.minecraft.entity.LivingEntity;
|
2018-07-27 00:10:18 +02:00
|
|
|
|
2019-05-27 17:59:15 +02:00
|
|
|
public class RenderPony<T extends LivingEntity, M extends EntityModel<T> & IPonyModel<T>> {
|
2018-07-27 00:10:18 +02:00
|
|
|
|
2019-05-27 17:59:15 +02:00
|
|
|
public ModelWrapper<T, M> playerModel;
|
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
|
|
|
|
2019-05-28 01:50:45 +02:00
|
|
|
private final IPonyRender<T, M> renderer;
|
2018-07-27 00:10:18 +02:00
|
|
|
|
2019-05-28 01:50:45 +02:00
|
|
|
private final FrustrumCheck<T> frustrum = new FrustrumCheck<>(this);
|
2018-09-20 14:32:54 +02:00
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2019-05-27 17:59:15 +02:00
|
|
|
public RenderPony(IPonyRender<T, M> renderer) {
|
2018-07-27 00:10:18 +02:00
|
|
|
this.renderer = renderer;
|
|
|
|
}
|
|
|
|
|
2019-05-27 17:59:15 +02:00
|
|
|
public VisibleRegion getFrustrum(T entity, VisibleRegion vanilla) {
|
2019-05-28 10:26:26 +02:00
|
|
|
if (entity.isSleeping() || !PonySettings.FRUSTRUM.get()) {
|
2018-09-20 14:32:54 +02:00
|
|
|
return vanilla;
|
|
|
|
}
|
|
|
|
return frustrum.withCamera(entity, vanilla);
|
|
|
|
}
|
|
|
|
|
2018-07-27 00:10:18 +02:00
|
|
|
public void preRenderCallback(T entity, float ticks) {
|
|
|
|
updateModel(entity);
|
|
|
|
|
2019-06-24 11:25:39 +02:00
|
|
|
getModel().updateLivingState(entity, pony);
|
2018-07-27 00:10:18 +02:00
|
|
|
|
|
|
|
float s = getScaleFactor();
|
2019-03-24 18:55:15 +01:00
|
|
|
GlStateManager.scalef(s, s, s);
|
2018-08-20 21:25:11 +02:00
|
|
|
enableModelRenderProfile();
|
2018-09-19 19:43:23 +02:00
|
|
|
|
2018-09-20 11:33:27 +02:00
|
|
|
translateRider(entity, ticks);
|
|
|
|
}
|
|
|
|
|
2018-10-29 16:57:43 +01:00
|
|
|
public float getRenderYaw(T entity, float rotationYaw, float partialTicks) {
|
2019-05-27 17:59:15 +02:00
|
|
|
if (entity.hasVehicle()) {
|
|
|
|
Entity mount = entity.getVehicle();
|
|
|
|
if (mount instanceof LivingEntity) {
|
|
|
|
return MathUtil.interpolateDegress(((LivingEntity)mount).field_6220, ((LivingEntity)mount).field_6283, partialTicks);
|
2018-10-29 16:57:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rotationYaw;
|
|
|
|
}
|
|
|
|
|
2019-05-27 17:59:15 +02:00
|
|
|
protected void translateRider(LivingEntity entity, float ticks) {
|
|
|
|
if (entity.hasVehicle()) {
|
|
|
|
Entity ridingEntity = entity.getVehicle();
|
2018-09-19 19:43:23 +02:00
|
|
|
|
2019-05-27 17:59:15 +02:00
|
|
|
if (ridingEntity instanceof LivingEntity) {
|
|
|
|
IPonyRender<LivingEntity, ?> renderer = PonyRenderManager.getInstance().getPonyRenderer((LivingEntity)ridingEntity);
|
2018-09-19 19:43:23 +02:00
|
|
|
|
|
|
|
if (renderer != null) {
|
|
|
|
// negate vanilla translations so the rider begins at the ridees feet.
|
2019-05-27 17:59:15 +02:00
|
|
|
GlStateManager.translatef(0, -ridingEntity.getHeight(), 0);
|
2018-09-19 19:43:23 +02:00
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
2019-05-27 17:59:15 +02:00
|
|
|
IPony riderPony = renderer.getEntityPony((LivingEntity)ridingEntity);
|
2018-09-19 19:43:23 +02:00
|
|
|
|
2019-05-27 17:59:15 +02:00
|
|
|
renderer.translateRider((LivingEntity)ridingEntity, riderPony, entity, pony, ticks);
|
2018-09-19 19:43:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-27 00:10:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
2018-10-29 16:57:43 +01:00
|
|
|
public void applyPostureTransform(T player, float yaw, float ticks) {
|
2019-06-24 11:25:39 +02:00
|
|
|
((PonyPosture<T>)getPosture(player)).apply(player, getModel(), yaw, ticks, 1);
|
2018-07-27 00:10:18 +02:00
|
|
|
}
|
|
|
|
|
2018-09-19 19:43:23 +02:00
|
|
|
@SuppressWarnings("unchecked")
|
2018-10-29 16:57:43 +01:00
|
|
|
public void applyPostureRiding(T player, float yaw, float ticks) {
|
2019-06-24 11:25:39 +02:00
|
|
|
((PonyPosture<T>)getPosture(player)).apply(player, getModel(), yaw, ticks, -1);
|
2018-09-19 19:43:23 +02:00
|
|
|
}
|
|
|
|
|
2019-05-28 01:50:45 +02:00
|
|
|
@Nonnull
|
2018-07-27 00:10:18 +02:00
|
|
|
private PonyPosture<?> getPosture(T entity) {
|
2019-05-27 17:59:15 +02:00
|
|
|
if (entity.isFallFlying()) {
|
2018-07-27 00:10:18 +02:00
|
|
|
return PonyPosture.ELYTRA;
|
|
|
|
}
|
|
|
|
|
2019-05-27 17:59:15 +02:00
|
|
|
if (entity.isAlive() && entity.isSleeping()) {
|
2019-05-28 01:50:45 +02:00
|
|
|
return PonyPosture.DEFAULT;
|
2019-03-24 18:55:15 +01:00
|
|
|
}
|
2018-07-27 00:10:18 +02:00
|
|
|
|
2019-06-24 11:25:39 +02:00
|
|
|
if (getModel().getAttributes().isSwimming) {
|
2018-07-27 00:10:18 +02:00
|
|
|
return PonyPosture.SWIMMING;
|
|
|
|
}
|
|
|
|
|
2019-06-24 11:25:39 +02:00
|
|
|
if (getModel().getAttributes().isGoingFast) {
|
2018-07-27 00:10:18 +02:00
|
|
|
return PonyPosture.FLIGHT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PonyPosture.FALLING;
|
|
|
|
}
|
|
|
|
|
2019-05-28 01:50:45 +02:00
|
|
|
public M getModel() {
|
|
|
|
return playerModel.getBody();
|
|
|
|
}
|
|
|
|
|
2019-05-27 17:59:15 +02:00
|
|
|
public M setPonyModel(ModelWrapper<T, M> model) {
|
2018-07-27 00:10:18 +02:00
|
|
|
playerModel = model;
|
|
|
|
|
2019-06-24 11:25:39 +02:00
|
|
|
return getModel();
|
2018-07-27 00:10:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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() {
|
2019-05-28 01:50:45 +02:00
|
|
|
return getModel().getSize().getShadowSize();
|
2018-07-27 00:10:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public float getScaleFactor() {
|
2019-05-28 01:50:45 +02:00
|
|
|
return getModel().getSize().getScaleFactor();
|
2018-07-27 00:10:18 +02:00
|
|
|
}
|
2018-09-05 11:33:48 +02:00
|
|
|
|
|
|
|
public double getNamePlateYOffset(T entity, double initial) {
|
|
|
|
|
2019-06-24 11:25:39 +02:00
|
|
|
// We start by negating the height calculation done by mahjong.
|
2019-05-27 17:59:15 +02:00
|
|
|
float y = -(entity.getHeight() + 0.5F - (entity.isSneaking() ? 0.25F : 0));
|
2018-09-05 11:33:48 +02:00
|
|
|
|
|
|
|
// Then we add our own offsets.
|
2019-06-24 11:25:39 +02:00
|
|
|
y += getModel().getAttributes().visualHeight * 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
|
|
|
}
|
|
|
|
|
2019-05-27 17:59:15 +02:00
|
|
|
if (entity.hasVehicle()) {
|
|
|
|
y += entity.getVehicle().getEyeHeight(entity.getPose());
|
2018-10-28 21:24:27 +01:00
|
|
|
}
|
|
|
|
|
2019-05-27 17:59:15 +02:00
|
|
|
if (entity.isSleeping()) {
|
2018-10-28 21:24:27 +01:00
|
|
|
y /= 2;
|
|
|
|
}
|
|
|
|
|
2018-09-05 11:33:48 +02:00
|
|
|
return initial + y;
|
|
|
|
}
|
2018-07-27 00:10:18 +02:00
|
|
|
}
|