Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(InventoryMove): no inventory interactions while moving #4728

Open
wants to merge 6 commits into
base: nextgen
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
@@ -0,0 +1,23 @@
package net.ccbluex.liquidbounce.injection.mixins.minecraft.gui;

import net.ccbluex.liquidbounce.features.module.modules.movement.ModuleInventoryMove;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.gui.screen.ingame.InventoryScreen;
import net.minecraft.screen.slot.Slot;
import net.minecraft.screen.slot.SlotActionType;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(HandledScreen.class)
public abstract class MixinHandledScreen extends MixinScreen {

@Inject(method = "onMouseClick(Lnet/minecraft/screen/slot/Slot;IILnet/minecraft/screen/slot/SlotActionType;)V", at = @At("HEAD"), cancellable = true)
private void cancelMouseClick(Slot slot, int slotId, int button, SlotActionType actionType, CallbackInfo ci) {
var invMove = ModuleInventoryMove.INSTANCE;
if ((Object) this instanceof InventoryScreen && invMove.getRunning() && invMove.cancelClicks()) {
ci.cancel();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,28 @@
*/
package net.ccbluex.liquidbounce.features.module.modules.movement

import net.ccbluex.liquidbounce.config.types.NamedChoice
import net.ccbluex.liquidbounce.config.types.ToggleableConfigurable
import net.ccbluex.liquidbounce.event.events.NotificationEvent
import net.ccbluex.liquidbounce.event.events.QueuePacketEvent
import net.ccbluex.liquidbounce.event.events.ScreenEvent
import net.ccbluex.liquidbounce.event.events.TransferOrigin
import net.ccbluex.liquidbounce.event.events.*
import net.ccbluex.liquidbounce.event.handler
import net.ccbluex.liquidbounce.event.tickHandler
import net.ccbluex.liquidbounce.features.module.Category
import net.ccbluex.liquidbounce.features.module.ClientModule
import net.ccbluex.liquidbounce.features.module.modules.movement.ModuleInventoryMove.Behaviour.*
import net.ccbluex.liquidbounce.utils.client.Chronometer
import net.ccbluex.liquidbounce.utils.client.PacketQueueManager
import net.ccbluex.liquidbounce.utils.client.formatAsTime
import net.ccbluex.liquidbounce.utils.client.notification
import net.ccbluex.liquidbounce.utils.inventory.InventoryManager
import net.ccbluex.liquidbounce.utils.inventory.closeInventorySilently
import net.minecraft.client.gui.screen.ChatScreen
import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen
import net.minecraft.client.gui.screen.ingame.HandledScreen
import net.minecraft.client.gui.screen.ingame.InventoryScreen
import net.minecraft.client.option.KeyBinding
import net.minecraft.item.ItemGroups
import net.minecraft.network.packet.c2s.play.*
import org.lwjgl.glfw.GLFW.*

/**
* InventoryMove module
Expand All @@ -46,9 +49,24 @@ import net.minecraft.network.packet.c2s.play.*

object ModuleInventoryMove : ClientModule("InventoryMove", Category.MOVEMENT) {

private val undetectable by boolean("Undetectable", false)
val behavior by enumChoice("Behavior", NORMAL)

enum class Behaviour(override val choiceName: String) : NamedChoice {
NORMAL("Normal"),
SAFE("Safe"), // disable clicks while moving
UNDETECTABLE("Undetectable"), // stop in inventory
}

private val passthroughSneak by boolean("PassthroughSneak", false)

// states of movement keys, using mc.options.<key>.isPressed doesn't work for some reason
private val movementKeys = mc.options.run {
arrayOf(forwardKey, leftKey, backKey, rightKey, jumpKey, sneakKey).associateWith { false }.toMutableMap()
}

fun cancelClicks() =
behavior == SAFE && movementKeys.any { (key, pressed) -> pressed && shouldHandleInputs(key) }

object Blink : ToggleableConfigurable(this,"Blink", false) {

/**
Expand Down Expand Up @@ -99,7 +117,9 @@ object ModuleInventoryMove : ClientModule("InventoryMove", Category.MOVEMENT) {
}

fun shouldHandleInputs(keyBinding: KeyBinding): Boolean {
if (!running || mc.currentScreen is ChatScreen || isInCreativeSearchField()) {
val screen = mc.currentScreen ?: return true

if (!running || screen is ChatScreen || isInCreativeSearchField()) {
return false
}

Expand All @@ -108,7 +128,20 @@ object ModuleInventoryMove : ClientModule("InventoryMove", Category.MOVEMENT) {
}

// If we are in a handled screen, we should handle the inputs only if the undetectable option is not enabled
return !undetectable || mc.currentScreen !is HandledScreen<*>
return behavior == NORMAL || screen !is HandledScreen<*>
|| behavior == SAFE && screen is InventoryScreen
}

@Suppress("unused")
val keyHandler = handler<KeyboardKeyEvent> { event ->
val key = movementKeys.keys.find { it.matchesKey(event.keyCode, event.scanCode) } ?: return@handler
val pressed = shouldHandleInputs(key) && event.action != GLFW_RELEASE
movementKeys[key] = pressed

if (behavior == SAFE && mc.currentScreen is InventoryScreen
&& InventoryManager.isInventoryOpenServerSide && pressed) {
closeInventorySilently()
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,6 @@ object InventoryManager : EventListener {

if (screen is InventoryScreen || screen is GenericContainerScreen) {
inventoryOpened()

if (screen is InventoryScreen) {
isInventoryOpenServerSide = true
}
Comment on lines -245 to -248
Copy link
Member

@1zun4 1zun4 Nov 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little bit worried about this. I have to validate first if this is not causing any issues with the Inventory Manager

Copy link
Member

@1zun4 1zun4 Nov 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I thought:
image

Inventory Cleaner and other modules will not try to change the items anymore when inventory is opened. It always requires one click to trigger it to be open. But I can easily fix this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I didn't consider that. I changed it because the server only knows that we're in an inventory if we click a slot.

}
}

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/liquidbounce.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"minecraft.gui.MixinChatHud",
"minecraft.gui.MixinChatInputSuggestor",
"minecraft.gui.MixinChatScreen",
"minecraft.gui.MixinHandledScreen",
"minecraft.gui.MixinInGameHud",
"minecraft.gui.MixinPlayerListHud",
"minecraft.gui.MixinScoreboard",
Expand Down
Loading