Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import net.ccbluex.liquidbounce.event.EventManager;
import net.ccbluex.liquidbounce.event.events.KeybindChangeEvent;
import net.ccbluex.liquidbounce.event.events.KeybindIsPressedEvent;
import net.ccbluex.liquidbounce.event.events.SetKeyPressedEvent;
import net.ccbluex.liquidbounce.utils.client.VanillaTranslationRecognizer;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
Expand All @@ -49,4 +50,10 @@ private boolean isPressed(boolean original) {
return EventManager.INSTANCE.callEvent(new KeybindIsPressedEvent((KeyBinding) (Object) this, original)).isPressed();
}

@Inject(method = "setKeyPressed", at = @At("HEAD"), cancellable = true)
private static void hookSetKeyPressed(InputUtil.Key key, boolean pressed, CallbackInfo ci) {
if (EventManager.INSTANCE.callEvent(new SetKeyPressedEvent(key, pressed)).isCancelled()) {
ci.cancel();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ val ALL_EVENT_CLASSES: Array<KClass<out Event>> = arrayOf(
TitleEvent.Subtitle::class,
TitleEvent.Fade::class,
TitleEvent.Clear::class,
SetKeyPressedEvent::class
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import net.ccbluex.liquidbounce.utils.inventory.InventoryAction
import net.ccbluex.liquidbounce.utils.inventory.InventoryConstraints
import net.ccbluex.liquidbounce.utils.kotlin.Priority
import net.minecraft.client.network.ServerInfo
import net.minecraft.client.util.InputUtil
import net.minecraft.world.GameMode

@Deprecated(
Expand Down Expand Up @@ -91,6 +92,9 @@ class TargetChangeEvent(val target: PlayerData?) : Event(), WebSocketEvent
@Nameable("blockCountChange")
class BlockCountChangeEvent(val count: Int?) : Event(), WebSocketEvent

@Nameable("minecraftKeyPressed")
class SetKeyPressedEvent(val key: InputUtil.Key, val pressed: Boolean) : CancellableEvent()

@Nameable("clientChatStateChange")
class ClientChatStateChange(val state: State) : Event(), WebSocketEvent {
enum class State {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@ package net.ccbluex.liquidbounce.features.module.modules.world
import net.ccbluex.liquidbounce.config.types.nesting.Choice
import net.ccbluex.liquidbounce.config.types.nesting.ChoiceConfigurable
import net.ccbluex.liquidbounce.config.types.nesting.ToggleableConfigurable
import net.ccbluex.liquidbounce.event.events.BlockAttackEvent
import net.ccbluex.liquidbounce.event.events.BlockBreakingProgressEvent
import net.ccbluex.liquidbounce.event.events.SetKeyPressedEvent
import net.ccbluex.liquidbounce.event.handler
import net.ccbluex.liquidbounce.features.module.Category
import net.ccbluex.liquidbounce.features.module.ClientModule
import net.ccbluex.liquidbounce.utils.block.bed.BedBlockTracker
import net.ccbluex.liquidbounce.utils.block.getCenterDistanceSquaredEyes
import net.ccbluex.liquidbounce.utils.inventory.HotbarItemSlot
import net.ccbluex.liquidbounce.utils.block.getState
import net.ccbluex.liquidbounce.utils.client.SilentHotbar
import net.ccbluex.liquidbounce.utils.collection.Filter
import net.ccbluex.liquidbounce.utils.inventory.HotbarItemSlot
import net.ccbluex.liquidbounce.utils.inventory.ItemSlot
import net.ccbluex.liquidbounce.utils.inventory.SlotGroup
import net.ccbluex.liquidbounce.utils.inventory.Slots
Expand Down Expand Up @@ -87,10 +89,34 @@ object ModuleAutoTool : ClientModule("AutoTool", Category.WORLD) {

private val swapPreviousDelay by int("SwapPreviousDelay", 20, 1..100, "ticks")

private val requireSneaking by boolean("RequireSneaking", false)
private object RequireSneaking : ToggleableConfigurable(
this, "RequireSneaking", false
) {
private val requireHold by boolean("RequireHold", false)

private var breakStartedWithHoldingShift = false

@Suppress("unused")
private val blockAttackHandler = handler<BlockAttackEvent> {
if (!breakStartedWithHoldingShift) {
breakStartedWithHoldingShift = mc.options.sneakKey.isPressed
}
}

@Suppress("unused")
private val keyHandler = handler<SetKeyPressedEvent> {
if (it.key == mc.options.attackKey.boundKey && !it.pressed) {
breakStartedWithHoldingShift = false
}
}

fun matches(): Boolean {
return mc.options.sneakKey.isPressed || (!requireHold && breakStartedWithHoldingShift)
}
}

private object RequireNearBed : ToggleableConfigurable(
this, "RequireNearBed", enabled = false
this, "RequireNearBed", false
), BedBlockTracker.Subscriber {
override val maxLayers: Int get() = 1

Expand All @@ -110,24 +136,26 @@ object ModuleAutoTool : ClientModule("AutoTool", Category.WORLD) {
}

init {
tree(RequireNearBed)
treeAll(
RequireSneaking,
RequireNearBed
)
}

@Suppress("unused")
private val handleBlockBreakingProgress = handler<BlockBreakingProgressEvent> { event ->
if (!RequireNearBed.enabled || RequireNearBed.matches()) {
if (
(!RequireNearBed.enabled || RequireNearBed.matches())
&& (!RequireSneaking.enabled || RequireSneaking.matches())
) {
switchToBreakBlock(event.pos)
}
}

fun switchToBreakBlock(pos: BlockPos) {
if (requireSneaking && !player.isSneaking) {
return
}

val blockState = pos.getState()!!
val slot = toolSelector.activeChoice.getTool(blockState) ?: return
SilentHotbar.selectSlotSilently(this, slot, swapPreviousDelay)
val bestSlot = toolSelector.activeChoice.getTool(blockState) ?: return
SilentHotbar.selectSlotSilently(this, bestSlot, swapPreviousDelay)
}

fun <T : ItemSlot> SlotGroup<T>.findBestToolToMineBlock(
Expand Down