This repository has been archived by the owner on Sep 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support custom tick rates, preparation for lagslayer hud fix
- Loading branch information
Showing
13 changed files
with
139 additions
and
60 deletions.
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
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 |
---|---|---|
@@ -1,8 +1,50 @@ | ||
package io.github.homchom.recode.game | ||
|
||
import kotlin.time.Duration.Companion.milliseconds | ||
import io.github.homchom.recode.Power | ||
import io.github.homchom.recode.event.listen | ||
import io.github.homchom.recode.event.listenEach | ||
import kotlinx.coroutines.flow.collect | ||
import kotlinx.coroutines.flow.take | ||
import kotlinx.coroutines.flow.takeWhile | ||
|
||
/** | ||
* @return this integer as a [kotlin.time.Duration] in ticks, where 20 ticks = 1 second. | ||
* The current client tick. | ||
* | ||
* @see waitTicks | ||
* @see AfterClientTickEvent | ||
*/ | ||
val Int.ticks get() = milliseconds * 50 | ||
val currentTick get() = TickRecorder.currentTick | ||
|
||
/** | ||
* Suspends until [AfterClientTickEvent] runs [ticks] times. Unlike [kotlinx.coroutines.delay], this is | ||
* event-based and respects tick rates. | ||
*/ | ||
suspend fun waitTicks(ticks: Int) = AfterClientTickEvent.notifications.take(ticks).collect() | ||
|
||
private object TickRecorder { | ||
var currentTick = 0L | ||
|
||
private val power = Power() | ||
|
||
init { | ||
power.listenEach(AfterClientTickEvent) { currentTick++ } | ||
} | ||
} | ||
|
||
class TickCountdown(private val duration: Int, private val onFinish: () -> Unit = {}) { | ||
val isActive get() = counter > 0 | ||
|
||
private var counter = 0 | ||
private val power = Power(startEnabled = true) | ||
|
||
fun wind() { | ||
val launch = !isActive | ||
counter = duration | ||
if (launch) power.listen(AfterClientTickEvent) { | ||
takeWhile { --counter > 0 } | ||
}.invokeOnCompletion { exception -> | ||
counter = 0 | ||
if (exception == null) onFinish() | ||
} | ||
} | ||
} |
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
28 changes: 28 additions & 0 deletions
28
src/main/java/io/github/homchom/recode/render/RenderDucks.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,28 @@ | ||
package io.github.homchom.recode.render | ||
|
||
import net.minecraft.core.SectionPos | ||
import net.minecraft.world.level.block.entity.BlockEntity | ||
|
||
/** | ||
* An [net.minecraft.client.renderer.LevelRenderer] that is augmented by recode. | ||
*/ | ||
@Suppress("FunctionName") | ||
interface DRecodeLevelRenderer { | ||
/** | ||
* @returns A filtered list of block entities that should still be rendered. | ||
*/ | ||
fun `recode$runBlockEntityEvents`( | ||
blockEntities: Collection<BlockEntity>, | ||
sectionPos: SectionPos? | ||
): List<BlockEntity> | ||
|
||
/** | ||
* Gets and returns the RGBA hex of [blockEntity]'s outline, or `null` if it will not be outlined. | ||
*/ | ||
fun `recode$getBlockEntityOutlineColor`(blockEntity: BlockEntity): Int? | ||
|
||
/** | ||
* Processes all unprocessed entity and block entity outlines. | ||
*/ | ||
fun `recode$processOutlines`(partialTick: Float) | ||
} |
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
2 changes: 0 additions & 2 deletions
2
src/main/java/io/github/homchom/recode/ui/text/StyledStringManipulation.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
d407688
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also comments out LagSlayer HUD so people don't have to explicitly disable it, for now