-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
raincoat-fabric/src/main/kotlin/dev/uten2c/raincoat/shake/ShakeEffect.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package dev.uten2c.raincoat.shake | ||
|
||
import kotlinx.datetime.Clock | ||
import kotlinx.datetime.Instant | ||
import net.minecraft.util.math.MathHelper | ||
import kotlin.time.Duration | ||
|
||
data class ShakeEffect(val startTime: Instant, val duration: Duration, val strength: Float) { | ||
val progress: Float | ||
get() = MathHelper.clamp(((Clock.System.now() - startTime) / duration).toFloat(), 0f, 1f) | ||
|
||
@JvmName("shouldPlay") | ||
fun shouldPlay(): Boolean { | ||
return strength > 0 && Clock.System.now() - startTime < duration | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
raincoat-fabric/src/main/kotlin/dev/uten2c/raincoat/shake/ShakeEffectUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package dev.uten2c.raincoat.shake | ||
|
||
import net.minecraft.client.util.math.MatrixStack | ||
import net.minecraft.util.math.RotationAxis | ||
import kotlin.random.Random | ||
|
||
object ShakeEffectUtils { | ||
@JvmStatic | ||
fun shake(matrices: MatrixStack, strength: Float) { | ||
val r1 = randomFloat() * strength | ||
val r2 = randomFloat() * strength | ||
matrices.translate(r1.toDouble() / 4, r2.toDouble() / 8, 0.0) | ||
matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(r1)) | ||
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(r2 * 2)) | ||
} | ||
|
||
private fun randomFloat(): Float { | ||
return Random.nextFloat() - 0.5f | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters