CCBlueX / LiquidBounce

A free mixin-based injection hacked client for Minecraft using the Fabric API
https://liquidbounce.net/
GNU General Public License v3.0
1.52k stars 488 forks source link

[BUG] Sequences break when waiting for ticks on the first execution #1731

Closed superblaubeere27 closed 10 months ago

superblaubeere27 commented 11 months ago

LiquidBounce Branch

Nextgen

LiquidBounce Build/Version

latest

Operating System

macOS, Linux, Windows 7, Windows 8, Windows 8.1, Windows 10, Windows 11

Minecraft Version

1.20.X

Describe the bug

If a subroutine waits for n ticks on the first execution, it will only wait until the next tick.

someSequence {
    // This code would run immediately

    waitTicks(5)

    // This code runs after only one tick (<- BUG)

    waitTicks(5)

    // This code runs after five ticks (Correct)
}

Steps to reproduce

This unit test found the bug:

    @Test
    fun testWaitTicksBug() {
        var nTimesRan = 0

        val seq = CommonTestSequence(sequenceManager) {
            nTimesRan += 1

            waitTicks(5)

            nTimesRan += 1
        }

        for (i in 0 until 5) {
            assertEquals(1, nTimesRan)

            seq.onTick()
        }

        assertEquals(2, nTimesRan)
    }

Client Log

-

Screenshots

No response

Ell1ott commented 11 months ago

You can fix it by using sync() before you wait for the first time. This is not optimally tho

superblaubeere27 commented 11 months ago

You can fix it by using sync() before you wait for the first time. This is not optimally tho

I already have a real fix for it, dw. The bug is caused by the ordering of the constructor and fields not being ideal.