Rewrite strafing to not use a mixin

This commit is contained in:
Sollace 2018-05-02 14:41:43 +02:00
parent e8500ea31f
commit b5104d67fd
5 changed files with 23 additions and 62 deletions

View file

@ -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);
}

View file

@ -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;
}
}

View file

@ -1,12 +1,13 @@
package com.minelittlepony.render.player; package com.minelittlepony.render.player;
import com.minelittlepony.MineLittlePony; import com.minelittlepony.MineLittlePony;
import com.minelittlepony.ducks.IPonyAnimationHolder;
import com.minelittlepony.model.ModelWrapper; import com.minelittlepony.model.ModelWrapper;
import com.minelittlepony.util.math.MathUtil;
import net.minecraft.client.entity.AbstractClientPlayer; import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.util.math.Vec3d;
public class RenderPonyPlayer extends RenderPonyBase { public class RenderPonyPlayer extends RenderPonyBase {
@ -28,7 +29,7 @@ public class RenderPonyPlayer extends RenderPonyBase {
@Override @Override
protected void transformElytraFlight(AbstractClientPlayer player, double motionX, double motionY, double motionZ, float ticks) { protected void transformElytraFlight(AbstractClientPlayer player, double motionX, double motionY, double motionZ, float ticks) {
GlStateManager.rotate(90, 1, 0, 0); GlStateManager.rotate(90, 1, 0, 0);
GlStateManager.translate(0, -1, 0); GlStateManager.translate(0, player.isSneaking() ? 0.2F : -1, 0);
} }
@Override @Override
@ -44,27 +45,23 @@ public class RenderPonyPlayer extends RenderPonyBase {
} }
} }
if (angle > Math.PI / 3) angle = Math.PI / 3; angle = MathUtil.clampLimit(angle, Math.PI / 3);
if (angle < -Math.PI / 3) angle = -Math.PI / 3;
ponyModel.motionPitch = (float) Math.toDegrees(angle); ponyModel.motionPitch = (float) Math.toDegrees(angle);
GlStateManager.rotate(ponyModel.motionPitch, 1, 0, 0); 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 (horMotion > 0 && horLook > 0) {
if (strafing != 0) { double magnitude = (motionX * lookDirection.x + motionZ * lookDirection.z) / horMotion * horLook;
if (Math.abs(lastStrafe) < Math.abs(strafing)) { double direction = motionX * lookDirection.z - motionZ * lookDirection.x;
lastStrafe += strafing/10; GlStateManager.rotate((float)Math.toDegrees(Math.signum(direction) * Math.acos(magnitude)), 0, 0, 1);
}
} else {
lastStrafe *= 0.8;
} }
((IPonyAnimationHolder)player).setStrafeAmount(lastStrafe);
GlStateManager.rotate((float)Math.toDegrees(lastStrafe), 0, 0, 1);
} }
//TODO: MC1.13 transformSwimming() //TODO: MC1.13 transformSwimming()

View file

@ -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);
}
}

View file

@ -8,7 +8,6 @@
"MixinThreadDownloadImageData", "MixinThreadDownloadImageData",
"MixinNetworkPlayerInfo", "MixinNetworkPlayerInfo",
"MixinRenderItem", "MixinRenderItem",
"MixinRenderManager", "MixinRenderManager"
"MixinEntityLivingBase"
] ]
} }