From 7f12104ec54c75387dd347ebb3ac441f51d9e5dd Mon Sep 17 00:00:00 2001 From: Sollace Date: Fri, 27 Jul 2018 00:10:18 +0200 Subject: [PATCH] Clean up some dank around the IRenderPony(s) --- .../com/minelittlepony/ducks/IRenderPony.java | 15 +-- .../com/minelittlepony/render/RenderPony.java | 88 ++++++++++++++ .../minelittlepony/render/RenderPonyMob.java | 51 ++------- .../render/layer/AbstractPonyLayer.java | 4 +- .../render/player/RenderPonyPlayer.java | 108 +++++------------- .../render/player/RenderSeaponyPlayer.java | 10 +- .../render/ponies/RenderPonyIllager.java | 2 +- .../render/ponies/RenderPonySkeleton.java | 2 +- .../render/ponies/RenderPonyVillager.java | 2 +- .../render/ponies/RenderPonyWitch.java | 2 +- .../render/ponies/RenderPonyZombie.java | 4 +- 11 files changed, 145 insertions(+), 143 deletions(-) create mode 100644 src/main/java/com/minelittlepony/render/RenderPony.java diff --git a/src/main/java/com/minelittlepony/ducks/IRenderPony.java b/src/main/java/com/minelittlepony/ducks/IRenderPony.java index 37e23ffd..225ec546 100644 --- a/src/main/java/com/minelittlepony/ducks/IRenderPony.java +++ b/src/main/java/com/minelittlepony/ducks/IRenderPony.java @@ -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 { /** * 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); } diff --git a/src/main/java/com/minelittlepony/render/RenderPony.java b/src/main/java/com/minelittlepony/render/RenderPony.java new file mode 100644 index 00000000..014b61f6 --- /dev/null +++ b/src/main/java/com/minelittlepony/render/RenderPony.java @@ -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 { + + public ModelWrapper playerModel; + + private AbstractPonyModel ponyModel; + + private Pony pony; + + private IRenderPony renderer; + + public RenderPony(IRenderPony 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)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(); + } +} diff --git a/src/main/java/com/minelittlepony/render/RenderPonyMob.java b/src/main/java/com/minelittlepony/render/RenderPonyMob.java index 3a25b741..e68b7059 100644 --- a/src/main/java/com/minelittlepony/render/RenderPonyMob.java +++ b/src/main/java/com/minelittlepony/render/RenderPonyMob.java @@ -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 extends RenderLiving implements IRenderPony { +public abstract class RenderPonyMob extends RenderLiving implements IRenderPony { - protected ModelWrapper playerModel; - - protected AbstractPonyModel ponyModel; - - private Pony pony; + protected final RenderPony renderPony = new RenderPony(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 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 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 extends RenderLiving } - public void preRenderCallback(T entity, float ticks) { - super.preRenderCallback(entity, ticks); - } - public final ResourceLocation getTextureFor(T entity) { return super.getEntityTexture(entity); } diff --git a/src/main/java/com/minelittlepony/render/layer/AbstractPonyLayer.java b/src/main/java/com/minelittlepony/render/layer/AbstractPonyLayer.java index 8e71326c..0fecf8d6 100644 --- a/src/main/java/com/minelittlepony/render/layer/AbstractPonyLayer.java +++ b/src/main/java/com/minelittlepony/render/layer/AbstractPonyLayer.java @@ -43,8 +43,8 @@ public abstract class AbstractPonyLayer implements L } @SuppressWarnings("unchecked") - protected IRenderPony getPonyRenderer() { - return (IRenderPony)renderer; + protected IRenderPony getPonyRenderer() { + return (IRenderPony)renderer; } public AbstractPonyModel getPlayerModel() { diff --git a/src/main/java/com/minelittlepony/render/player/RenderPonyPlayer.java b/src/main/java/com/minelittlepony/render/player/RenderPonyPlayer.java index e6e0c3c7..603f1353 100644 --- a/src/main/java/com/minelittlepony/render/player/RenderPonyPlayer.java +++ b/src/main/java/com/minelittlepony/render/player/RenderPonyPlayer.java @@ -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 { 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 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)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); } } diff --git a/src/main/java/com/minelittlepony/render/player/RenderSeaponyPlayer.java b/src/main/java/com/minelittlepony/render/player/RenderSeaponyPlayer.java index 58856c16..48181183 100644 --- a/src/main/java/com/minelittlepony/render/player/RenderSeaponyPlayer.java +++ b/src/main/java/com/minelittlepony/render/player/RenderSeaponyPlayer.java @@ -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; } } diff --git a/src/main/java/com/minelittlepony/render/ponies/RenderPonyIllager.java b/src/main/java/com/minelittlepony/render/ponies/RenderPonyIllager.java index 5175fefd..38becc51 100644 --- a/src/main/java/com/minelittlepony/render/ponies/RenderPonyIllager.java +++ b/src/main/java/com/minelittlepony/render/ponies/RenderPonyIllager.java @@ -29,7 +29,7 @@ public abstract class RenderPonyIllager 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); } diff --git a/src/main/java/com/minelittlepony/render/ponies/RenderPonySkeleton.java b/src/main/java/com/minelittlepony/render/ponies/RenderPonySkeleton.java index b3695b86..82fa7ca9 100644 --- a/src/main/java/com/minelittlepony/render/ponies/RenderPonySkeleton.java +++ b/src/main/java/com/minelittlepony/render/ponies/RenderPonySkeleton.java @@ -92,7 +92,7 @@ public class RenderPonySkeleton 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); } diff --git a/src/main/java/com/minelittlepony/render/ponies/RenderPonyVillager.java b/src/main/java/com/minelittlepony/render/ponies/RenderPonyVillager.java index cdd6b242..04ac32bd 100644 --- a/src/main/java/com/minelittlepony/render/ponies/RenderPonyVillager.java +++ b/src/main/java/com/minelittlepony/render/ponies/RenderPonyVillager.java @@ -24,7 +24,7 @@ public class RenderPonyVillager extends RenderPonyMob { } @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); } diff --git a/src/main/java/com/minelittlepony/render/ponies/RenderPonyWitch.java b/src/main/java/com/minelittlepony/render/ponies/RenderPonyWitch.java index ccb72cac..c2b671bd 100644 --- a/src/main/java/com/minelittlepony/render/ponies/RenderPonyWitch.java +++ b/src/main/java/com/minelittlepony/render/ponies/RenderPonyWitch.java @@ -38,7 +38,7 @@ public class RenderPonyWitch extends RenderPonyMob { } @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); } diff --git a/src/main/java/com/minelittlepony/render/ponies/RenderPonyZombie.java b/src/main/java/com/minelittlepony/render/ponies/RenderPonyZombie.java index a7078fa1..541d8092 100644 --- a/src/main/java/com/minelittlepony/render/ponies/RenderPonyZombie.java +++ b/src/main/java/com/minelittlepony/render/ponies/RenderPonyZombie.java @@ -47,7 +47,7 @@ public class RenderPonyZombie 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 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); }