diff --git a/src/main/java/com/minelittlepony/Pony.java b/src/main/java/com/minelittlepony/Pony.java index 1c022a4b..80d06751 100644 --- a/src/main/java/com/minelittlepony/Pony.java +++ b/src/main/java/com/minelittlepony/Pony.java @@ -107,8 +107,7 @@ public class Pony { } public PonyRace getRace(boolean ignorePony) { - return PonyRace.ALICORN; - //return metadata.getRace().getEffectiveRace(MineLittlePony.getConfig().getPonyLevel(ignorePony)); + return metadata.getRace().getEffectiveRace(MineLittlePony.getConfig().getPonyLevel(ignorePony)); } public ResourceLocation getTexture() { diff --git a/src/main/java/com/minelittlepony/ducks/IPonyAnimationHolder.java b/src/main/java/com/minelittlepony/ducks/IPonyAnimationHolder.java new file mode 100644 index 00000000..4c9f7520 --- /dev/null +++ b/src/main/java/com/minelittlepony/ducks/IPonyAnimationHolder.java @@ -0,0 +1,5 @@ +package com.minelittlepony.ducks; + +public interface IPonyAnimationHolder { + float getStrafeAmount(float ticks); +} diff --git a/src/main/java/com/minelittlepony/mixin/MixinEntityLivingBase.java b/src/main/java/com/minelittlepony/mixin/MixinEntityLivingBase.java new file mode 100644 index 00000000..bd8a9a29 --- /dev/null +++ b/src/main/java/com/minelittlepony/mixin/MixinEntityLivingBase.java @@ -0,0 +1,38 @@ +package com.minelittlepony.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +import com.minelittlepony.ducks.IPonyAnimationHolder; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.world.World; + +@Mixin(EntityLivingBase.class) +public abstract class MixinEntityLivingBase extends Entity implements IPonyAnimationHolder { + @Shadow + public float moveStrafing; + + private MixinEntityLivingBase(World worldIn) { + super(worldIn); + } + + // No other place to save this stuff? :'c + // Add any animations you want + // This could also go into Pony, but I'm unsure if that's a good place for it (@Immutable). + private float strafeRollAmount = 0; + + @Override + public float getStrafeAmount(float ticks) { + float strafing = this.moveStrafing; + if (strafing != 0) { + if (Math.abs(strafeRollAmount) < Math.abs(strafing)) { + strafeRollAmount += strafing/10; + } + } else { + strafeRollAmount *= 0.8; + } + return (float)Math.toDegrees(strafeRollAmount * ticks); + } +} diff --git a/src/main/java/com/minelittlepony/renderer/player/RenderPonyBase.java b/src/main/java/com/minelittlepony/renderer/player/RenderPonyBase.java index 75ee2eec..dece3cc2 100644 --- a/src/main/java/com/minelittlepony/renderer/player/RenderPonyBase.java +++ b/src/main/java/com/minelittlepony/renderer/player/RenderPonyBase.java @@ -26,7 +26,8 @@ public abstract class RenderPonyBase extends RenderPlayer implements IRenderPony protected final boolean smallArms; private PlayerModel playerModel; - private AbstractPonyModel ponyModel; + + protected AbstractPonyModel ponyModel; private Pony pony; @@ -72,60 +73,51 @@ public abstract class RenderPonyBase extends RenderPlayer implements IRenderPony super.doRender(player, x, y, z, entityYaw, partialTicks); } + + // TODO: Why are there two sets of arms? @Override public void renderRightArm(AbstractClientPlayer player) { updateModel(player); bindEntityTexture(player); + GlStateManager.pushMatrix(); + GlStateManager.translate(0, -0.37, 0); super.renderRightArm(player); + GlStateManager.popMatrix(); } @Override public void renderLeftArm(AbstractClientPlayer player) { updateModel(player); bindEntityTexture(player); + GlStateManager.pushMatrix(); + GlStateManager.translate(0.06, -0.37, -0); super.renderLeftArm(player); + GlStateManager.popMatrix(); } @Override protected void applyRotations(AbstractClientPlayer player, float yaw, float pitch, float ticks) { super.applyRotations(player, yaw, pitch, ticks); + double motionX = player.posX - player.prevPosX; + double motionY = player.onGround ? 0 : player.posY - player.prevPosY; + double motionZ = player.posZ - player.prevPosZ; + if (player.isElytraFlying()) { - transformFlying(player, yaw, pitch, ticks); + transformElytraFlight(player, motionX, motionY, motionZ, ticks); return; } if (player.isEntityAlive() && player.isPlayerSleeping()) return; - // require arms to be stretched out (sorry mud ponies, no flight skills for you) - if (!((ModelPlayerPony) ponyModel).rainboom) { - ponyModel.motionPitch = 0; + if (((ModelPlayerPony) ponyModel).rainboom) { + transformPegasusFlight(player, motionX, motionY, motionZ, yaw, pitch, ticks); return; } - double motionX = player.posX - player.prevPosX; - double motionY = player.posY - player.prevPosY; - double motionZ = player.posZ - player.prevPosZ; - if (player.onGround) { - motionY = 0; - } - double dist = Math.sqrt(motionX * motionX + motionZ * motionZ); - double angle = Math.atan2(motionY, dist); - if (!player.capabilities.isFlying) { - if (angle > 0) { - angle = 0; - } else { - angle /= 2; - } - } - - if (angle > Math.PI / 3) angle = Math.PI / 3; - if (angle < -Math.PI / 3) angle = -Math.PI / 3; - - ponyModel.motionPitch = (float) Math.toDegrees(angle); - - GlStateManager.rotate((float) Math.toDegrees(angle), 1, 0, 0); + // require arms to be stretched out (sorry mud ponies, no flight skills for you) + ponyModel.motionPitch = 0; } public ResourceLocation getEntityTexture(AbstractClientPlayer entity) { @@ -156,5 +148,7 @@ public abstract class RenderPonyBase extends RenderPlayer implements IRenderPony protected abstract float getScaleFactor(); - protected abstract void transformFlying(AbstractClientPlayer player, float yaw, float pitch, float ticks); + protected abstract void transformElytraFlight(AbstractClientPlayer player, double motionX, double motionY, double motionZ, float ticks); + + protected abstract void transformPegasusFlight(AbstractClientPlayer player, double motionX, double motionY, double motionZ, float yaw, float pitch, float ticks); } diff --git a/src/main/java/com/minelittlepony/renderer/player/RenderPonyPlayer.java b/src/main/java/com/minelittlepony/renderer/player/RenderPonyPlayer.java index 107a04ea..422f4f2f 100644 --- a/src/main/java/com/minelittlepony/renderer/player/RenderPonyPlayer.java +++ b/src/main/java/com/minelittlepony/renderer/player/RenderPonyPlayer.java @@ -1,6 +1,7 @@ package com.minelittlepony.renderer.player; import com.minelittlepony.MineLittlePony; +import com.minelittlepony.ducks.IPonyAnimationHolder; import com.minelittlepony.model.PlayerModel; import net.minecraft.client.entity.AbstractClientPlayer; @@ -8,24 +9,46 @@ import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.entity.RenderManager; public class RenderPonyPlayer extends RenderPonyBase { - public RenderPonyPlayer(RenderManager renderManager, boolean useSmallArms, String id, PlayerModel model) { - super(renderManager, useSmallArms, id, model); - } + public RenderPonyPlayer(RenderManager renderManager, boolean useSmallArms, String id, PlayerModel model) { + super(renderManager, useSmallArms, id, model); + } - @Override - protected float getPonyShadowScale() { - if (!MineLittlePony.getConfig().showscale) return .5f; - return getPony().getMetadata().getSize().getShadowSize(); - } + @Override + protected float getPonyShadowScale() { + if (!MineLittlePony.getConfig().showscale) return .5f; + return getPony().getMetadata().getSize().getShadowSize(); + } - @Override - protected float getScaleFactor() { - return getPony().getMetadata().getSize().getScaleFactor(); - } + @Override + protected float getScaleFactor() { + return getPony().getMetadata().getSize().getScaleFactor(); + } - @Override - protected void transformFlying(AbstractClientPlayer player, float yaw, float pitch, float ticks) { - GlStateManager.rotate(90, 1, 0, 0); - GlStateManager.translate(0, -1, 0); - } + @Override + protected void transformElytraFlight(AbstractClientPlayer player, double motionX, double motionY, double motionZ, float ticks) { + GlStateManager.rotate(90, 1, 0, 0); + GlStateManager.translate(0, -1, 0); + } + + @Override + protected void transformPegasusFlight(AbstractClientPlayer player, double motionX, double motionY, double motionZ, float yaw, float pitch, float ticks) { + double dist = Math.sqrt(motionX * motionX + motionZ * motionZ); + double angle = Math.atan2(motionY, dist); + + if (!player.capabilities.isFlying) { + if (angle > 0) { + angle = 0; + } else { + angle /= 2; + } + } + + if (angle > Math.PI / 3) angle = Math.PI / 3; + if (angle < -Math.PI / 3) angle = -Math.PI / 3; + + ponyModel.motionPitch = (float) Math.toDegrees(angle); + + GlStateManager.rotate(ponyModel.motionPitch, 1, 0, 0); + GlStateManager.rotate(((IPonyAnimationHolder)player).getStrafeAmount(ticks), 0, 0, 1); + } } diff --git a/src/main/resources/minelp.mixin.json b/src/main/resources/minelp.mixin.json index 03138d99..972824cf 100644 --- a/src/main/resources/minelp.mixin.json +++ b/src/main/resources/minelp.mixin.json @@ -8,6 +8,7 @@ "MixinThreadDownloadImageData", "MixinNetworkPlayerInfo", "MixinRenderItem", - "MixinRenderManager" + "MixinRenderManager", + "MixinEntityLivingBase" ] }