Skip to content

Commit

Permalink
BackTrack && FakeLag Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
XeContrast committed Dec 6, 2024
1 parent 702bfb2 commit ef3ee7e
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 329 deletions.
37 changes: 11 additions & 26 deletions src/main/java/net/ccbluex/liquidbounce/event/EventManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import net.ccbluex.liquidbounce.utils.MinecraftInstance

class EventManager : MinecraftInstance() {

private val registry = HashMap<Class<out Event>, MutableList<EventHook>>()
private val registry = hashMapOf<Class<out Event>, MutableList<EventHook>>()

// private val counter = HashMap<Class<out Event>, Int>()
// private var lastSyncTime = System.currentTimeMillis()
Expand Down Expand Up @@ -38,13 +38,10 @@ class EventManager : MinecraftInstance() {
*
* @param listenable for unregister
*/
fun unregisterListener(listenable: Listenable) {
for ((key, targets) in registry) {
fun unregisterListener(listenable: Listenable) =
registry.forEach { (_, targets) ->
targets.removeIf { it.eventClass == listenable }

registry[key] = targets
}
}

// private fun printProfiler() {
// println("--- Event Profiler(${Date()}) ---")
Expand All @@ -65,29 +62,17 @@ class EventManager : MinecraftInstance() {
* @param event to call
*/
fun callEvent(event: Event) {
// if(System.currentTimeMillis() - lastSyncTime > 1000) {
// printProfiler()
// lastSyncTime = System.currentTimeMillis()
// }
// counter[event.javaClass] = counter.getOrDefault(event.javaClass, 0) + 1

val targets = registry[event.javaClass] ?: return
try {
for (invokableEventTarget in targets) {
try {
if (!invokableEventTarget.eventClass.handleEvents() && !invokableEventTarget.isIgnoreCondition) {
continue
}

invokableEventTarget.method.invoke(invokableEventTarget.eventClass, event)
} catch (nullPointerException: NullPointerException) {
nullPointerException.printStackTrace()
} catch (throwable: Throwable) {
throwable.printStackTrace()
}
for (invokableEventTarget in targets) {
try {
if (!invokableEventTarget.eventClass.handleEvents() && !invokableEventTarget.isIgnoreCondition)
continue

invokableEventTarget.method.invoke(invokableEventTarget.eventClass, event)
} catch (throwable: Throwable) {
throwable.printStackTrace()
}
}catch (e :Exception){
e.printStackTrace()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ object Backtrack : Module() {
}

"modern" -> {
if (mc.isSingleplayer || mc.currentServerData == null) {
clearPackets()
return
}

// Prevent cancelling packets when not needed
if (isPacketQueueEmpty && areQueuedPacketsEmpty && !shouldBacktrack())
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ object FakeLag : Module() {
if (!resetTimer.hasTimePassed(recoilTime.get().toLong()))
return

if (mc.isSingleplayer || mc.currentServerData == null) {
blink()
return
}

if (event.eventType == EventState.SEND) {
event.cancelEvent()
if (packet is C03PacketPlayer && packet.isMoving) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ object BlockOverlay : Module() {
get() {
val blockPos = mc.objectMouseOver?.blockPos ?: return null

if (canBeClicked(blockPos) && mc.theWorld.worldBorder.contains(blockPos)) {
if (blockPos.canBeClicked() && mc.theWorld.worldBorder.contains(blockPos)) {
return blockPos
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class SuperheroFX : Module() {
fun onRender3D(event: Render3DEvent) {
val removeList = mutableListOf<FXParticle>()
for (particle in textParticles) {
if (particle.canRemove) {
if (particle.canRemove && !removeList.contains(particle)) {
removeList.add(particle)
continue
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import net.ccbluex.liquidbounce.ui.font.Fonts
import net.ccbluex.liquidbounce.ui.i18n.LanguageManager
import net.ccbluex.liquidbounce.utils.*
import net.ccbluex.liquidbounce.utils.block.BlockUtils
import net.ccbluex.liquidbounce.utils.block.BlockUtils.canBeClicked
import net.ccbluex.liquidbounce.utils.block.BlockUtils.isReplaceable
import net.ccbluex.liquidbounce.utils.block.PlaceInfo
import net.ccbluex.liquidbounce.utils.block.PlaceInfo.Companion.get
Expand Down Expand Up @@ -1236,7 +1237,7 @@ class Scaffold : Module() {
}
for (side in StaticStorage.facings()) {
val neighbor = hypixelBlockPos.offset(side)
if (!BlockUtils.canBeClicked(neighbor)) continue
if (!neighbor.canBeClicked()) continue
val dirVec = Vec3(side.directionVec)
var xSearch = 0.1
while (xSearch < 0.9) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1559,7 +1559,7 @@ class Scaffold2 : Module() {
} else {
for (facingType in EnumFacing.entries) {
val neighbor = blockPosition.offset(facingType)
if (!canBeClicked(neighbor)) continue
if (!neighbor.canBeClicked()) continue
val dirVec = Vec3(facingType.directionVec)
val auto = (if (towerState) towerSearchMode else searchMode).get().equals("Auto", true)
val center = (if (towerState) towerSearchMode else searchMode).get().equals("AutoCenter", true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ import net.ccbluex.liquidbounce.features.value.ListValue
import net.ccbluex.liquidbounce.ui.client.hud.element.Border
import net.ccbluex.liquidbounce.ui.client.hud.element.Element
import net.ccbluex.liquidbounce.ui.client.hud.element.ElementInfo
import net.ccbluex.liquidbounce.utils.EntityUtils
import net.ccbluex.liquidbounce.utils.MiniMapRegister
import net.ccbluex.liquidbounce.utils.RainbowShader
import net.ccbluex.liquidbounce.utils.SafeVertexBuffer
import net.ccbluex.liquidbounce.utils.*
import net.ccbluex.liquidbounce.utils.render.RenderUtils
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.client.renderer.Tessellator
Expand Down Expand Up @@ -75,16 +72,12 @@ class Radar(x: Double = 5.0, y: Double = 130.0) : Element(x, y) {
private var lastFov = 0f

override fun drawElement(partialTicks: Float): Border {
MiniMapRegister.updateChunks()

val fovAngle = fovAngleValue.get()

if (lastFov != fovAngle || fovMarkerVertexBuffer == null) {
if (lastFov != fovAngleValue.get() || fovMarkerVertexBuffer == null) {
// Free Memory
fovMarkerVertexBuffer?.deleteGlBuffers()

fovMarkerVertexBuffer = createFovIndicator(fovAngle)
lastFov = fovAngle
fovMarkerVertexBuffer = createFovIndicator(fovAngleValue.get())
lastFov = fovAngleValue.get()
}

val renderViewEntity = mc.renderViewEntity!!
Expand Down Expand Up @@ -313,8 +306,8 @@ class Radar(x: Double = 5.0, y: Double = 130.0) : Element(x, y) {

worldRenderer.begin(GL11.GL_TRIANGLE_FAN, DefaultVertexFormats.POSITION)

val start = (90.0f - (angle * 0.5f)) / 180.0f * Math.PI.toFloat()
val end = (90.0f + (angle * 0.5f)) / 180.0f * Math.PI.toFloat()
val start = (90f - (angle * 0.5f)).toRadians()
val end = (90f + (angle * 0.5f)).toRadians()

var curr = end
val radius = 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ object PacketUtils : MinecraftInstance(), Listenable {
}

is S14PacketEntity -> {
val entity = packet.getEntity(world)
val entity = packet.getEntity(world) ?: return
val mixinEntity = entity as? IMixinEntity

mixinEntity?.apply {
Expand Down
41 changes: 33 additions & 8 deletions src/main/java/net/ccbluex/liquidbounce/utils/block/BlockUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,30 @@ package net.ccbluex.liquidbounce.utils.block

import net.ccbluex.liquidbounce.utils.MinecraftInstance
import net.minecraft.block.Block
import net.minecraft.block.BlockContainer
import net.minecraft.block.BlockWorkbench
import net.minecraft.block.material.Material
import net.minecraft.block.state.IBlockState
import net.minecraft.client.Minecraft
import net.minecraft.entity.item.EntityFallingBlock
import net.minecraft.util.AxisAlignedBB
import net.minecraft.util.BlockPos
import net.minecraft.util.MathHelper
import net.minecraft.util.Vec3
import kotlin.math.floor

val BlockPos.state: IBlockState?
get() = Minecraft.getMinecraft().theWorld?.getBlockState(this)

val BlockPos.block: Block?
get() = this.state?.block
val BlockPos.material: Material?
get() = this.block?.material
val BlockPos.isReplaceable: Boolean
get() = this.material?.isReplaceable ?: false
val BlockPos.center: Vec3
get() = Vec3(x + 0.5, y + 0.5, z + 0.5)

object BlockUtils : MinecraftInstance() {

/**
Expand Down Expand Up @@ -44,13 +60,6 @@ object BlockUtils : MinecraftInstance() {
@JvmStatic
fun getState(blockPos: BlockPos?): IBlockState = mc.theWorld.getBlockState(blockPos)

/**
* Check if [blockPos] is clickable
*/
@JvmStatic
fun canBeClicked(blockPos: BlockPos?) = getBlock(blockPos)?.canCollideCheck(getState(blockPos), false) ?: false &&
mc.theWorld.worldBorder.contains(blockPos)

/**
* Get block name by [id]
*/
Expand Down Expand Up @@ -154,7 +163,7 @@ object BlockUtils : MinecraftInstance() {
* Check if block bounding box is full or partial (non-full)
*/
fun isBlockBBValid(blockPos: BlockPos, blockState: IBlockState? = null, supportSlabs: Boolean = false, supportPartialBlocks: Boolean = false): Boolean {
val state = blockState ?: getState(blockPos) ?: return false
val state = blockState ?: getState(blockPos)

val box = state.block.getCollisionBoundingBox(mc.theWorld, blockPos, state) ?: return false

Expand All @@ -171,4 +180,20 @@ object BlockUtils : MinecraftInstance() {

@JvmStatic
fun floorVec3(vec3: Vec3) = Vec3(floor(vec3.xCoord), floor(vec3.yCoord), floor(vec3.zCoord))

fun BlockPos.canBeClicked(): Boolean {
val state = this.state ?: return false
val block = state.block ?: return false

return when {
this !in mc.theWorld.worldBorder -> false
!block.canCollideCheck(state, false) -> false
block.material.isReplaceable -> false
block.hasTileEntity(state) -> false
!isBlockBBValid(this, state, supportSlabs = true, supportPartialBlocks = true) -> false
mc.theWorld.loadedEntityList.any { it is EntityFallingBlock && it.position == this } -> false
block is BlockContainer || block is BlockWorkbench -> false
else -> true
}
}
}
Loading

0 comments on commit ef3ee7e

Please sign in to comment.