import net.minecraft.client.util.math.MatrixStack
import net.minecraft.util.Arm
import net.minecraft.util.math.RotationAxis
import kotlin.math.PI
import kotlin.math.sin // Import sin for smoother curves if needed
// Assuming AnimationChoice and float parameter syntax are defined elsewhere
// Example: abstract class AnimationChoice(val name: String) {
// abstract fun transform(matrices: MatrixStack, arm: Arm, equipProgress: Float, swingProgress: Float)
// // Parameter definition might look like:
// // protected fun <T> parameter(name: String, defaultValue: T, range: ClosedRange<T>): T { ... }
// // val float = { name: String, default: Float, range: ClosedRange<Float> -> parameter(name, default, range) }
// }
// protected fun float(name: String, default: Float, range: ClosedRange<Float>) = ...
// --- Your Original Example (for reference) ---
object OneSevenAnimation : AnimationChoice("1.7") {
private val translateY by float("Y", 0.1f, 0.05f..0.3f)
private val swingProgressScale by float("SwingScale", 0.9f, 0.1f..1.0f)
override fun transform(matrices: MatrixStack, arm: Arm, equipProgress: Float, swingProgress: Float) {
matrices.translate(if (arm == Arm.RIGHT) -0.1f else 0.1f, translateY, 0.0f)
applySwingOffset(matrices, arm, swingProgress * swingProgressScale) // Base swing modified
matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(-102.25f))
matrices.multiply(
(if (arm == Arm.RIGHT) RotationAxis.POSITIVE_Y else RotationAxis.NEGATIVE_Y)
.rotationDegrees(13.365f)
)
matrices.multiply(
(if (arm == Arm.RIGHT) RotationAxis.POSITIVE_Z else RotationAxis.NEGATIVE_Z)
.rotationDegrees(78.05f)
)
}
}
// --- New Animation Ideas ---
/**
* A sharp, fast swing with a wrist-flick motion at the end.
* Feels quick and precise.
*/
object FlickShotAnimation : AnimationChoice("FlickShot") {
private val initialXOffset by float("InitialX", if (arm == Arm.RIGHT) 0.1f else -0.1f, -0.2f..0.2f)
private val flickAmount by float("Flick", 35f, 10f..60f)
private val flickPoint by float("FlickPoint", 0.6f, 0.4f..0.8f) // When the flick happens (0 to 1)
private val speedFactor by float("Speed", 1.2f, 0.5f..2.0f)
override fun transform(matrices: MatrixStack, arm: Arm, equipProgress: Float, swingProgress: Float) {
// Apply base swing offset, but faster
applySwingOffset(matrices, arm, swingProgress * speedFactor)
// Initial positioning adjustment
matrices.translate(initialXOffset, 0f, 0f)
// Add the sharp flick rotation near the end of the swing
if (swingProgress > flickPoint) {
val flickProgress = (swingProgress - flickPoint) / (1f - flickPoint) // Normalize progress after flickPoint
matrices.multiply(
(if (arm == Arm.RIGHT) RotationAxis.POSITIVE_Z else RotationAxis.NEGATIVE_Z)
.rotationDegrees(flickAmount * flickProgress)
)
}
// Base transformation (adjust these as needed to match your desired base pose)
matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(-90f)) // Standard arm position
matrices.multiply(
(if (arm == Arm.RIGHT) RotationAxis.NEGATIVE_Y else RotationAxis.POSITIVE_Y)
.rotationDegrees(15f)
)
matrices.multiply(
(if (arm == Arm.RIGHT) RotationAxis.POSITIVE_Z else RotationAxis.NEGATIVE_Z)
.rotationDegrees(10f)
)
}
}
/**
* A heavy, impactful swing. Slows down slightly at the point of impact, then recoils.
* Conveys weight and force.
*/
object HeavyImpactAnimation : AnimationChoice("HeavyImpact") {
private val windUpY by float("WindUpY", -0.15f, -0.3f..0.0f)
private val impactPausePoint by float("PausePoint", 0.6f, 0.5f..0.8f)
private val impactRecoil by float("Recoil", 15f, 5f..30f)
private val armSwingX by float("ArmSwingX", -70f, -90f..-40f)
override fun transform(matrices: MatrixStack, arm: Arm, equipProgress: Float, swingProgress: Float) {
// Small wind-up: move arm back slightly at the start
if (swingProgress < 0.2f) {
val windUpProgress = swingProgress / 0.2f
matrices.translate(0f, windUpY * (1f - windUpProgress), 0f)
matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(-30f * (1f - windUpProgress)))
}
// Apply base swing, potentially modified
// Apply swing progress, but maybe ease out near impact
val currentSwing = if (swingProgress < impactPausePoint) {
swingProgress
} else {
// Hold near impact point, then recoil
impactPausePoint + (swingProgress - impactPausePoint) * 0.5f // Slow down
}
applySwingOffset(matrices, arm, currentSwing)
// Add recoil after impact point
if (swingProgress > impactPausePoint && swingProgress < impactPausePoint + 0.3f) {
val recoilProgress = (swingProgress - impactPausePoint) / 0.3f
matrices.translate(0f, 0f, impactRecoil * recoilProgress * (if (arm == Arm.RIGHT) 1 else -1) ) // Move slightly forward/backward
}
// Base transformation (adjust these)
matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(armSwingX)) // Adjust swing arc
matrices.multiply(
(if (arm == Arm.RIGHT) RotationAxis.NEGATIVE_Y else RotationAxis.POSITIVE_Y)
.rotationDegrees(10f)
)
matrices.multiply(
(if (arm == Arm.RIGHT) RotationAxis.POSITIVE_Z else RotationAxis.NEGATIVE_Z)
.rotationDegrees(5f)
)
}
}
/**
* A spinning, slightly wild swing. Adds a twist to the standard motion.
*/
object TwirlAnimation : AnimationChoice("Twirl") {
private val initialShiftX by float("ShiftX", if (arm == Arm.RIGHT) -0.05f else 0.05f, -0.15f..0.15f)
private val initialShiftY by float("ShiftY", -0.05f, -0.2f..0.0f)
private val spinAmount by float("Spin", 90f, 30f..180f)
private val spinStart by float("SpinStart", 0.2f, 0.0f..0.5f)
private val spinEnd by float("SpinEnd", 0.7f, 0.5f..0.9f)
override fun transform(matrices: MatrixStack, arm: Arm, equipProgress: Float, swingProgress: Float) {
// Initial adjustment for the wind-up
matrices.translate(initialShiftX, initialShiftY, 0f)
// Apply the spin during the middle part of the swing
if (swingProgress > spinStart && swingProgress < spinEnd) {
val spinProgress = (swingProgress - spinStart) / (spinEnd - spinStart) // Normalize progress within spin phase
matrices.multiply(
(if (arm == Arm.RIGHT) RotationAxis.POSITIVE_Y else RotationAxis.NEGATIVE_Y)
.rotationDegrees(spinAmount * spinProgress)
)
}
// Apply the base swing offset, potentially modified by the spin context
applySwingOffset(matrices, arm, swingProgress)
// Base transformation (adjust these)
matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(-100f))
matrices.multiply(
(if (arm == Arm.RIGHT) RotationAxis.POSITIVE_Y else RotationAxis.NEGATIVE_Y)
.rotationDegrees(10f)
)
matrices.multiply(
(if (arm == Arm.RIGHT) RotationAxis.POSITIVE_Z else RotationAxis.NEGATIVE_Z)
.rotationDegrees(5f)
)
}
}
/**
* A simple, grounded animation focusing on a strong downward/forward motion.
* Feels more deliberate, less flashy.
*/
object GroundedSmashAnimation : AnimationChoice("GroundedSmash") {
private val forwardPush by float("ForwardPush", 0.1f, 0.0f..0.2f)
private val downwardForce by float("DownwardForce", 20f, 0f..45f)
private val anticX by float("AnticX", if (arm == Arm.RIGHT) 10f else -10f, -30f..30f)
private val anticY by float("AnticY", -0.1f, -0.2f..0.0f)
override fun transform(matrices: MatrixStack, arm: Arm, equipProgress: Float, swingProgress: Float) {
// Slight backward/upward "anticipation"
if (swingProgress < 0.15f) {
val anticProgress = swingProgress / 0.15f
matrices.translate(0f, anticY * (1f - anticProgress), 0f)
matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(anticX * (1f - anticProgress)))
}
// Apply swing, emphasizing forward/downward motion
val swingFactor = swingProgress * (1f + forwardPush) // Pushes forward slightly
applySwingOffset(matrices, arm, swingFactor) // Apply base swing offset
// Add downward force rotation, strongest near middle/impact
val downwardRotation = downwardForce * sin(swingProgress * PI) // Use sine wave for smooth increase/decrease
matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(downwardRotation))
// Base positioning adjustments (often minimal for this style)
matrices.translate(if (arm == Arm.RIGHT) 0.05f else -0.05f, 0.05f, 0.0f)
matrices.multiply(
(if (arm == Arm.RIGHT) RotationAxis.NEGATIVE_Y else RotationAxis.POSITIVE_Y)
.rotationDegrees(5f)
)
}
}