Skip to content

Commit 936cc3a

Browse files
committed
feat: add restore velocity option after cinematic finishes
1 parent 4a38b5a commit 936cc3a

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

engine/engine-paper/src/main/kotlin/com/typewritermc/engine/paper/entry/temporal/TemporalInteraction.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import com.typewritermc.engine.paper.entry.entries.CinematicAction
1212
import com.typewritermc.engine.paper.entry.entries.CinematicEntry
1313
import com.typewritermc.engine.paper.entry.entries.EventTrigger
1414
import com.typewritermc.engine.paper.entry.matches
15-
import com.typewritermc.engine.paper.entry.temporal.TemporalState.*
15+
import com.typewritermc.engine.paper.entry.temporal.TemporalState.ENDING
16+
import com.typewritermc.engine.paper.entry.temporal.TemporalState.PLAYING
17+
import com.typewritermc.engine.paper.entry.temporal.TemporalState.STARTING
1618
import com.typewritermc.engine.paper.entry.triggerFor
1719
import com.typewritermc.engine.paper.events.AsyncCinematicEndEvent
1820
import com.typewritermc.engine.paper.events.AsyncCinematicStartEvent

engine/engine-paper/src/main/kotlin/com/typewritermc/engine/paper/utils/PlayerState.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import com.github.retrooper.packetevents.util.Dummy
1111
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerSetSlot
1212
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerTimeUpdate
1313
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerWindowItems
14+
import com.typewritermc.core.utils.point.Vector
1415
import com.typewritermc.engine.paper.extensions.packetevents.sendPacketTo
1516
import com.typewritermc.engine.paper.interaction.InterceptionBundle
1617
import com.typewritermc.engine.paper.plugin
@@ -45,6 +46,7 @@ enum class GenericPlayerStateProvider(private val store: Player.() -> Any, priva
4546
resetPlayerTime()
4647
WrapperPlayServerTimeUpdate(world.gameTime, playerTime).sendPacketTo(this)
4748
}),
49+
VELOCITY({ velocity.toVector() }, { velocity = (it as Vector).toBukkitVector() }),
4850

4951
// All Players that are visible to the player
5052
VISIBLE_PLAYERS({
@@ -125,6 +127,10 @@ fun Player.state(keys: Array<out PlayerStateProvider>): PlayerState {
125127
return PlayerState(keys.associateWith { it.store(this) })
126128
}
127129

130+
fun Player.state(keys: List<PlayerStateProvider>): PlayerState {
131+
return PlayerState(keys.associateWith { it.store(this) })
132+
}
133+
128134
fun Player.restore(state: PlayerState?) {
129135
state?.state?.forEach { (key, value) -> key.restore(this, value) }
130136
}

extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/cinematic/CameraCinematicEntry.kt

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class CameraCinematicEntry(
8282
@Segments(icon = "fa6-solid:video")
8383
@InnerMin(Min(10))
8484
val segments: List<CameraSegment> = emptyList(),
85+
val advancedCameraSettings: AdvancedCameraSettings = AdvancedCameraSettings(),
8586
) : PrimaryCinematicEntry {
8687
override fun create(player: Player): CinematicAction {
8788
return CameraCinematicAction(
@@ -106,6 +107,16 @@ data class CameraSegment(
106107
val path: List<PathPoint> = emptyList(),
107108
) : Segment
108109

110+
/**
111+
* Advanced settings for camera cinematics.
112+
*
113+
* @property restoreVelocity When true, restores the player's velocity to its pre-cinematic value
114+
* after the cinematic finishes.
115+
*/
116+
data class AdvancedCameraSettings(
117+
val restoreVelocity: Boolean = false
118+
)
119+
109120
data class PathPoint(
110121
@WithRotation
111122
val location: Var<Position> = ConstVar(Position.ORIGIN),
@@ -187,12 +198,15 @@ class CameraCinematicAction(
187198

188199
if (originalState == null) {
189200
originalState = state(
190-
LOCATION,
191-
ALLOW_FLIGHT,
192-
FLYING,
193-
VISIBLE_PLAYERS,
194-
SHOWING_PLAYER,
195-
EffectStateProvider(INVISIBILITY)
201+
listOfNotNull(
202+
LOCATION,
203+
ALLOW_FLIGHT,
204+
FLYING,
205+
VISIBLE_PLAYERS,
206+
SHOWING_PLAYER,
207+
EffectStateProvider(INVISIBILITY),
208+
VELOCITY.takeIf { entry.advancedCameraSettings.restoreVelocity }
209+
)
196210
)
197211
context[PlayerPositionOverride] = position
198212
}

0 commit comments

Comments
 (0)