mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2024-11-26 06:18:00 +01:00
Rewrite strafing to not use a mixin
This commit is contained in:
parent
e8500ea31f
commit
b5104d67fd
5 changed files with 23 additions and 62 deletions
|
@ -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);
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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()
|
||||
|
|
10
src/main/java/com/minelittlepony/util/math/MathUtil.java
Normal file
10
src/main/java/com/minelittlepony/util/math/MathUtil.java
Normal 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);
|
||||
}
|
||||
}
|
|
@ -8,7 +8,6 @@
|
|||
"MixinThreadDownloadImageData",
|
||||
"MixinNetworkPlayerInfo",
|
||||
"MixinRenderItem",
|
||||
"MixinRenderManager",
|
||||
"MixinEntityLivingBase"
|
||||
"MixinRenderManager"
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue