Skip to content

Commit

Permalink
fixed flaws with f#cker module
Browse files Browse the repository at this point in the history
fixed breaking slowly
fixed not breaking instantly
clean-up code
  • Loading branch information
1zun4 committed Dec 7, 2023
1 parent 7897d7a commit 3a7739e
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ object ModuleAutoFarm : Module("AutoFarm", Category.WORLD) {

private var currentTarget: BlockPos? = null

val networkTickHandler = repeatable { event ->
val repeatable = repeatable { event ->
if (mc.currentScreen is HandledScreen<*>) {
return@repeatable
}
Expand Down Expand Up @@ -91,7 +91,7 @@ object ModuleAutoFarm : Module("AutoFarm", Category.WORLD) {
if (!blockPos.getState()!!.isAir) {
val direction = rayTraceResult.side

if (mc.interactionManager!!.updateBlockBreakingProgress(blockPos, direction)) {
if (interaction.updateBlockBreakingProgress(blockPos, direction)) {
player.swingHand(Hand.MAIN_HAND)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,27 @@ object ModuleAutoTool : Module("AutoTool", Category.WORLD) {
val blockState = world.getBlockState(event.pos)
val inventory = player.inventory
val index = if (search) {
val (hotbarSlot, stack) = (0..8).map { Pair(it, inventory.getStack(it)) }.filter {
val stack = it.second
(stack.isNothing() || (!player.isCreative && (stack.damage < (stack.maxDamage - 2) || ignoreDurability)))
}.maxByOrNull {
val stack = it.second
val (hotbarSlot, stack) = (0..8).map {
it to inventory.getStack(it)
}.filter { (_, stack) ->
(stack.isNothing() ||
(!player.isCreative && (stack.damage < (stack.maxDamage - 2) || ignoreDurability)))
}.maxByOrNull { (_, stack) ->
stack.getMiningSpeedMultiplier(blockState)
} ?: return@handler
if (stack.getMiningSpeedMultiplier(blockState) == player.inventory.mainHandStack.getMiningSpeedMultiplier(
blockState
)
) return@handler
// no point in switching slots

val miningSpeedMultiplier = stack.getMiningSpeedMultiplier(blockState)

// The current slot already matches the best
if (miningSpeedMultiplier == player.inventory.mainHandStack.getMiningSpeedMultiplier(blockState)) {
return@handler
}

hotbarSlot
} else {
slot
}

SilentHotbar.selectSlotSilently(this, index, swapPreviousDelay)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import net.ccbluex.liquidbounce.features.module.modules.player.ModuleBlink
import net.ccbluex.liquidbounce.utils.aiming.RotationManager
import net.ccbluex.liquidbounce.utils.aiming.RotationsConfigurable
import net.ccbluex.liquidbounce.utils.aiming.raytraceBlock
import net.ccbluex.liquidbounce.utils.block.doBreak
import net.ccbluex.liquidbounce.utils.block.getCenterDistanceSquared
import net.ccbluex.liquidbounce.utils.block.getState
import net.ccbluex.liquidbounce.utils.block.searchBlocksInCuboid
Expand All @@ -34,8 +35,6 @@ import net.ccbluex.liquidbounce.utils.entity.getNearestPoint
import net.ccbluex.liquidbounce.utils.item.findBlocksEndingWith
import net.minecraft.block.BlockState
import net.minecraft.client.gui.screen.ingame.HandledScreen
import net.minecraft.network.packet.c2s.play.HandSwingC2SPacket
import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket
import net.minecraft.util.ActionResult
import net.minecraft.util.Hand
import net.minecraft.util.hit.HitResult
Expand All @@ -60,7 +59,6 @@ object ModuleFucker : Module("Fucker", Category.WORLD) {
}
}
private val surroundings by boolean("Surroundings", true)
private val visualSwing by boolean("VisualSwing", true)
private val targets by blocks("Target", findBlocksEndingWith("_BED", "DRAGON_EGG").toHashSet())
private val delay by int("Delay", 0, 0..20)
private val action by enumChoice("Action", DestroyAction.DESTROY, DestroyAction.values())
Expand All @@ -78,8 +76,19 @@ object ModuleFucker : Module("Fucker", Category.WORLD) {
return@repeatable
}

val wasTarget = currentTarget

updateTarget()

if (wasTarget != null && currentTarget == null) {
interaction.cancelBlockBreaking()
}

// Delay if the target changed - this also includes when introducing a new target from null.
if (wasTarget != currentTarget) {
waitTicks(delay)
}

// Check if blink is enabled - if so, we don't want to do anything.
if (ModuleBlink.enabled) {
return@repeatable
Expand All @@ -96,13 +105,11 @@ object ModuleFucker : Module("Fucker", Category.WORLD) {
destroyerTarget.pos.getState() ?: return@repeatable
) ?: return@repeatable

// Check if the raytrace result includes a block, if not we don't want to deal with it.
if (rayTraceResult.type != HitResult.Type.BLOCK) {
return@repeatable
}

val raytracePos = rayTraceResult.blockPos
if (raytracePos != destroyerTarget.pos) {

// Check if the raytrace result includes a block, if not we don't want to deal with it.
if (rayTraceResult.type != HitResult.Type.BLOCK ||
raytracePos.getState()?.isAir == true || raytracePos != destroyerTarget.pos) {
return@repeatable
}

Expand All @@ -114,40 +121,7 @@ object ModuleFucker : Module("Fucker", Category.WORLD) {

waitTicks(delay)
} else {
// Air is not very interesting. Trust me. It's better to breath it instead of breaking it.
if (raytracePos.getState()?.isAir == true) {
return@repeatable
}

val direction = rayTraceResult.side

if (forceImmediateBreak) {
network.sendPacket(
PlayerActionC2SPacket(
PlayerActionC2SPacket.Action.START_DESTROY_BLOCK, raytracePos, direction
)
)
swingHand()
network.sendPacket(
PlayerActionC2SPacket(
PlayerActionC2SPacket.Action.STOP_DESTROY_BLOCK, raytracePos, direction
)
)
} else {
if (interaction.updateBlockBreakingProgress(raytracePos, direction)) {
swingHand()
}
}

waitTicks(delay)
}
}

private fun swingHand() {
if (visualSwing) {
player.swingHand(Hand.MAIN_HAND)
} else {
network.sendPacket(HandSwingC2SPacket(Hand.MAIN_HAND))
doBreak(rayTraceResult, immediate = forceImmediateBreak)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ package net.ccbluex.liquidbounce.utils.block

import net.ccbluex.liquidbounce.utils.client.interaction
import net.ccbluex.liquidbounce.utils.client.mc
import net.ccbluex.liquidbounce.utils.client.network
import net.ccbluex.liquidbounce.utils.client.player
import net.minecraft.block.Block
import net.minecraft.block.BlockState
import net.minecraft.block.SideShapeType
import net.minecraft.item.ItemPlacementContext
import net.minecraft.item.ItemStack
import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket
import net.minecraft.util.ActionResult
import net.minecraft.util.Hand
import net.minecraft.util.hit.BlockHitResult
Expand Down Expand Up @@ -280,3 +282,38 @@ private fun handlePass(hand: Hand, stack: ItemStack, onItemUseSuccess: () -> Boo

handleActionsOnAccept(hand, actionResult, true, onItemUseSuccess)
}

/**
* Breaks the block
*/
fun doBreak(rayTraceResult: BlockHitResult, immediate: Boolean = false) {
val direction = rayTraceResult.side
val blockPos = rayTraceResult.blockPos

if (immediate) {
network.sendPacket(
PlayerActionC2SPacket(
PlayerActionC2SPacket.Action.START_DESTROY_BLOCK, blockPos, direction
)
)
player.swingHand(Hand.MAIN_HAND)
network.sendPacket(
PlayerActionC2SPacket(
PlayerActionC2SPacket.Action.STOP_DESTROY_BLOCK, blockPos, direction
)
)
return
}

if (player.isCreative) {
if (interaction.attackBlock(blockPos, rayTraceResult.side)) {
player.swingHand(Hand.MAIN_HAND)
return
}
}

if (interaction.updateBlockBreakingProgress(blockPos, direction)) {
player.swingHand(Hand.MAIN_HAND)
mc.particleManager.addBlockBreakingParticles(blockPos, direction)
}
}

0 comments on commit 3a7739e

Please sign in to comment.