From fcbd2545cbc2230f186b6e89a8ab4855ec6abc07 Mon Sep 17 00:00:00 2001 From: luisc Date: Mon, 23 Feb 2026 16:15:43 -0600 Subject: [PATCH] changed rotation of orbs and discs based on their heading --- .../client/renderer/RenderAbilityDisc.java | 12 ++++++++++ .../client/renderer/RenderAbilityOrb.java | 12 ++++++++++ src/main/java/noppes/npcs/util/MathUtil.java | 24 +++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 src/main/java/noppes/npcs/util/MathUtil.java diff --git a/src/main/java/kamkeel/npcs/client/renderer/RenderAbilityDisc.java b/src/main/java/kamkeel/npcs/client/renderer/RenderAbilityDisc.java index d013dd306..068d0b2fb 100644 --- a/src/main/java/kamkeel/npcs/client/renderer/RenderAbilityDisc.java +++ b/src/main/java/kamkeel/npcs/client/renderer/RenderAbilityDisc.java @@ -4,6 +4,8 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import kamkeel.npcs.entity.EntityAbilityDisc; import net.minecraft.entity.Entity; +import net.minecraft.util.Vec3; +import noppes.npcs.util.MathUtil; import org.lwjgl.opengl.GL11; /** @@ -51,6 +53,16 @@ public class RenderAbilityDisc extends RenderEnergyAbility { GL11.glRotatef(90.0f, 1.0f, 0.0f, 0.0f); } + double motionX = entity.motionX; + double motionY = entity.motionY; + double motionZ = entity.motionZ; + Vec3 motionVec = Vec3.createVectorHelper(motionX, motionY, motionZ); + + float motionYaw = MathUtil.getYaw(motionVec); + float motionPitch = MathUtil.getPitch(motionVec); + GL11.glRotatef(motionYaw, 0, 1, 0); + GL11.glRotatef(motionPitch, 1, 0, 0); + // Apply Y-axis rotation for spin GL11.glRotatef(disc.getInterpolatedRotationY(partialTicks), 0.0f, 1.0f, 0.0f); diff --git a/src/main/java/kamkeel/npcs/client/renderer/RenderAbilityOrb.java b/src/main/java/kamkeel/npcs/client/renderer/RenderAbilityOrb.java index a3adf71a0..1e0972659 100644 --- a/src/main/java/kamkeel/npcs/client/renderer/RenderAbilityOrb.java +++ b/src/main/java/kamkeel/npcs/client/renderer/RenderAbilityOrb.java @@ -4,6 +4,8 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import kamkeel.npcs.entity.EntityAbilityOrb; import net.minecraft.entity.Entity; +import net.minecraft.util.Vec3; +import noppes.npcs.util.MathUtil; import org.lwjgl.opengl.GL11; /** @@ -37,6 +39,16 @@ public class RenderAbilityOrb extends RenderEnergyAbility { renderAttachedLightning(orb, 0.6f * 0.5f, scale); } + double motionX = entity.motionX; + double motionY = entity.motionY; + double motionZ = entity.motionZ; + Vec3 motionVec = Vec3.createVectorHelper(motionX, motionY, motionZ); + + float motionYaw = MathUtil.getYaw(motionVec); + float motionPitch = MathUtil.getPitch(motionVec); + GL11.glRotatef(motionYaw, 0, 1, 0); + GL11.glRotatef(motionPitch, 1, 0, 0); + // Use entity's interpolated rotation for smooth spinning GL11.glRotatef(orb.getInterpolatedRotationX(partialTicks), 1.0f, 0.0f, 0.0f); GL11.glRotatef(orb.getInterpolatedRotationY(partialTicks), 0.0f, 1.0f, 0.0f); diff --git a/src/main/java/noppes/npcs/util/MathUtil.java b/src/main/java/noppes/npcs/util/MathUtil.java new file mode 100644 index 000000000..cfaec4e2a --- /dev/null +++ b/src/main/java/noppes/npcs/util/MathUtil.java @@ -0,0 +1,24 @@ +package noppes.npcs.util; + +import net.minecraft.util.Vec3; + +public class MathUtil { + + public static float getYaw(Vec3 vector) { + double x = vector.xCoord; + double z = vector.zCoord; + double yawRad = Math.atan2(z, x); + + return 90F - (float) Math.toDegrees(yawRad); + } + + public static float getPitch(Vec3 vector) { + double x = vector.xCoord; + double y = vector.yCoord; + double z = vector.zCoord; + double horizontalMag = Math.sqrt(x * x + z * z); + double pitchRad = Math.atan2(y, horizontalMag); + + return (float) -Math.toDegrees(pitchRad); + } +}