Clean up some dank around the IRenderPony(s)

This commit is contained in:
Sollace 2018-07-27 00:10:18 +02:00
parent 302a8a22ad
commit 7f12104ec5
11 changed files with 145 additions and 143 deletions

View file

@ -1,24 +1,19 @@
package com.minelittlepony.ducks; package com.minelittlepony.ducks;
import com.minelittlepony.model.ModelWrapper; import com.minelittlepony.model.ModelWrapper;
import com.minelittlepony.pony.data.Pony;
import net.minecraft.entity.EntityLivingBase;
/** /**
* I Render Pony now, oky? * I Render Pony now, oky?
*/ */
public interface IRenderPony { public interface IRenderPony<T extends EntityLivingBase> {
/** /**
* Gets the wrapped pony model for this renderer. * Gets the wrapped pony model for this renderer.
*/ */
ModelWrapper getModelWrapper(); ModelWrapper getModelWrapper();
/** Pony getEntityPony(T entity);
* Gets the current shadow size for rendering.
*/
float getShadowScale();
/**
* Gets the scaling factor used when rendering this pony.
*/
float getScaleFactor();
} }

View 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();
}
}

View file

@ -2,7 +2,6 @@ package com.minelittlepony.render;
import com.minelittlepony.MineLittlePony; import com.minelittlepony.MineLittlePony;
import com.minelittlepony.ducks.IRenderPony; import com.minelittlepony.ducks.IRenderPony;
import com.minelittlepony.model.AbstractPonyModel;
import com.minelittlepony.model.ModelWrapper; import com.minelittlepony.model.ModelWrapper;
import com.minelittlepony.pony.data.Pony; import com.minelittlepony.pony.data.Pony;
import com.minelittlepony.render.layer.LayerHeldPonyItem; import com.minelittlepony.render.layer.LayerHeldPonyItem;
@ -23,18 +22,14 @@ import javax.annotation.Nonnull;
// TODO: A lot of this duplicates RenderPonyPlayer // TODO: A lot of this duplicates RenderPonyPlayer
// and is the whole reason we had this scaling bug in the first place. // 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 final RenderPony<T> renderPony = new RenderPony<T>(this);
protected AbstractPonyModel ponyModel;
private Pony pony;
public RenderPonyMob(RenderManager manager, ModelWrapper model) { public RenderPonyMob(RenderManager manager, ModelWrapper model) {
super(manager, model.getBody(), 0.5F); super(manager, model.getBody(), 0.5F);
setPonyModel(model); mainModel = renderPony.setPonyModel(model);
addLayers(); addLayers();
} }
@ -60,14 +55,9 @@ public abstract class RenderPonyMob<T extends EntityLiving> extends RenderLiving
} }
@Override @Override
protected void preRenderCallback(T entity, float ticks) { public void preRenderCallback(T entity, float ticks) {
updateModel(entity); renderPony.preRenderCallback(entity, ticks);
shadowSize = renderPony.getShadowScale();
ponyModel.updateLivingState(entity, pony);
shadowSize = getShadowScale();
float s = getScaleFactor();
GlStateManager.scale(s, s, s);
if (!entity.isRiding()) { if (!entity.isRiding()) {
GlStateManager.translate(0, 0, -entity.width / 2); // move us to the center of the shadow 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 @Override
public ModelWrapper getModelWrapper() { public ModelWrapper getModelWrapper() {
return playerModel; return renderPony.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());
} }
@Override @Override
public float getShadowScale() { public Pony getEntityPony(T entity) {
return ponyModel.getSize().getShadowSize(); return MineLittlePony.getInstance().getManager().getPony(getEntityTexture(entity), false);
}
@Override
public float getScaleFactor() {
return ponyModel.getSize().getScaleFactor();
} }
@Override @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) { public final ResourceLocation getTextureFor(T entity) {
return super.getEntityTexture(entity); return super.getEntityTexture(entity);
} }

View file

@ -43,8 +43,8 @@ public abstract class AbstractPonyLayer<T extends EntityLivingBase> implements L
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected IRenderPony getPonyRenderer() { protected IRenderPony<T> getPonyRenderer() {
return (IRenderPony)renderer; return (IRenderPony<T>)renderer;
} }
public AbstractPonyModel getPlayerModel() { public AbstractPonyModel getPlayerModel() {

View file

@ -6,20 +6,18 @@ import java.util.Optional;
import com.minelittlepony.MineLittlePony; import com.minelittlepony.MineLittlePony;
import com.minelittlepony.PonyConfig; import com.minelittlepony.PonyConfig;
import com.minelittlepony.ducks.IRenderPony; import com.minelittlepony.ducks.IRenderPony;
import com.minelittlepony.model.AbstractPonyModel;
import com.minelittlepony.model.ModelWrapper; import com.minelittlepony.model.ModelWrapper;
import com.minelittlepony.model.components.ModelDeadMau5Ears; import com.minelittlepony.model.components.ModelDeadMau5Ears;
import com.minelittlepony.pony.data.Pony; import com.minelittlepony.pony.data.Pony;
import com.minelittlepony.pony.data.PonyLevel; import com.minelittlepony.pony.data.PonyLevel;
import com.minelittlepony.render.PonySkull; import com.minelittlepony.render.PonySkull;
import com.minelittlepony.render.RenderPony;
import com.minelittlepony.render.PonySkullRenderer.ISkull; import com.minelittlepony.render.PonySkullRenderer.ISkull;
import com.minelittlepony.render.layer.LayerEntityOnPonyShoulder; import com.minelittlepony.render.layer.LayerEntityOnPonyShoulder;
import com.minelittlepony.render.layer.LayerHeldPonyItemMagical; import com.minelittlepony.render.layer.LayerHeldPonyItemMagical;
import com.minelittlepony.render.layer.LayerPonyArmor;
import com.minelittlepony.render.layer.LayerPonyCape; import com.minelittlepony.render.layer.LayerPonyCape;
import com.minelittlepony.render.layer.LayerPonyCustomHead; import com.minelittlepony.render.layer.LayerPonyCustomHead;
import com.minelittlepony.render.layer.LayerPonyElytra; import com.minelittlepony.render.layer.LayerPonyElytra;
import com.minelittlepony.transform.PonyPosture;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import com.mojang.authlib.minecraft.MinecraftProfileTexture; import com.mojang.authlib.minecraft.MinecraftProfileTexture;
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type; 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.client.resources.DefaultPlayerSkin;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.EnumHandSide;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.client.renderer.entity.RenderPlayer; import net.minecraft.client.renderer.entity.RenderPlayer;
import net.minecraft.client.renderer.entity.layers.LayerArrow; import net.minecraft.client.renderer.entity.layers.LayerArrow;
import net.minecraft.entity.Entity; 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() { public static final ISkull SKULL = new PonySkull() {
@ -84,16 +82,12 @@ public class RenderPonyPlayer extends RenderPlayer implements IRenderPony {
} }
}.register(ISkull.PLAYER); }.register(ISkull.PLAYER);
private ModelWrapper playerModel; protected final RenderPony<AbstractClientPlayer> renderPony = new RenderPony<>(this);
protected AbstractPonyModel ponyModel;
protected Pony pony;
public RenderPonyPlayer(RenderManager manager, boolean useSmallArms, ModelWrapper model) { public RenderPonyPlayer(RenderManager manager, boolean useSmallArms, ModelWrapper model) {
super(manager, useSmallArms); super(manager, useSmallArms);
setPonyModel(model); mainModel = renderPony.setPonyModel(model);
addLayers(); addLayers();
} }
@ -101,7 +95,6 @@ public class RenderPonyPlayer extends RenderPlayer implements IRenderPony {
protected void addLayers() { protected void addLayers() {
layerRenderers.clear(); layerRenderers.clear();
addLayer(new LayerPonyArmor<>(this));
addLayer(new LayerArrow(this)); addLayer(new LayerArrow(this));
addLayer(new LayerPonyCustomHead<>(this)); addLayer(new LayerPonyCustomHead<>(this));
addLayer(new LayerPonyElytra<>(this)); addLayer(new LayerPonyElytra<>(this));
@ -131,13 +124,8 @@ public class RenderPonyPlayer extends RenderPlayer implements IRenderPony {
@Override @Override
protected void preRenderCallback(AbstractClientPlayer player, float ticks) { protected void preRenderCallback(AbstractClientPlayer player, float ticks) {
updateModel(player); renderPony.preRenderCallback(player, ticks);
shadowSize = renderPony.getShadowScale();
ponyModel.updateLivingState(player, pony);
shadowSize = getShadowScale();
float s = getScaleFactor();
GlStateManager.scale(s, s, s);
if (player.isRiding()) { if (player.isRiding()) {
GlStateManager.translate(0, player.getYOffset(), 0); GlStateManager.translate(0, player.getYOffset(), 0);
@ -152,89 +140,49 @@ public class RenderPonyPlayer extends RenderPlayer implements IRenderPony {
} }
@Override @Override
public void renderRightArm(AbstractClientPlayer player) { public final void renderRightArm(AbstractClientPlayer player) {
updateModel(player); renderArm(player, EnumHandSide.RIGHT);
bindEntityTexture(player);
GlStateManager.pushMatrix();
GlStateManager.translate(0, -0.37, 0);
super.renderRightArm(player);
GlStateManager.popMatrix();
} }
@Override @Override
public void renderLeftArm(AbstractClientPlayer player) { public final void renderLeftArm(AbstractClientPlayer player) {
updateModel(player); renderArm(player, EnumHandSide.LEFT);
}
protected void renderArm(AbstractClientPlayer player, EnumHandSide side) {
renderPony.updateModel(player);
bindEntityTexture(player); bindEntityTexture(player);
GlStateManager.pushMatrix(); GlStateManager.pushMatrix();
GlStateManager.translate(0.06, -0.37, 0); GlStateManager.translate(side == EnumHandSide.LEFT ? 0.06 : 0, -0.37, 0);
super.renderLeftArm(player);
if (side == EnumHandSide.LEFT) {
super.renderLeftArm(player);
} else {
super.renderRightArm(player);
}
GlStateManager.popMatrix(); GlStateManager.popMatrix();
} }
@SuppressWarnings("unchecked")
@Override @Override
protected void applyRotations(AbstractClientPlayer player, float yaw, float pitch, float ticks) { protected void applyRotations(AbstractClientPlayer player, float yaw, float pitch, float ticks) {
super.applyRotations(player, yaw, pitch, ticks); super.applyRotations(player, yaw, pitch, ticks);
PonyPosture<?> posture = getPosture(player); renderPony.applyPostureTransform(player, yaw, pitch, ticks);
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;
} }
@Override @Override
public ResourceLocation getEntityTexture(AbstractClientPlayer player) { public ResourceLocation getEntityTexture(AbstractClientPlayer player) {
updateModel(player); return renderPony.getPony(player).getTexture();
return pony.getTexture();
} }
@Override @Override
public ModelWrapper getModelWrapper() { public ModelWrapper getModelWrapper() {
return playerModel; return renderPony.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());
} }
@Override @Override
public float getShadowScale() { public Pony getEntityPony(AbstractClientPlayer player) {
return ponyModel.getSize().getShadowSize(); return MineLittlePony.getInstance().getManager().getPony(player);
}
@Override
public float getScaleFactor() {
return ponyModel.getSize().getScaleFactor();
} }
} }

View file

@ -1,6 +1,7 @@
package com.minelittlepony.render.player; package com.minelittlepony.render.player;
import com.minelittlepony.model.ModelWrapper; import com.minelittlepony.model.ModelWrapper;
import com.minelittlepony.pony.data.Pony;
import net.minecraft.client.entity.AbstractClientPlayer; import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.client.renderer.entity.RenderManager;
@ -17,12 +18,15 @@ public class RenderSeaponyPlayer extends RenderPonyPlayer {
normalPony = model; normalPony = model;
} }
protected void updatePony(AbstractClientPlayer player) { @Override
super.updatePony(player); public Pony getEntityPony(AbstractClientPlayer player) {
Pony pony = super.getEntityPony(player);
boolean wet = pony.isFullySubmerged(player); boolean wet = pony.isFullySubmerged(player);
setPonyModel(wet ? seapony : normalPony); mainModel = renderPony.setPonyModel(wet ? seapony : normalPony);
return pony;
} }
} }

View file

@ -29,7 +29,7 @@ public abstract class RenderPonyIllager<T extends AbstractIllager> extends Rende
} }
@Override @Override
protected void preRenderCallback(T entity, float ticks) { public void preRenderCallback(T entity, float ticks) {
super.preRenderCallback(entity, ticks); super.preRenderCallback(entity, ticks);
GlStateManager.scale(0.9375F, 0.9375F, 0.9375F); GlStateManager.scale(0.9375F, 0.9375F, 0.9375F);
} }

View file

@ -92,7 +92,7 @@ public class RenderPonySkeleton<Skeleton extends AbstractSkeleton> extends Rende
} }
@Override @Override
protected void preRenderCallback(EntityWitherSkeleton skeleton, float ticks) { public void preRenderCallback(EntityWitherSkeleton skeleton, float ticks) {
super.preRenderCallback(skeleton, ticks); super.preRenderCallback(skeleton, ticks);
GlStateManager.scale(1.2F, 1.2F, 1.2F); GlStateManager.scale(1.2F, 1.2F, 1.2F);
} }

