Skip to content

Commit

Permalink
feat(legacy): Improved FlagCheck GhostBlock Checks (CCBlueX#3065)
Browse files Browse the repository at this point in the history
should have less false flag & work better now (Closes: CCBlueX#2495)
  • Loading branch information
EclipsesDev authored May 20, 2024
1 parent e12a6c5 commit dadad13
Showing 1 changed file with 39 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ package net.ccbluex.liquidbounce.features.module.modules.misc
import net.ccbluex.liquidbounce.event.*
import net.ccbluex.liquidbounce.features.module.Module
import net.ccbluex.liquidbounce.features.module.Category
import net.ccbluex.liquidbounce.features.module.modules.combat.KillAura
import net.ccbluex.liquidbounce.script.api.global.Chat
import net.ccbluex.liquidbounce.utils.extensions.onPlayerRightClick
import net.ccbluex.liquidbounce.value.BoolValue
import net.ccbluex.liquidbounce.value.FloatValue
import net.ccbluex.liquidbounce.value.IntegerValue
import net.minecraft.init.Blocks
import net.minecraft.network.login.server.S00PacketDisconnect
import net.minecraft.network.play.client.C08PacketPlayerBlockPlacement
import net.minecraft.network.play.server.S01PacketJoinGame
import net.minecraft.network.play.server.S08PacketPlayerPosLook
import net.minecraft.util.BlockPos
import net.minecraft.util.EnumFacing
import net.minecraft.util.Vec3
import kotlin.math.abs
import kotlin.math.roundToLong
import kotlin.math.sqrt
Expand All @@ -33,13 +33,17 @@ object FlagCheck : Module("FlagCheck", Category.MISC, gameDetecting = true, hide
private var lastYaw = 0F
private var lastPitch = 0F

private var blockPlacementAttempts = mutableMapOf<BlockPos, Long>()
private var successfulPlacements = mutableSetOf<BlockPos>()

private fun clearFlags() {
flagCount = 0
blockPlacementAttempts.clear()
successfulPlacements.clear()
}

private var lagbackDetected = false
private var forceRotateDetected = false
private var ghostBlockDetected = false

private var lastMotionX = 0.0
private var lastMotionY = 0.0
Expand Down Expand Up @@ -76,18 +80,7 @@ object FlagCheck : Module("FlagCheck", Category.MISC, gameDetecting = true, hide
forceRotateDetected = false
}

// Idk still testing :/
// TODO: Make better check for ghostblock
if (player.onGround && player.onPlayerRightClick(BlockPos.ORIGIN, EnumFacing.DOWN, Vec3(packet.x, packet.y, packet.z))
&& player.lookVec.rotatePitch(-90f) != null) {
ghostBlockDetected = true
flagCount++
Chat.print("§dDetected §3GhostBlock §b(§eS08Packet§b) §b(§c${flagCount}x§b)")
} else {
ghostBlockDetected = false
}

if (!forceRotateDetected && !ghostBlockDetected) {
if (!forceRotateDetected) {
lagbackDetected = true
flagCount++
Chat.print("§dDetected §3Lagback §b(§c${flagCount}x§b)")
Expand All @@ -101,6 +94,12 @@ object FlagCheck : Module("FlagCheck", Category.MISC, gameDetecting = true, hide
lastPitch = mc.thePlayer.rotationPitch
}

if (packet is C08PacketPlayerBlockPlacement) {
val blockPos = packet.position
blockPlacementAttempts[blockPos] = System.currentTimeMillis()
successfulPlacements.add(blockPos)
}

when (packet) {
is S01PacketJoinGame, is S00PacketDisconnect -> {
clearFlags()
Expand All @@ -116,11 +115,34 @@ object FlagCheck : Module("FlagCheck", Category.MISC, gameDetecting = true, hide
}

/**
* Rubberband Checks (Still Under Testing)
* Rubberband Checks (Still Under Testing) & GhostBlock Checks
*/
@EventTarget
fun onUpdate(event: UpdateEvent) {
val player = mc.thePlayer ?: return
val world = mc.theWorld ?: return

val currentTime = System.currentTimeMillis()
val iterator = blockPlacementAttempts.iterator()

while (iterator.hasNext()) {
val entry = iterator.next()
val blockPos = entry.key
val timestamp = entry.value

if (currentTime - timestamp > 500) {
val block = world.getBlockState(blockPos).block
if (block == Blocks.air && player.isSwingInProgress
&& successfulPlacements != blockPos && !player.isBlocking
&& !KillAura.renderBlocking && !KillAura.blockStatus) {

successfulPlacements.remove(blockPos)
flagCount++
Chat.print("§dDetected §3GhostBlock §b(§c${flagCount}x§b)")
}
iterator.remove()
}
}

if (!rubberbandCheck || player.ticksExisted <= 100)
return
Expand Down

0 comments on commit dadad13

Please sign in to comment.