fix: fixed Button being pressed after leaving Visual or Normal mode

This commit is contained in:
moonleay 2024-04-22 23:30:56 +02:00
parent 7be72ac9d9
commit 00f1c66972
Signed by: moonleay
GPG key ID: 82667543CCD715FB

View file

@ -1,9 +1,13 @@
package net.moonleay.mods.gimble.mixin;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.option.GameOptions;
import net.moonleay.mods.gimble.client.editor.Editor;
import net.moonleay.mods.gimble.client.editor.modes.Mode;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@ -11,6 +15,10 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(MinecraftClient.class)
public class NormalModeMixin {
@Shadow
@Nullable
public GameOptions options;
@Inject(method = "openPauseMenu", at = @At("HEAD"), cancellable = true)
private void setNormalMode(boolean pause, CallbackInfo ci) {
if (Editor.INSTANCE.getCURRENT_MODE() != Mode.NORMAL){
@ -20,4 +28,19 @@ public class NormalModeMixin {
ci.cancel();
}
}
@Inject(method = "handleInputEvents", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isUsingItem()Z"), cancellable = true)
private void blockWorldManipulation(CallbackInfo ci) {
if (Editor.INSTANCE.getCURRENT_MODE() == Mode.NORMAL || Editor.INSTANCE.getCURRENT_MODE() == Mode.VISUAL) {
while(this.options.attackKey.wasPressed()) {
}
while(this.options.useKey.wasPressed()) {
}
while(this.options.pickItemKey.wasPressed()) {
}
ci.cancel();
}
}
}