mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2024-11-26 14:27:59 +01:00
Clean up some dank around the IRenderPony(s)
This commit is contained in:
parent
302a8a22ad
commit
7f12104ec5
11 changed files with 145 additions and 143 deletions
|
@ -1,24 +1,19 @@
|
|||
package com.minelittlepony.ducks;
|
||||
|
||||
import com.minelittlepony.model.ModelWrapper;
|
||||
import com.minelittlepony.pony.data.Pony;
|
||||
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
|
||||
/**
|
||||
* I Render Pony now, oky?
|
||||
*/
|
||||
public interface IRenderPony {
|
||||
public interface IRenderPony<T extends EntityLivingBase> {
|
||||
|
||||
/**
|
||||
* Gets the wrapped pony model for this renderer.
|
||||
*/
|
||||
ModelWrapper getModelWrapper();
|
||||
|
||||
/**
|
||||
* Gets the current shadow size for rendering.
|
||||
*/
|
||||
float getShadowScale();
|
||||
|
||||
/**
|
||||
* Gets the scaling factor used when rendering this pony.
|
||||
*/
|
||||
float getScaleFactor();
|
||||
Pony getEntityPony(T entity);
|
||||
}
|
||||
|
|
88
src/main/java/com/minelittlepony/render/RenderPony.java
Normal file
88
src/main/java/com/minelittlepony/render/RenderPony.java
Normal file
|
@ -0,0 +1,88 @@
|
|||
package com.minelittlepony.render;
|
||||
|
||||
import com.minelittlepony.ducks.IRenderPony;
|
||||
import com.minelittlepony.model.AbstractPonyModel;
|
||||
import com.minelittlepony.model.ModelWrapper;
|
||||
import com.minelittlepony.pony.data.Pony;
|
||||
import com.minelittlepony.transform.PonyPosture;
|
||||
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
|
||||
public class RenderPony<T extends EntityLivingBase> {
|
||||
|
||||
public ModelWrapper playerModel;
|
||||
|
||||
private AbstractPonyModel ponyModel;
|
||||
|
||||
private Pony pony;
|
||||
|
||||
private IRenderPony<T> renderer;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
public Pony getPony(T entity) {
|
||||
updateModel(entity);
|
||||
return pony;
|
||||
}
|
||||
|
||||
public float getShadowScale() {
|
||||
return ponyModel.getSize().getShadowSize();
|
||||
}
|
||||
|
||||
public float getScaleFactor() {
|
||||
return ponyModel.getSize().getScaleFactor();
|
||||
}
|
||||
}
|
|
@ -2,7 +2,6 @@ package com.minelittlepony.render;
|
|||
|
||||
import com.minelittlepony.MineLittlePony;
|
||||
import com.minelittlepony.ducks.IRenderPony;
|
||||
import com.minelittlepony.model.AbstractPonyModel;
|
||||
import com.minelittlepony.model.ModelWrapper;
|
||||
import com.minelittlepony.pony.data.Pony;
|
||||
import com.minelittlepony.render.layer.LayerHeldPonyItem;
|
||||
|
@ -23,18 +22,14 @@ import javax.annotation.Nonnull;
|
|||
|
||||
// TODO: A lot of this duplicates RenderPonyPlayer
|
||||
// and is the whole reason we had this scaling bug in the first place.
|
||||
public abstract class RenderPonyMob<T extends EntityLiving> extends RenderLiving<T> implements IRenderPony {
|
||||
public abstract class RenderPonyMob<T extends EntityLiving> extends RenderLiving<T> implements IRenderPony<T> {
|
||||
|
||||
protected ModelWrapper playerModel;
|
||||
|
||||
protected AbstractPonyModel ponyModel;
|
||||
|
||||
private Pony pony;
|
||||
protected final RenderPony<T> renderPony = new RenderPony<T>(this);
|
||||
|
||||
public RenderPonyMob(RenderManager manager, ModelWrapper model) {
|
||||
super(manager, model.getBody(), 0.5F);
|
||||
|
||||
setPonyModel(model);
|
||||
mainModel = renderPony.setPonyModel(model);
|
||||
|
||||
addLayers();
|
||||
}
|
||||
|
@ -60,14 +55,9 @@ public abstract class RenderPonyMob<T extends EntityLiving> extends RenderLiving
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void preRenderCallback(T entity, float ticks) {
|
||||
updateModel(entity);
|
||||
|
||||
ponyModel.updateLivingState(entity, pony);
|
||||
shadowSize = getShadowScale();
|
||||
|
||||
float s = getScaleFactor();
|
||||
GlStateManager.scale(s, s, s);
|
||||
public void preRenderCallback(T entity, float ticks) {
|
||||
renderPony.preRenderCallback(entity, ticks);
|
||||
shadowSize = renderPony.getShadowScale();
|
||||
|
||||
if (!entity.isRiding()) {
|
||||
GlStateManager.translate(0, 0, -entity.width / 2); // move us to the center of the shadow
|
||||
|
@ -78,31 +68,12 @@ public abstract class RenderPonyMob<T extends EntityLiving> extends RenderLiving
|
|||
|
||||
@Override
|
||||
public ModelWrapper getModelWrapper() {
|
||||
return playerModel;
|
||||
}
|
||||
|
||||
protected void setPonyModel(ModelWrapper model) {
|
||||
playerModel = model;
|
||||
mainModel = ponyModel = playerModel.getBody();
|
||||
}
|
||||
|
||||
protected void updatePony(T entity) {
|
||||
pony = MineLittlePony.getInstance().getManager().getPony(getEntityTexture(entity), false);
|
||||
}
|
||||
|
||||
protected void updateModel(T entity) {
|
||||
updatePony(entity);
|
||||
playerModel.apply(pony.getMetadata());
|
||||
return renderPony.playerModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getShadowScale() {
|
||||
return ponyModel.getSize().getShadowSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getScaleFactor() {
|
||||
return ponyModel.getSize().getScaleFactor();
|
||||
public Pony getEntityPony(T entity) {
|
||||
return MineLittlePony.getInstance().getManager().getPony(getEntityTexture(entity), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -124,10 +95,6 @@ public abstract class RenderPonyMob<T extends EntityLiving> extends RenderLiving
|
|||
|
||||
}
|
||||
|
||||
public void preRenderCallback(T entity, float ticks) {
|
||||
super.preRenderCallback(entity, ticks);
|
||||
}
|
||||
|
||||
public final ResourceLocation getTextureFor(T entity) {
|
||||
return super.getEntityTexture(entity);
|
||||
}
|
||||
|
|
|
@ -43,8 +43,8 @@ public abstract class AbstractPonyLayer<T extends EntityLivingBase> implements L
|
|||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected IRenderPony getPonyRenderer() {
|
||||
return (IRenderPony)renderer;
|
||||
protected IRenderPony<T> getPonyRenderer() {
|
||||
return (IRenderPony<T>)renderer;
|
||||
}
|
||||
|
||||
public AbstractPonyModel getPlayerModel() {
|
||||
|
|
|
@ -6,20 +6,18 @@ import java.util.Optional;
|
|||
import com.minelittlepony.MineLittlePony;
|
||||
import com.minelittlepony.PonyConfig;
|
||||
import com.minelittlepony.ducks.IRenderPony;
|
||||
import com.minelittlepony.model.AbstractPonyModel;
|
||||
import com.minelittlepony.model.ModelWrapper;
|
||||
import com.minelittlepony.model.components.ModelDeadMau5Ears;
|
||||
import com.minelittlepony.pony.data.Pony;
|
||||
import com.minelittlepony.pony.data.PonyLevel;
|
||||
import com.minelittlepony.render.PonySkull;
|
||||
import com.minelittlepony.render.RenderPony;
|
||||
import com.minelittlepony.render.PonySkullRenderer.ISkull;
|
||||
import com.minelittlepony.render.layer.LayerEntityOnPonyShoulder;
|
||||
import com.minelittlepony.render.layer.LayerHeldPonyItemMagical;
|
||||
import com.minelittlepony.render.layer.LayerPonyArmor;
|
||||
import com.minelittlepony.render.layer.LayerPonyCape;
|
||||
import com.minelittlepony.render.layer.LayerPonyCustomHead;
|
||||
import com.minelittlepony.render.layer.LayerPonyElytra;
|
||||
import com.minelittlepony.transform.PonyPosture;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
|
||||
|
@ -32,13 +30,13 @@ import net.minecraft.client.renderer.entity.RenderManager;
|
|||
|
||||
import net.minecraft.client.resources.DefaultPlayerSkin;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.EnumHandSide;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.client.renderer.entity.RenderPlayer;
|
||||
import net.minecraft.client.renderer.entity.layers.LayerArrow;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
|
||||
public class RenderPonyPlayer extends RenderPlayer implements IRenderPony {
|
||||
public class RenderPonyPlayer extends RenderPlayer implements IRenderPony<AbstractClientPlayer> {
|
||||
|
||||
public static final ISkull SKULL = new PonySkull() {
|
||||
|
||||
|
@ -84,16 +82,12 @@ public class RenderPonyPlayer extends RenderPlayer implements IRenderPony {
|
|||
}
|
||||
}.register(ISkull.PLAYER);
|
||||
|
||||
private ModelWrapper playerModel;
|
||||
|
||||
protected AbstractPonyModel ponyModel;
|
||||
|
||||
protected Pony pony;
|
||||
protected final RenderPony<AbstractClientPlayer> renderPony = new RenderPony<>(this);
|
||||
|
||||
public RenderPonyPlayer(RenderManager manager, boolean useSmallArms, ModelWrapper model) {
|
||||
super(manager, useSmallArms);
|
||||
|
||||
setPonyModel(model);
|
||||
mainModel = renderPony.setPonyModel(model);
|
||||
|
||||
addLayers();
|
||||
}
|
||||
|
@ -101,7 +95,6 @@ public class RenderPonyPlayer extends RenderPlayer implements IRenderPony {
|
|||
protected void addLayers() {
|
||||
layerRenderers.clear();
|
||||
|
||||
addLayer(new LayerPonyArmor<>(this));
|
||||
addLayer(new LayerArrow(this));
|
||||
addLayer(new LayerPonyCustomHead<>(this));
|
||||
addLayer(new LayerPonyElytra<>(this));
|
||||
|
@ -131,13 +124,8 @@ public class RenderPonyPlayer extends RenderPlayer implements IRenderPony {
|
|||
|
||||
@Override
|
||||
protected void preRenderCallback(AbstractClientPlayer player, float ticks) {
|
||||
updateModel(player);
|
||||
|
||||
ponyModel.updateLivingState(player, pony);
|
||||
shadowSize = getShadowScale();
|
||||
|
||||
float s = getScaleFactor();
|
||||
GlStateManager.scale(s, s, s);
|
||||
renderPony.preRenderCallback(player, ticks);
|
||||
shadowSize = renderPony.getShadowScale();
|
||||
|
||||
if (player.isRiding()) {
|
||||
GlStateManager.translate(0, player.getYOffset(), 0);
|
||||
|
@ -152,89 +140,49 @@ public class RenderPonyPlayer extends RenderPlayer implements IRenderPony {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void renderRightArm(AbstractClientPlayer player) {
|
||||
updateModel(player);
|
||||
bindEntityTexture(player);
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.translate(0, -0.37, 0);
|
||||
super.renderRightArm(player);
|
||||
GlStateManager.popMatrix();
|
||||
public final void renderRightArm(AbstractClientPlayer player) {
|
||||
renderArm(player, EnumHandSide.RIGHT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderLeftArm(AbstractClientPlayer player) {
|
||||
updateModel(player);
|
||||
public final void renderLeftArm(AbstractClientPlayer player) {
|
||||
renderArm(player, EnumHandSide.LEFT);
|
||||
}
|
||||
|
||||
protected void renderArm(AbstractClientPlayer player, EnumHandSide side) {
|
||||
renderPony.updateModel(player);
|
||||
bindEntityTexture(player);
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.translate(0.06, -0.37, 0);
|
||||
super.renderLeftArm(player);
|
||||
GlStateManager.translate(side == EnumHandSide.LEFT ? 0.06 : 0, -0.37, 0);
|
||||
|
||||
if (side == EnumHandSide.LEFT) {
|
||||
super.renderLeftArm(player);
|
||||
} else {
|
||||
super.renderRightArm(player);
|
||||
}
|
||||
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected void applyRotations(AbstractClientPlayer player, float yaw, float pitch, float ticks) {
|
||||
super.applyRotations(player, yaw, pitch, 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(getModelWrapper().getBody(), player, motionX, motionY, motionZ, pitch, yaw, ticks);
|
||||
}
|
||||
}
|
||||
|
||||
protected PonyPosture<?> getPosture(EntityLivingBase entity) {
|
||||
if (entity.isElytraFlying()) {
|
||||
return PonyPosture.ELYTRA;
|
||||
}
|
||||
|
||||
if (entity.isEntityAlive() && entity.isPlayerSleeping()) return null;
|
||||
|
||||
if (getModelWrapper().getBody().isSwimming()) {
|
||||
return PonyPosture.SWIMMING;
|
||||
}
|
||||
|
||||
if (getModelWrapper().getBody().isGoingFast()) {
|
||||
return PonyPosture.FLIGHT;
|
||||
}
|
||||
|
||||
return PonyPosture.FALLING;
|
||||
renderPony.applyPostureTransform(player, yaw, pitch, ticks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getEntityTexture(AbstractClientPlayer player) {
|
||||
updateModel(player);
|
||||
return pony.getTexture();
|
||||
return renderPony.getPony(player).getTexture();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelWrapper getModelWrapper() {
|
||||
return playerModel;
|
||||
}
|
||||
|
||||
protected void setPonyModel(ModelWrapper model) {
|
||||
playerModel = model;
|
||||
mainModel = ponyModel = playerModel.getBody();
|
||||
}
|
||||
|
||||
protected void updatePony(AbstractClientPlayer player) {
|
||||
pony = MineLittlePony.getInstance().getManager().getPony(player);
|
||||
}
|
||||
|
||||
protected void updateModel(AbstractClientPlayer player) {
|
||||
updatePony(player);
|
||||
getModelWrapper().apply(pony.getMetadata());
|
||||
return renderPony.playerModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getShadowScale() {
|
||||
return ponyModel.getSize().getShadowSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getScaleFactor() {
|
||||
return ponyModel.getSize().getScaleFactor();
|
||||
public Pony getEntityPony(AbstractClientPlayer player) {
|
||||
return MineLittlePony.getInstance().getManager().getPony(player);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.minelittlepony.render.player;
|
||||
|
||||
import com.minelittlepony.model.ModelWrapper;
|
||||
import com.minelittlepony.pony.data.Pony;
|
||||
|
||||
import net.minecraft.client.entity.AbstractClientPlayer;
|
||||
import net.minecraft.client.renderer.entity.RenderManager;
|
||||
|
@ -17,12 +18,15 @@ public class RenderSeaponyPlayer extends RenderPonyPlayer {
|
|||
normalPony = model;
|
||||
}
|
||||
|
||||
protected void updatePony(AbstractClientPlayer player) {
|
||||
super.updatePony(player);
|
||||
@Override
|
||||
public Pony getEntityPony(AbstractClientPlayer player) {
|
||||
Pony pony = super.getEntityPony(player);
|
||||
|
||||
boolean wet = pony.isFullySubmerged(player);
|
||||
|
||||
setPonyModel(wet ? seapony : normalPony);
|
||||
mainModel = renderPony.setPonyModel(wet ? seapony : normalPony);
|
||||
|
||||
return pony;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ public abstract class RenderPonyIllager<T extends AbstractIllager> extends Rende
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void preRenderCallback(T entity, float ticks) {
|
||||
public void preRenderCallback(T entity, float ticks) {
|
||||
super.preRenderCallback(entity, ticks);
|
||||
GlStateManager.scale(0.9375F, 0.9375F, 0.9375F);
|
||||
}
|
||||
|
|
|
@ -92,7 +92,7 @@ public class RenderPonySkeleton<Skeleton extends AbstractSkeleton> extends Rende
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void preRenderCallback(EntityWitherSkeleton skeleton, float ticks) {
|
||||
public void preRenderCallback(EntityWitherSkeleton skeleton, float ticks) {
|
||||
super.preRenderCallback(skeleton, ticks);
|
||||
GlStateManager.scale(1.2F, 1.2F, 1.2F);
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ public class RenderPonyVillager extends RenderPonyMob<EntityVillager> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void preRenderCallback(EntityVillager villager, float ticks) {
|
||||
public void preRenderCallback(EntityVillager villager, float ticks) {
|
||||
super.preRenderCallback(villager, ticks);
|
||||
GlStateManager.scale(0.9375F, 0.9375F, 0.9375F);
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ public class RenderPonyWitch extends RenderPonyMob<EntityWitch> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void preRenderCallback(EntityWitch entity, float ticks) {
|
||||
public void preRenderCallback(EntityWitch entity, float ticks) {
|
||||
super.preRenderCallback(entity, ticks);
|
||||
GlStateManager.scale(0.9375F, 0.9375F, 0.9375F);
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ public class RenderPonyZombie<Zombie extends EntityZombie> extends RenderPonyMob
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void preRenderCallback(EntityHusk entity, float ticks) {
|
||||
public void preRenderCallback(EntityHusk entity, float ticks) {
|
||||
super.preRenderCallback(entity, ticks);
|
||||
GlStateManager.scale(1.0625F, 1.0625F, 1.0625F);
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ public class RenderPonyZombie<Zombie extends EntityZombie> extends RenderPonyMob
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void preRenderCallback(EntityGiantZombie entity, float ticks) {
|
||||
public void preRenderCallback(EntityGiantZombie entity, float ticks) {
|
||||
super.preRenderCallback(entity, ticks);
|
||||
GlStateManager.scale(3, 3, 3);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue