Skip to content

Commit f0fc4df

Browse files
committed
feat: add restore velocity option after cinematic finishes
1 parent 1e0de35 commit f0fc4df

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

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

Lines changed: 4 additions & 2 deletions
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
@@ -163,7 +165,7 @@ data class TemporalStartTrigger(
163165

164166
data class TemporalSettings(
165167
val blockChatMessages: Boolean = true,
166-
val blockActionBarMessages: Boolean = true,
168+
val blockActionBarMessages: Boolean = true
167169
)
168170

169171
data object TemporalStopTrigger : EventTrigger {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import org.bukkit.inventory.EquipmentSlot
2323
import org.bukkit.inventory.ItemStack
2424
import org.bukkit.potion.PotionEffect
2525
import org.bukkit.potion.PotionEffectType
26+
import org.bukkit.util.Vector
2627

2728
interface PlayerStateProvider {
2829
fun store(player: Player): Any
@@ -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 }, { velocity = it as Vector }),
4850

4951
// All Players that are visible to the player
5052
VISIBLE_PLAYERS({

extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/action/CinematicEntry.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,13 @@ class CinematicEntry(
4545
val blockChatMessages: Boolean = true,
4646
@Default("true")
4747
@Help("Whether to block actionbar messages from showing to the player while in the cinematic.")
48-
val blockActionBarMessages: Boolean = true
48+
val blockActionBarMessages: Boolean = true,
49+
@Default("false")
50+
@Help("Whether to restore the player's velocity after the cinematic finishes.")
51+
val restoreVelocity: Boolean = false
4952
) : ActionEntry {
5053
override val eventTriggers: List<EventTrigger>
51-
get() = listOf(TemporalStartTrigger(pageId, super.eventTriggers, TemporalSettings(blockChatMessages, blockActionBarMessages)))
54+
get() = listOf(TemporalStartTrigger(pageId, super.eventTriggers, TemporalSettings(blockChatMessages, blockActionBarMessages, restoreVelocity)))
5255

5356
override fun ActionTrigger.execute() {}
5457
}

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

Lines changed: 14 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,10 @@ data class CameraSegment(
106107
val path: List<PathPoint> = emptyList(),
107108
) : Segment
108109

110+
data class AdvancedCameraSettings(
111+
val restoreVelocity: Boolean = false
112+
)
113+
109114
data class PathPoint(
110115
@WithRotation
111116
val location: Var<Position> = ConstVar(Position.ORIGIN),
@@ -187,12 +192,15 @@ class CameraCinematicAction(
187192

188193
if (originalState == null) {
189194
originalState = state(
190-
LOCATION,
191-
ALLOW_FLIGHT,
192-
FLYING,
193-
VISIBLE_PLAYERS,
194-
SHOWING_PLAYER,
195-
EffectStateProvider(INVISIBILITY)
195+
*listOfNotNull(
196+
LOCATION,
197+
ALLOW_FLIGHT,
198+
FLYING,
199+
VISIBLE_PLAYERS,
200+
SHOWING_PLAYER,
201+
EffectStateProvider(INVISIBILITY),
202+
VELOCITY.takeIf { entry.advancedCameraSettings.restoreVelocity }
203+
).toTypedArray()
196204
)
197205
context[PlayerPositionOverride] = position
198206
}

0 commit comments

Comments
 (0)