From 57116d3b6fe5989989af99a13f3695c5b2345bda Mon Sep 17 00:00:00 2001 From: cvs0 Date: Tue, 6 Aug 2024 22:50:39 -0600 Subject: [PATCH] MCA Module --- src/main/java/net/aoba/module/Module.java | 17 ++++ .../java/net/aoba/module/ModuleManager.java | 3 +- .../net/aoba/module/modules/misc/MCA.java | 87 +++++++++++++++++++ 3 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 src/main/java/net/aoba/module/modules/misc/MCA.java diff --git a/src/main/java/net/aoba/module/Module.java b/src/main/java/net/aoba/module/Module.java index 0176e56..ccd1552 100644 --- a/src/main/java/net/aoba/module/Module.java +++ b/src/main/java/net/aoba/module/Module.java @@ -36,6 +36,8 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -461,6 +463,14 @@ public static boolean swapBack() { return result; } + public static FindItemResult find(Item... items) { + return find(itemStack -> { + for (Item item : items) { + if (itemStack.getItem() == item) return true; + } + return false; + }); + } public static void rotatePitch(float degrees) { MinecraftClient client = MinecraftClient.getInstance(); @@ -477,4 +487,11 @@ public static void rotatePitch(float degrees) { client.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.LookAndOnGround(player.getYaw(), newPitch, player.isOnGround())); } } + + public static void sendChatMessage(String message) { + MinecraftClient mc = MinecraftClient.getInstance(); + if (mc.inGameHud != null) { + mc.inGameHud.getChatHud().addMessage(Text.of(Formatting.DARK_PURPLE + "[" + Formatting.LIGHT_PURPLE + "Aoba" + Formatting.DARK_PURPLE + "] " + Formatting.RESET + message)); + } + } } \ No newline at end of file diff --git a/src/main/java/net/aoba/module/ModuleManager.java b/src/main/java/net/aoba/module/ModuleManager.java index 3b01840..76725fa 100644 --- a/src/main/java/net/aoba/module/ModuleManager.java +++ b/src/main/java/net/aoba/module/ModuleManager.java @@ -36,7 +36,6 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.util.InputUtil.Key; -import javax.tools.Tool; import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -115,6 +114,7 @@ public class ModuleManager implements KeyDownListener { public Module tooltips = new Tooltips(); public Module antihunger = new AntiHunger(); public Module expthrower = new EXPThrower(); + public Module mcf = new MCA(); public ModuleManager(List addons) { addModule(aimbot); @@ -185,6 +185,7 @@ public ModuleManager(List addons) { addModule(tooltips); addModule(antihunger); addModule(expthrower); + addModule(mcf); addons.stream().filter(Objects::nonNull).forEach(addon -> { try { diff --git a/src/main/java/net/aoba/module/modules/misc/MCA.java b/src/main/java/net/aoba/module/modules/misc/MCA.java new file mode 100644 index 0000000..f0962d2 --- /dev/null +++ b/src/main/java/net/aoba/module/modules/misc/MCA.java @@ -0,0 +1,87 @@ +package net.aoba.module.modules.misc; + +import net.aoba.Aoba; +import net.aoba.event.events.MouseClickEvent; +import net.aoba.event.listeners.MouseClickListener; +import net.aoba.module.Category; +import net.aoba.module.Module; +import net.aoba.settings.types.EnumSetting; +import net.aoba.settings.types.KeybindSetting; +import net.aoba.utils.FindItemResult; +import net.aoba.utils.types.MouseAction; +import net.aoba.utils.types.MouseButton; +import net.minecraft.client.util.InputUtil; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.Items; +import net.minecraft.util.Hand; +import org.lwjgl.glfw.GLFW; +import org.spongepowered.asm.mixin.injection.invoke.util.InvokeUtil; + +public class MCA extends Module implements MouseClickListener { + private final EnumSetting mode = new EnumSetting<>("mca_mode", "Mode", "The mode for the action to run when the middle mouse button is clicked.", Mode.FRIEND); + + private int selectedSlot; + + public MCA() { + super(new KeybindSetting("key.mca", "MCA Key", InputUtil.fromKeyCode(GLFW.GLFW_KEY_UNKNOWN, 0))); + + this.setName("MCA"); + this.setCategory(Category.of("misc")); + this.setDescription("Middle Click Action"); + + this.addSetting(mode); + } + + @Override + public void onDisable() { + Aoba.getInstance().eventManager.RemoveListener(MouseClickListener.class, this); + } + + @Override + public void onEnable() { + Aoba.getInstance().eventManager.AddListener(MouseClickListener.class, this); + } + + @Override + public void onToggle() { + + } + + @Override + public void OnMouseClick(MouseClickEvent mouseClickEvent) { + if (mouseClickEvent.button == MouseButton.MIDDLE && mouseClickEvent.action == MouseAction.DOWN) { + if (mode.getValue() == Mode.FRIEND) { + if (MC.targetedEntity == null) return; + if (!(MC.targetedEntity instanceof PlayerEntity player)) return; + + if (!Aoba.getInstance().friendsList.contains(player)) { + Aoba.getInstance().friendsList.addFriend(player); + mouseClickEvent.cancel(); + + sendChatMessage("Added " + player.getName().getString() + " to friends list."); + } else { + Aoba.getInstance().friendsList.removeFriend(player); + mouseClickEvent.cancel(); + + sendChatMessage("Removed " + player.getName().getString() + " from friends list."); + } + } else if (mode.getValue() == Mode.PEARL) { + FindItemResult result = find(Items.ENDER_PEARL); + + if (!result.found() || !result.isHotbar()) return; + + selectedSlot = MC.player.getInventory().selectedSlot; + + if (!result.isMainHand()) { + swap(result.slot(), false); + + MC.interactionManager.interactItem(MC.player, Hand.MAIN_HAND); + } + } + } + } + + public enum Mode { + FRIEND, PEARL + } +}