-
-
Notifications
You must be signed in to change notification settings - Fork 95
Various smaller improvements #350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
dfb8afb
Add a NONE RespawnLocationType to PlayerRespawnEventEntry
codingcat2468 802dea8
Add InvisibleData to ArmorStandEntity
codingcat2468 c99e1b9
Add a worldborder cinematic entry
codingcat2468 7b6ade6
Add frame range checks to InCinematicFactEntry
codingcat2468 d6f5250
Rename isInvisible property in InvisibleData to "invisible"
codingcat2468 b1fce6e
Revert changes to InCinematicFactEntry
codingcat2468 2b5f7ec
Implement a new "cinematic section" fact
codingcat2468 4c1b3d2
Small tweaks
gabber235 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
79 changes: 79 additions & 0 deletions
79
...ion/src/main/kotlin/com/typewritermc/basic/entries/cinematic/WorldborderCinematicEntry.kt
This file contains hidden or 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,79 @@ | ||
package com.typewritermc.basic.entries.cinematic | ||
|
||
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerWorldBorderSize | ||
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayWorldBorderLerpSize | ||
import com.typewritermc.core.books.pages.Colors | ||
import com.typewritermc.core.extension.annotations.Entry | ||
import com.typewritermc.core.extension.annotations.Segments | ||
import com.typewritermc.engine.paper.entry.Criteria | ||
import com.typewritermc.engine.paper.entry.entries.CinematicAction | ||
import com.typewritermc.engine.paper.entry.entries.PrimaryCinematicEntry | ||
import com.typewritermc.engine.paper.entry.entries.Segment | ||
import com.typewritermc.engine.paper.entry.temporal.SimpleCinematicAction | ||
import com.typewritermc.engine.paper.extensions.packetevents.sendPacket | ||
import com.typewritermc.engine.paper.extensions.packetevents.sendPacketTo | ||
import org.bukkit.entity.Player | ||
import java.time.Duration | ||
import java.util.* | ||
|
||
@Entry("worldborder_cinematic", "A cinematic that resizes the worldborder over time", Colors.CYAN, "mdi:resize") | ||
/** | ||
* The `Worldborder cinematic` entry can animate the worldborder client-side. | ||
* The border animation speed is not linked to the server's tick rate, since the animation fully runs on the client. | ||
* | ||
* ## How could this be used? | ||
* | ||
* This entry could be used to show the worldborder changing size during a cinematic, for example to emphasize a narrator talking about | ||
* how the border could change on a server based on certain conditions. | ||
*/ | ||
class WorldborderCinematicEntry( | ||
override val id: String = "", | ||
override val name: String = "", | ||
override val criteria: List<Criteria> = emptyList(), | ||
@Segments(icon = "mdi:resize") | ||
val segments: List<WorldborderSegment> = emptyList(), | ||
) : PrimaryCinematicEntry { | ||
override fun create(player: Player): CinematicAction { | ||
return WorldborderCinematicAction( | ||
player, | ||
this, | ||
) | ||
} | ||
} | ||
|
||
data class WorldborderSegment( | ||
override val startFrame: Int = 0, | ||
override val endFrame: Int = 0, | ||
val newSize: Double = 0.0, | ||
val oldSize: Optional<Double> = Optional.empty(), | ||
val transitionTime: Duration = Duration.ofMillis(1000), | ||
val fadeBack: Boolean = false | ||
) : Segment | ||
|
||
class WorldborderCinematicAction( | ||
private val player: Player, | ||
entry: WorldborderCinematicEntry, | ||
) : SimpleCinematicAction<WorldborderSegment>() { | ||
|
||
override val segments: List<WorldborderSegment> = entry.segments | ||
|
||
override suspend fun startSegment(segment: WorldborderSegment) { | ||
super.startSegment(segment) | ||
|
||
val oldSize = segment.oldSize.orElseGet(this::borderSize) | ||
val packet = WrapperPlayWorldBorderLerpSize(oldSize, segment.newSize, segment.transitionTime.toMillis()) | ||
packet.sendPacketTo(player) | ||
} | ||
|
||
private fun borderSize(): Double { | ||
return player.world.worldBorder.size | ||
} | ||
|
||
override suspend fun stopSegment(segment: WorldborderSegment) { | ||
super.stopSegment(segment) | ||
|
||
val packet = if (!segment.fadeBack) WrapperPlayServerWorldBorderSize(borderSize()) | ||
else WrapperPlayWorldBorderLerpSize(segment.newSize, borderSize(), segment.transitionTime.toMillis()) | ||
player.sendPacket(packet) | ||
} | ||
} |
This file contains hidden or 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
69 changes: 69 additions & 0 deletions
69
...xtension/src/main/kotlin/com/typewritermc/basic/entries/fact/CinematicSectionFactEntry.kt
This file contains hidden or 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,69 @@ | ||
package com.typewritermc.basic.entries.fact | ||
|
||
import com.google.gson.annotations.SerializedName | ||
import com.typewritermc.core.books.pages.Colors | ||
import com.typewritermc.core.books.pages.PageType | ||
import com.typewritermc.core.entries.Ref | ||
import com.typewritermc.core.entries.emptyRef | ||
import com.typewritermc.core.extension.annotations.Entry | ||
import com.typewritermc.core.extension.annotations.Help | ||
import com.typewritermc.core.extension.annotations.Page | ||
import com.typewritermc.engine.paper.entry.entries.GroupEntry | ||
import com.typewritermc.engine.paper.entry.entries.ReadableFactEntry | ||
import com.typewritermc.engine.paper.entry.temporal.currentTemporalFrame | ||
import com.typewritermc.engine.paper.entry.temporal.isPlayingTemporal | ||
import com.typewritermc.engine.paper.facts.FactData | ||
import org.bukkit.entity.Player | ||
import java.util.* | ||
|
||
@Entry( | ||
"cinematic_section_fact", | ||
"Whether the player is within a certain section of a cinematic", | ||
Colors.PURPLE, | ||
"mdi:camera-burst" | ||
) | ||
/** | ||
* The 'Cinematic Section Fact' is a fact that can return different values depending | ||
* on what part of a cinematic the player is in. | ||
* | ||
* The specified `sections` can be used to map a certain range of cinematic frames to a value | ||
* that will then be returned by the fact if the player is in that range. If none of the ranges | ||
* match or the player is not currently in a cinematic, the value from `default` will be returned instead. | ||
* | ||
* Optionally, a cinematic page can be specified to only check for the given sections | ||
* in that page, instead of any active cinematic. | ||
* | ||
* | ||
* <fields.ReadonlyFactInfo /> | ||
* | ||
* ## How could this be used? | ||
* With this fact, it is possible to make an entry act differently depending on | ||
* what section of a cinematic the player is in. | ||
*/ | ||
class CinematicSectionFactEntry( | ||
override val id: String = "", | ||
override val name: String = "", | ||
override val comment: String = "", | ||
override val group: Ref<GroupEntry> = emptyRef(), | ||
@Page(PageType.CINEMATIC) | ||
@SerializedName("cinematic") | ||
val pageId: String = "", | ||
val sections: List<CinematicSection> = emptyList(), | ||
@Help("Will be returned when the player is not in a cinematic, or not in any of the given sections") | ||
val default: Optional<Int> = Optional.empty() | ||
) : ReadableFactEntry { | ||
override fun readSinglePlayer(player: Player): FactData { | ||
val inCinematic = if (pageId.isNotBlank()) player.isPlayingTemporal(pageId) else player.isPlayingTemporal() | ||
val default = default.orElse(0) | ||
if (!inCinematic) return FactData(default) | ||
|
||
val output = sections.firstOrNull { it.frameRange.contains(player.currentTemporalFrame() ?: -1) }?.value | ||
return FactData(output ?: default) | ||
gabber235 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
|
||
data class CinematicSection( | ||
@Help("The range of cinematic frames the player has to be in") | ||
val frameRange: ClosedRange<Int> = IntRange.EMPTY, | ||
val value: Int = 0 | ||
gabber235 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
} |
gabber235 marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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
38 changes: 38 additions & 0 deletions
38
.../kotlin/com/typewritermc/entity/entries/data/minecraft/living/armorstand/InvisibleData.kt
This file contains hidden or 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,38 @@ | ||
package com.typewritermc.entity.entries.data.minecraft.living.armorstand | ||
|
||
import com.typewritermc.core.books.pages.Colors | ||
import com.typewritermc.core.extension.annotations.Entry | ||
import com.typewritermc.core.extension.annotations.Tags | ||
import com.typewritermc.engine.paper.entry.entity.SinglePropertyCollectorSupplier | ||
import com.typewritermc.engine.paper.entry.entries.EntityData | ||
import com.typewritermc.engine.paper.entry.entries.EntityProperty | ||
import com.typewritermc.engine.paper.extensions.packetevents.metas | ||
import me.tofaa.entitylib.meta.other.ArmorStandMeta | ||
import me.tofaa.entitylib.wrapper.WrapperEntity | ||
import org.bukkit.entity.Player | ||
import java.util.* | ||
import kotlin.reflect.KClass | ||
|
||
@Entry("invisible_data", "Whether the armor stand itself is invisible", Colors.RED, "mdi:mirror-variant") | ||
@Tags("invisible_data", "armor_stand_data") | ||
class InvisibleData( | ||
override val id: String = "", | ||
override val name: String = "", | ||
val invisible: Boolean = false, | ||
override val priorityOverride: Optional<Int> = Optional.empty(), | ||
) : EntityData<InvisibleProperty> { | ||
override fun type(): KClass<InvisibleProperty> = InvisibleProperty::class | ||
|
||
override fun build(player: Player): InvisibleProperty = InvisibleProperty(invisible) | ||
} | ||
|
||
data class InvisibleProperty(val invisible: Boolean) : EntityProperty { | ||
companion object : SinglePropertyCollectorSupplier<InvisibleProperty>(InvisibleProperty::class, InvisibleProperty(false)) | ||
} | ||
|
||
fun applyInvisibleData(entity: WrapperEntity, property: InvisibleProperty) { | ||
entity.metas { | ||
meta<ArmorStandMeta> { isInvisible = property.invisible } | ||
error("Could not apply InvisibleData to ${entity.entityType} entity.") | ||
} | ||
} |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.