diff --git a/src/main/java/com/minelittlepony/ducks/IPonyAnimationHolder.java b/src/main/java/com/minelittlepony/ducks/IPonyAnimationHolder.java deleted file mode 100644 index 2fd0c4f5..00000000 --- a/src/main/java/com/minelittlepony/ducks/IPonyAnimationHolder.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.minelittlepony.ducks; - -/** - * Holding class for entities that support special pony animations used for the renderers. - */ -public interface IPonyAnimationHolder { - - /** - * Updates and gets the amount this entity is strafing to each side. - */ - float getStrafeAmount(); - - void setStrafeAmount(float strafeAmount); -} diff --git a/src/main/java/com/minelittlepony/mixin/MixinEntityLivingBase.java b/src/main/java/com/minelittlepony/mixin/MixinEntityLivingBase.java deleted file mode 100644 index 078e4f91..00000000 --- a/src/main/java/com/minelittlepony/mixin/MixinEntityLivingBase.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.minelittlepony.mixin; - -import org.spongepowered.asm.mixin.Mixin; - -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 { - 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() { - return strafeRollAmount; - } - - @Override - public void setStrafeAmount(float strafeAmount) { - strafeRollAmount = strafeAmount; - } -} diff --git a/src/main/java/com/minelittlepony/render/player/RenderPonyPlayer.java b/src/main/java/com/minelittlepony/render/player/RenderPonyPlayer.java index 519d0cd7..5b0468c0 100644 --- a/src/main/java/com/minelittlepony/render/player/RenderPonyPlayer.java +++ b/src/main/java/com/minelittlepony/render/player/RenderPonyPlayer.java @@ -1,12 +1,13 @@ package com.minelittlepony.render.player; import com.minelittlepony.MineLittlePony; -import com.minelittlepony.ducks.IPonyAnimationHolder; import com.minelittlepony.model.ModelWrapper; +import com.minelittlepony.util.math.MathUtil; import net.minecraft.client.entity.AbstractClientPlayer; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraft.util.math.Vec3d; public class RenderPonyPlayer extends RenderPonyBase { @@ -28,7 +29,7 @@ public class RenderPonyPlayer extends RenderPonyBase { @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); + GlStateManager.translate(0, player.isSneaking() ? 0.2F : -1, 0); } @Override @@ -44,27 +45,23 @@ public class RenderPonyPlayer extends RenderPonyBase { } } - if (angle > Math.PI / 3) angle = Math.PI / 3; - if (angle < -Math.PI / 3) angle = -Math.PI / 3; + angle = MathUtil.clampLimit(angle, Math.PI / 3); ponyModel.motionPitch = (float) Math.toDegrees(angle); GlStateManager.rotate(ponyModel.motionPitch, 1, 0, 0); + // Strafe like an elytra + Vec3d lookDirection = player.getForward(); - float lastStrafe = ((IPonyAnimationHolder)player).getStrafeAmount(); + double horMotion = Math.sqrt(motionX * motionX + motionZ * motionZ); + double horLook = Math.sqrt(lookDirection.x * lookDirection.x + lookDirection.z * lookDirection.z); - float strafing = player.moveStrafing; - if (strafing != 0) { - if (Math.abs(lastStrafe) < Math.abs(strafing)) { - lastStrafe += strafing/10; - } - } else { - lastStrafe *= 0.8; + if (horMotion > 0 && horLook > 0) { + double magnitude = (motionX * lookDirection.x + motionZ * lookDirection.z) / horMotion * horLook; + double direction = motionX * lookDirection.z - motionZ * lookDirection.x; + GlStateManager.rotate((float)Math.toDegrees(Math.signum(direction) * Math.acos(magnitude)), 0, 0, 1); } - - ((IPonyAnimationHolder)player).setStrafeAmount(lastStrafe); - GlStateManager.rotate((float)Math.toDegrees(lastStrafe), 0, 0, 1); } //TODO: MC1.13 transformSwimming() diff --git a/src/main/java/com/minelittlepony/util/math/MathUtil.java b/src/main/java/com/minelittlepony/util/math/MathUtil.java new file mode 100644 index 00000000..5dab16ec --- /dev/null +++ b/src/main/java/com/minelittlepony/util/math/MathUtil.java @@ -0,0 +1,10 @@ +package com.minelittlepony.util.math; + +import net.minecraft.util.math.MathHelper; + +public class MathUtil { + + public static double clampLimit(double num, double limit) { + return MathHelper.clamp(num, -limit, limit); + } +} diff --git a/src/main/resources/minelp.mixin.json b/src/main/resources/minelp.mixin.json index 972824cf..03138d99 100644 --- a/src/main/resources/minelp.mixin.json +++ b/src/main/resources/minelp.mixin.json @@ -8,7 +8,6 @@ "MixinThreadDownloadImageData", "MixinNetworkPlayerInfo", "MixinRenderItem", - "MixinRenderManager", - "MixinEntityLivingBase" + "MixinRenderManager" ] }