View file

@ -24,7 +24,7 @@ public class RenderPonyVillager extends RenderPonyMob<EntityVillager> {
} }
@Override @Override
protected void preRenderCallback(EntityVillager villager, float ticks) { public void preRenderCallback(EntityVillager villager, float ticks) {
super.preRenderCallback(villager, ticks); super.preRenderCallback(villager, ticks);
GlStateManager.scale(0.9375F, 0.9375F, 0.9375F); GlStateManager.scale(0.9375F, 0.9375F, 0.9375F);
} }

View file

@ -38,7 +38,7 @@ public class RenderPonyWitch extends RenderPonyMob<EntityWitch> {
} }
@Override @Override
protected void preRenderCallback(EntityWitch entity, float ticks) { public void preRenderCallback(EntityWitch entity, float ticks) {
super.preRenderCallback(entity, ticks); super.preRenderCallback(entity, ticks);
GlStateManager.scale(0.9375F, 0.9375F, 0.9375F); GlStateManager.scale(0.9375F, 0.9375F, 0.9375F);
} }

View file

@ -47,7 +47,7 @@ public class RenderPonyZombie<Zombie extends EntityZombie> extends RenderPonyMob
} }
@Override @Override
protected void preRenderCallback(EntityHusk entity, float ticks) { public void preRenderCallback(EntityHusk entity, float ticks) {
super.preRenderCallback(entity, ticks); super.preRenderCallback(entity, ticks);
GlStateManager.scale(1.0625F, 1.0625F, 1.0625F); GlStateManager.scale(1.0625F, 1.0625F, 1.0625F);
} }
@ -66,7 +66,7 @@ public class RenderPonyZombie<Zombie extends EntityZombie> extends RenderPonyMob
} }
@Override @Override
protected void preRenderCallback(EntityGiantZombie entity, float ticks) { public void preRenderCallback(EntityGiantZombie entity, float ticks) {
super.preRenderCallback(entity, ticks); super.preRenderCallback(entity, ticks);
GlStateManager.scale(3, 3, 3); GlStateManager.scale(3, 3, 3);
} }