2019-03-23 20:49:34 +01:00
|
|
|
package com.minelittlepony.client.render;
|
|
|
|
|
2021-02-06 15:52:06 +01:00
|
|
|
import com.minelittlepony.api.model.ModelAttributes;
|
2020-04-03 23:54:12 +02:00
|
|
|
import com.minelittlepony.api.pony.IPony;
|
2019-07-12 17:06:03 +02:00
|
|
|
import com.minelittlepony.client.MineLittlePony;
|
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-11-26 22:55:39 +01:00
|
|
|
import com.minelittlepony.mson.api.ModelKey;
|
2019-11-30 13:56:07 +01:00
|
|
|
import com.minelittlepony.util.MathUtil;
|
2019-12-07 11:10:39 +01:00
|
|
|
import com.mojang.blaze3d.platform.GlStateManager.DstFactor;
|
|
|
|
import com.mojang.blaze3d.platform.GlStateManager.SrcFactor;
|
2019-11-23 18:28:42 +01:00
|
|
|
import com.mojang.blaze3d.systems.RenderSystem;
|
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-11-23 18:28:42 +01:00
|
|
|
import net.minecraft.client.render.Frustum;
|
2019-05-27 17:59:15 +02:00
|
|
|
import net.minecraft.client.render.entity.model.EntityModel;
|
2019-11-23 18:28:42 +01:00
|
|
|
import net.minecraft.client.util.math.MatrixStack;
|
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;
|
2019-10-04 21:31:48 +02:00
|
|
|
import net.minecraft.util.Identifier;
|
2018-07-27 00:10:18 +02:00
|
|
|
|
2019-11-29 16:26:19 +01:00
|
|
|
public class EquineRenderManager<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-11-29 16:26:19 +01:00
|
|
|
private final IPonyRenderContext<T, M> renderer;
|
2018-07-27 00:10:18 +02:00
|
|
|
|
2019-07-14 15:01:31 +02:00
|
|
|
private boolean skipBlend;
|
|
|
|
|
2019-05-28 01:50:45 +02:00
|
|
|
private final FrustrumCheck<T> frustrum = new FrustrumCheck<>(this);
|
2018-09-20 14:32:54 +02:00
|
|
|
|
2019-07-14 15:01:31 +02:00
|
|
|
public static void enableModelRenderProfile(boolean skipBlend) {
|
2019-11-23 18:28:42 +01:00
|
|
|
RenderSystem.enableBlend();
|
2019-07-14 15:01:31 +02:00
|
|
|
if (!skipBlend) {
|
2019-12-07 11:10:39 +01:00
|
|
|
RenderSystem.blendFunc(SrcFactor.SRC_ALPHA, DstFactor.ONE_MINUS_SRC_ALPHA);
|
2019-07-14 15:01:31 +02:00
|
|
|
}
|
2018-08-20 21:25:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void disableModelRenderProfile() {
|
2019-11-23 18:28:42 +01:00
|
|
|
RenderSystem.disableBlend();
|
2018-08-20 21:25:11 +02:00
|
|
|
}
|
|
|
|
|
2019-11-29 16:26:19 +01:00
|
|
|
public EquineRenderManager(IPonyRenderContext<T, M> renderer) {
|
2018-07-27 00:10:18 +02:00
|
|
|
this.renderer = renderer;
|
|
|
|
}
|
|
|
|
|
2019-07-14 15:01:31 +02:00
|
|
|
public void setSkipBlend() {
|
|
|
|
skipBlend = true;
|
|
|
|
}
|
|
|
|
|
2019-11-23 18:28:42 +01:00
|
|
|
public Frustum getFrustrum(T entity, Frustum vanilla) {
|
2019-07-12 17:06:03 +02:00
|
|
|
if (entity.isSleeping() || !MineLittlePony.getInstance().getConfig().frustrum.get()) {
|
2018-09-20 14:32:54 +02:00
|
|
|
return vanilla;
|
|
|
|
}
|
|
|
|
return frustrum.withCamera(entity, vanilla);
|
|
|
|
}
|
|
|
|
|
2019-11-23 18:28:42 +01:00
|
|
|
public void preRenderCallback(T entity, MatrixStack stack, float ticks) {
|
2021-02-06 15:52:06 +01:00
|
|
|
updateModel(entity, ModelAttributes.Mode.THIRD_PERSON);
|
2018-07-27 00:10:18 +02:00
|
|
|
|
|
|
|
float s = getScaleFactor();
|
2019-11-23 18:28:42 +01:00
|
|
|
stack.scale(s, s, s);
|
2019-07-14 15:01:31 +02:00
|
|
|
enableModelRenderProfile(skipBlend);
|
2018-09-19 19:43:23 +02:00
|
|
|
|
2019-11-23 18:28:42 +01:00
|
|
|
translateRider(entity, stack, ticks);
|
2018-09-20 11:33:27 +02:00
|
|
|
}
|
|
|
|
|
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();
|
2019-07-07 23:20:50 +02:00
|
|
|
if (mount instanceof LivingEntity) {
|
2019-11-22 18:24:22 +01:00
|
|
|
return MathUtil.interpolateDegress(((LivingEntity) mount).prevBodyYaw, ((LivingEntity) mount).bodyYaw, partialTicks);
|
2018-10-29 16:57:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rotationYaw;
|
|
|
|
}
|
|
|
|
|
2019-11-23 18:28:42 +01:00
|
|
|
protected void translateRider(T entity, MatrixStack stack, float ticks) {
|
2019-07-07 23:20:50 +02:00
|
|
|
if (entity.hasVehicle() && entity.getVehicle() instanceof LivingEntity) {
|
2018-09-19 19:43:23 +02:00
|
|
|
|
2019-07-07 23:20:50 +02:00
|
|
|
LivingEntity ridingEntity = (LivingEntity) entity.getVehicle();
|
2019-11-30 12:12:46 +01:00
|
|
|
IPonyRenderContext<LivingEntity, ?> renderer = PonyRenderDispatcher.getInstance().getPonyRenderer(ridingEntity);
|
2018-09-19 19:43:23 +02:00
|
|
|
|
2019-07-07 23:20:50 +02:00
|
|
|
if (renderer != null) {
|
|
|
|
// negate vanilla translations so the rider begins at the ridees feet.
|
2019-11-23 18:28:42 +01:00
|
|
|
stack.translate(0, -ridingEntity.getHeight(), 0);
|
2018-09-19 19:43:23 +02:00
|
|
|
|
2019-07-07 23:20:50 +02:00
|
|
|
IPony riderPony = renderer.getEntityPony(ridingEntity);
|
2018-09-19 19:43:23 +02:00
|
|
|
|
2019-11-23 18:28:42 +01:00
|
|
|
renderer.translateRider(ridingEntity, riderPony, entity, pony, stack, ticks);
|
2018-09-19 19:43:23 +02:00
|
|
|
}
|
|
|
|
}
|
2018-07-27 00:10:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
2019-11-23 18:28:42 +01:00
|
|
|
public void applyPostureTransform(T player, MatrixStack stack, float yaw, float ticks) {
|
|
|
|
((PonyPosture<T>) getPosture(player)).apply(player, getModel(), stack, yaw, ticks, 1);
|
2018-07-27 00:10:18 +02:00
|
|
|
}
|
|
|
|
|
2018-09-19 19:43:23 +02:00
|
|
|
@SuppressWarnings("unchecked")
|
2019-11-23 18:28:42 +01:00
|
|
|
public void applyPostureRiding(T player, MatrixStack stack, float yaw, float ticks) {
|
|
|
|
((PonyPosture<T>) getPosture(player)).apply(player, getModel(), stack, 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()) {
|
2021-02-28 23:16:39 +01:00
|
|
|
return PonyPosture.STANDING;
|
2019-03-24 18:55:15 +01:00
|
|
|
}
|
2018-07-27 00:10:18 +02:00
|
|
|
|
2021-02-28 23:16:39 +01:00
|
|
|
if (getModel().getAttributes().isHorizontal) {
|
2018-07-27 00:10:18 +02:00
|
|
|
return PonyPosture.SWIMMING;
|
|
|
|
}
|
|
|
|
|
2021-06-07 16:27:54 +02:00
|
|
|
if (getModel().getAttributes().isGoingFast && !getModel().getAttributes().isRiptide) {
|
2021-02-28 23:16:39 +01:00
|
|
|
return PonyPosture.FLYING;
|
2018-07-27 00:10:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return PonyPosture.FALLING;
|
|
|
|
}
|
|
|
|
|
2019-05-28 01:50:45 +02:00
|
|
|
public M getModel() {
|
|
|
|
return playerModel.getBody();
|
|
|
|
}
|
|
|
|
|
2020-02-21 15:50:45 +01:00
|
|
|
public ModelWrapper<T, M> getModelWrapper() {
|
|
|
|
return playerModel;
|
|
|
|
}
|
|
|
|
|
2019-11-29 16:26:19 +01:00
|
|
|
public ModelWrapper<T, M> setModel(ModelKey<?> key) {
|
|
|
|
playerModel = new ModelWrapper<>(key);
|
2018-07-27 00:10:18 +02:00
|
|
|
|
2019-11-26 22:55:39 +01:00
|
|
|
return playerModel;
|
2018-07-27 00:10:18 +02:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:50:45 +01:00
|
|
|
public ModelWrapper<T, M> setModel(ModelWrapper<T, M> wrapper) {
|
|
|
|
playerModel = wrapper;
|
|
|
|
return wrapper;
|
|
|
|
}
|
|
|
|
|
2019-10-04 21:31:48 +02:00
|
|
|
public void updateMetadata(Identifier texture) {
|
|
|
|
pony = MineLittlePony.getInstance().getManager().getPony(texture);
|
2021-02-06 15:52:06 +01:00
|
|
|
playerModel.applyMetadata(pony.getMetadata());
|
2019-10-04 21:31:48 +02:00
|
|
|
}
|
|
|
|
|
2021-02-06 15:52:06 +01:00
|
|
|
public void updateModel(T entity, ModelAttributes.Mode mode) {
|
2018-07-27 00:10:18 +02:00
|
|
|
pony = renderer.getEntityPony(entity);
|
2021-02-06 15:52:06 +01:00
|
|
|
playerModel.applyMetadata(pony.getMetadata());
|
2019-07-03 15:58:28 +02:00
|
|
|
pony.updateForEntity(entity);
|
2019-07-06 17:35:11 +02:00
|
|
|
|
2019-11-30 11:14:52 +01:00
|
|
|
getModel().updateLivingState(entity, pony, mode);
|
2018-07-27 00:10:18 +02:00
|
|
|
}
|
|
|
|
|
2018-08-30 16:12:21 +02:00
|
|
|
public IPony getPony(T entity) {
|
2021-02-06 15:52:06 +01:00
|
|
|
updateModel(entity, ModelAttributes.Mode.THIRD_PERSON);
|
2018-07-27 00:10:18 +02:00
|
|
|
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
|
|
|
|
2019-11-23 18:28:42 +01:00
|
|
|
public double getNamePlateYOffset(T entity) {
|
2018-09-05 11:33:48 +02:00
|
|
|
|
2019-06-24 11:25:39 +02:00
|
|
|
// We start by negating the height calculation done by mahjong.
|
2021-03-11 15:18:12 +01:00
|
|
|
float y = -(entity.getHeight() + 0.5F);
|
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;
|
|
|
|
}
|
|
|
|
|
2019-11-23 18:28:42 +01:00
|
|
|
return y;
|
2018-09-05 11:33:48 +02:00
|
|
|
}
|
2018-07-27 00:10:18 +02:00
|
|
|
}
|