Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ internal class EmoteScene(asset: CosmeticAsset, meta: JsonObject?, private val l
}
}

fun query(name: String, value: Float) {
if (!failed) renderer.setQuery(name, value)
}

fun clock(wearer: Long, wanted: Double, shift: Double, real: Double): Double =
sceneClock.at(wearer, wanted, shift, real)

Expand Down
38 changes: 16 additions & 22 deletions src/main/kotlin/org/polyfrost/polyplus/client/lobby/LobbyGrab.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import net.minecraft.world.entity.Pose
import net.minecraft.world.phys.Vec3
import org.polyfrost.oneconfig.api.ui.v1.ExperimentalOneConfigUiApi
import org.polyfrost.oneconfig.api.ui.v1.a11y.Motion
import org.polyfrost.polyplus.client.bedrock.BedrockConstants
import org.polyfrost.polyplus.client.cosmetics.access.PlayerEmotesAccess
import org.polyfrost.polyplus.client.emotes.Emote
import org.polyfrost.polyplus.client.emotes.EmoteBundles
Expand Down Expand Up @@ -46,7 +45,8 @@ object LobbyGrab {
private const val NEAR_HOME = 1.5
private const val HEAD_HEIGHT = 1.6
private const val TURN_AROUND = 180f
private const val BASE_TICKS = 10.0
private const val LOOP_SECONDS = 1.0
private const val SWING_QUERY = "lobby_swing"
private const val FLAIL = 1.0
private const val ARM_SWING = 30.0
private const val ARM_SPREAD = 18.0
Expand Down Expand Up @@ -77,7 +77,7 @@ object LobbyGrab {
private val dangling by lazy { emote(FLAIL) }
private val still by lazy { emote(0.0) }

private class Hold(val avatar: LobbyAvatar, val anchor: Vec3, val previousClock: (() -> Long)?) {
private class Hold(val avatar: LobbyAvatar, val anchor: Vec3) {
var neckX = 0.0
var neckY = 0.0
var perRight = 1.0
Expand All @@ -93,7 +93,6 @@ object LobbyGrab {
var swing = 0.0
var lastSwing = 0.0
var tickNanos = System.nanoTime()
var starting = false
}

private class Drop(val avatar: LobbyAvatar, val from: Vec3, val to: Vec3, val ticks: Int, val hop: Double, val home: Boolean) {
Expand Down Expand Up @@ -140,16 +139,14 @@ object LobbyGrab {
if (abs(perRight) < MIN_SCALE || abs(perUp) < MIN_SCALE) return false
if (avatar.arrival != LobbyAvatar.Arrival.LANDED) avatar.halt()
strolling = null
val controller = controller(avatar)
val hold = Hold(avatar, avatar.position(), controller.clock)
val hold = Hold(avatar, avatar.position())
hold.neckX = neckX
hold.neckY = neckY
hold.perRight = perRight
hold.perUp = perUp
drop = null
held = hold
aim(hold, x, y)
controller.clock = { clockMs(hold) }
play(hold)
return true
}
Expand All @@ -163,7 +160,6 @@ object LobbyGrab {
held = null
val avatar = hold.avatar
val controller = controller(avatar)
controller.clock = hold.previousClock
if (Motion.reduced) controller.stop() else LobbyEntrance.fallPose()?.let(controller::play) ?: controller.stop()
val from = avatar.position()
val rest = avatar.rest.pos
Expand Down Expand Up @@ -202,7 +198,6 @@ object LobbyGrab {
drop = null
val avatar = hold?.avatar ?: falling?.avatar ?: return
val controller = controller(avatar)
if (hold != null) controller.clock = hold.previousClock
if (ours(controller.playing)) controller.stop()
avatar.pose = Pose.STANDING
if (avatar.arrival != LobbyAvatar.Arrival.LANDED) return
Expand All @@ -213,8 +208,10 @@ object LobbyGrab {
}

fun steer(avatar: LobbyAvatar): Boolean {
val active = held?.avatar === avatar || drop?.avatar === avatar
val hold = held
val active = hold?.avatar === avatar || drop?.avatar === avatar
if (!active) return false
if (hold != null) lean(hold)
val yaw = cameraYaw + TURN_AROUND
val head = avatar.position().add(0.0, HEAD_HEIGHT, 0.0)
val flat = sqrt((eye.x - head.x) * (eye.x - head.x) + (eye.z - head.z) * (eye.z - head.z))
Expand Down Expand Up @@ -332,26 +329,23 @@ object LobbyGrab {
}

private fun play(hold: Hold) {
val controller = controller(hold.avatar)
hold.starting = true
pose()?.let(controller::play)
hold.starting = false
val emote = pose() ?: return
emote.scene.query(SWING_QUERY, 0f)
controller(hold.avatar).play(emote)
}

private fun pose(): Emote? = if (Motion.reduced) still else dangling

private fun ours(emote: Emote?): Boolean = emote != null && (emote.id == DANGLE_ID || emote === LobbyEntrance.fallPose())

private fun clockMs(hold: Hold): Long {
if (hold.starting) return 0L
private fun lean(hold: Hold) {
val emote = controller(hold.avatar).playing?.takeIf { it === pose() } ?: return
val partial = ((System.nanoTime() - hold.tickNanos) / NANOS / TICK_SECONDS).coerceIn(0.0, 1.0)
val roll = -Mth.lerp(partial, hold.lastSwing, hold.swing).coerceIn(-MAX_SWING, MAX_SWING)
return ((BASE_TICKS + MAX_SWING + roll) * BedrockConstants.MS_PER_TICK).toLong()
emote.scene.query(SWING_QUERY, roll.toFloat())
}

private fun emote(flail: Double): Emote? {
val start = BASE_TICKS / BedrockConstants.TICKS_PER_SECOND
val end = (BASE_TICKS + 2.0 * MAX_SWING) / BedrockConstants.TICKS_PER_SECOND
val arm = ARM_SWING * flail
val spread = ARM_SPREAD * flail
val kick = LEG_KICK * flail
Expand All @@ -360,10 +354,10 @@ object LobbyGrab {
"format_version": "1.8.0",
"animations": {
"animation.lobby.dangle": {
"loop": "hold_on_last_frame",
"animation_length": $end,
"loop": true,
"animation_length": $LOOP_SECONDS,
"bones": {
"root": {"rotation": {"$start": [0, 0, ${-MAX_SWING}], "$end": [0, 0, $MAX_SWING]}},
"root": {"rotation": [0, 0, "q.$SWING_QUERY"]},
"rightArm": {"rotation": ["-25 + math.sin(q.life_time * 830) * $arm", 0, "60 + math.sin(q.life_time * 610) * $spread"]},
"leftArm": {"rotation": ["-25 - math.sin(q.life_time * 830) * $arm", 0, "-60 - math.sin(q.life_time * 610) * $spread"]},
"rightLeg": {"rotation": ["math.sin(q.life_time * 1000) * $kick", 0, 5]},
Expand Down