mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2024-11-22 20:47:59 +01:00
Allow for mounted ponies to translate riding ponies onto their mount's backs, and apply postures to them
This commit is contained in:
parent
cd27adb14e
commit
ff57ec8e40
7 changed files with 93 additions and 0 deletions
|
@ -4,6 +4,7 @@ import java.util.Map;
|
|||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.minelittlepony.mixin.MixinRenderManager;
|
||||
import com.minelittlepony.ducks.IRenderPony;
|
||||
import com.minelittlepony.hdskins.gui.EntityPonyModel;
|
||||
import com.minelittlepony.hdskins.gui.RenderPonyModel;
|
||||
import com.minelittlepony.model.player.PlayerModels;
|
||||
|
@ -12,9 +13,14 @@ import com.minelittlepony.render.player.RenderPonyPlayer;
|
|||
import com.minelittlepony.render.ponies.MobRenderers;
|
||||
import com.mumfrey.liteloader.util.ModUtilities;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.entity.Render;
|
||||
import net.minecraft.client.renderer.entity.RenderLivingBase;
|
||||
import net.minecraft.client.renderer.entity.RenderManager;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
|
||||
/**
|
||||
* Render manager responsible for replacing and restoring entity renderers when the client settings change.
|
||||
|
@ -88,4 +94,16 @@ public class PonyRenderManager {
|
|||
public LevitatingItemRenderer getMagicRenderer() {
|
||||
return magicRenderer;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Nullable
|
||||
public <T extends EntityLivingBase, R extends RenderLivingBase<T> & IRenderPony<T>> R getPonyRenderer(T entity) {
|
||||
Render<Entity> renderer = Minecraft.getMinecraft().getRenderManager().getEntityRenderObject(entity);
|
||||
|
||||
if (renderer instanceof RenderLivingBase && renderer instanceof IRenderPony) {
|
||||
return (R)(Object)renderer;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,10 @@ package com.minelittlepony.ducks;
|
|||
|
||||
import com.minelittlepony.model.ModelWrapper;
|
||||
import com.minelittlepony.pony.data.IPony;
|
||||
import com.minelittlepony.render.RenderPony;
|
||||
import com.minelittlepony.util.math.MathUtil;
|
||||
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
|
||||
/**
|
||||
|
@ -16,4 +19,19 @@ public interface IRenderPony<T extends EntityLivingBase> {
|
|||
ModelWrapper getModelWrapper();
|
||||
|
||||
IPony getEntityPony(T entity);
|
||||
|
||||
RenderPony<T> getInternalRenderer();
|
||||
|
||||
/**
|
||||
* Called by riders to have their transportation adjust their position.
|
||||
*/
|
||||
default void translateRider(T entity, IPony entityPony, EntityLivingBase passenger, IPony passengerPony, float ticks) {
|
||||
if (!passengerPony.getRace(false).isHuman()) {
|
||||
float yaw = MathUtil.interpolateDegress(entity.prevRenderYawOffset, entity.renderYawOffset, ticks);
|
||||
|
||||
GlStateManager.translate(0, 0, 0.8F);
|
||||
|
||||
getInternalRenderer().applyPostureRiding(entity, entity.ticksExisted + ticks, yaw, ticks);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -111,4 +111,9 @@ public class RenderPonyModel extends RenderPlayerModel<EntityPonyModel> implemen
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public RenderPony<EntityPonyModel> getInternalRenderer() {
|
||||
return renderPony;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.minelittlepony.render;
|
||||
|
||||
import com.minelittlepony.MineLittlePony;
|
||||
import com.minelittlepony.ducks.IRenderPony;
|
||||
import com.minelittlepony.model.AbstractPonyModel;
|
||||
import com.minelittlepony.model.ModelWrapper;
|
||||
|
@ -7,6 +8,7 @@ import com.minelittlepony.pony.data.IPony;
|
|||
import com.minelittlepony.transform.PonyPosture;
|
||||
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
|
||||
public class RenderPony<T extends EntityLivingBase> {
|
||||
|
@ -41,6 +43,25 @@ public class RenderPony<T extends EntityLivingBase> {
|
|||
float s = getScaleFactor();
|
||||
GlStateManager.scale(s, s, s);
|
||||
enableModelRenderProfile();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -54,6 +75,18 @@ public class RenderPony<T extends EntityLivingBase> {
|
|||
}
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
private PonyPosture<?> getPosture(T entity) {
|
||||
if (entity.isElytraFlying()) {
|
||||
return PonyPosture.ELYTRA;
|
||||
|
|
|
@ -11,6 +11,7 @@ import com.minelittlepony.render.layer.LayerPonyArmor;
|
|||
import com.minelittlepony.render.layer.LayerPonyCustomHead;
|
||||
import com.minelittlepony.render.layer.LayerPonyElytra;
|
||||
import com.voxelmodpack.hdskins.HDSkinManager;
|
||||
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.entity.RenderLiving;
|
||||
import net.minecraft.client.renderer.entity.RenderManager;
|
||||
|
@ -92,6 +93,11 @@ public abstract class RenderPonyMob<T extends EntityLiving> extends RenderLiving
|
|||
return HDSkinManager.INSTANCE.getConvertedSkin(getTexture(entity));
|
||||
}
|
||||
|
||||
@Override
|
||||
public RenderPony<T> getInternalRenderer() {
|
||||
return renderPony;
|
||||
}
|
||||
|
||||
protected abstract ResourceLocation getTexture(T entity);
|
||||
|
||||
public abstract static class Proxy<T extends EntityLiving> extends RenderPonyMob<T> {
|
||||
|
|
|
@ -138,4 +138,8 @@ public class RenderPonyPlayer extends RenderPlayer implements IRenderPony<Abstra
|
|||
return MineLittlePony.getInstance().getManager().getPony(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RenderPony<AbstractClientPlayer> getInternalRenderer() {
|
||||
return renderPony;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,4 +16,13 @@ public class MathUtil {
|
|||
|
||||
return angle;
|
||||
}
|
||||
|
||||
public static float interpolateDegress(float prev, float current, float partialTicks) {
|
||||
float difference = current - prev;
|
||||
|
||||
while (difference < -180) difference += 360;
|
||||
while (difference >= 180) difference -= 360;
|
||||
|
||||
return prev + partialTicks * difference;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue