|
| 1 | +package com.meteor.automation.modules; |
| 2 | + |
| 3 | +import com.meteor.automation.MeteorAutomation; |
| 4 | +import meteordevelopment.meteorclient.events.game.OpenScreenEvent; |
| 5 | +import meteordevelopment.meteorclient.events.game.GameLeftEvent; |
| 6 | +import meteordevelopment.meteorclient.settings.*; |
| 7 | +import meteordevelopment.meteorclient.systems.modules.Module; |
| 8 | +import meteordevelopment.orbit.EventHandler; |
| 9 | +import net.minecraft.client.MinecraftClient; |
| 10 | +import net.minecraft.client.gui.screen.Screen; |
| 11 | +import net.minecraft.entity.Entity; |
| 12 | +import net.minecraft.item.Item; |
| 13 | +import net.minecraft.item.Items; |
| 14 | +import net.minecraft.util.Hand; |
| 15 | +import com.meteor.automation.utils.LogUtils; |
| 16 | +import meteordevelopment.meteorclient.utils.player.ChatUtils; |
| 17 | + |
| 18 | +public class AutoJoinModule extends Module { |
| 19 | + private final SettingGroup sgGeneral = settings.getDefaultGroup(); |
| 20 | + |
| 21 | + // Setting for enabling auto join |
| 22 | + private final Setting<Boolean> autoJoinEnabled = sgGeneral.add(new BoolSetting.Builder() |
| 23 | + .name("enable-auto-join") |
| 24 | + .description("Automatically joins the desired game mode when in the lobby.") |
| 25 | + .defaultValue(true) |
| 26 | + .build()); |
| 27 | + |
| 28 | + // Item setting for specifying the item used to open the menu |
| 29 | + private final Setting<Item> joinItem = sgGeneral.add(new ItemSetting.Builder() |
| 30 | + .name("join-item") |
| 31 | + .description("The item required to open the menu to join a game mode.") |
| 32 | + .defaultValue(Items.STONE) // Use Items.STONE directly |
| 33 | + .build()); |
| 34 | + |
| 35 | + // Enum for join methods |
| 36 | + private enum JoinMethod { |
| 37 | + NPC, |
| 38 | + ITEM, |
| 39 | + CHAT_COMMAND |
| 40 | + } |
| 41 | + |
| 42 | + // Setting for selecting the join method |
| 43 | + private final Setting<JoinMethod> joinMethod = sgGeneral.add(new EnumSetting.Builder<JoinMethod>() |
| 44 | + .name("join-method") |
| 45 | + .description("Choose the method to join.") |
| 46 | + .defaultValue(JoinMethod.NPC) |
| 47 | + .build()); |
| 48 | + |
| 49 | + private Entity targetedNpc; // Store the targeted NPC for joining |
| 50 | + |
| 51 | + public AutoJoinModule() { |
| 52 | + super(MeteorAutomation.UTILITY, "auto-join", "Automatically joins the server from the lobby."); |
| 53 | + } |
| 54 | + |
| 55 | + @EventHandler |
| 56 | + private void onOpenScreen(OpenScreenEvent event) { |
| 57 | + if (autoJoinEnabled.get() && isInLobby(event.screen)) { |
| 58 | + handleJoin(); |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + private boolean isInLobby(Screen screen) { |
| 63 | + return screen.getClass().getSimpleName().equals("MainMenuScreen"); // Change as per your lobby name |
| 64 | + } |
| 65 | + |
| 66 | + private void handleJoin() { |
| 67 | + switch (joinMethod.get()) { |
| 68 | + case NPC: |
| 69 | + clickNpc(); |
| 70 | + break; |
| 71 | + case ITEM: |
| 72 | + useItemToOpenMenu(); |
| 73 | + break; |
| 74 | + case CHAT_COMMAND: |
| 75 | + sendChatCommand(); |
| 76 | + break; |
| 77 | + default: |
| 78 | + LogUtils.error("Invalid join method selected!"); |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + private void clickNpc() { |
| 83 | + if (targetedNpc != null) { |
| 84 | + MinecraftClient mc = MinecraftClient.getInstance(); |
| 85 | + mc.interactionManager.interactEntity(mc.player, targetedNpc, Hand.MAIN_HAND); |
| 86 | + LogUtils.info("Clicked on NPC to join the game."); |
| 87 | + } else { |
| 88 | + LogUtils.error("No NPC targeted for clicking."); |
| 89 | + } |
| 90 | + } |
| 91 | + |
| 92 | + @EventHandler |
| 93 | + private void onAttackEntity(AttackEntityEvent event) { |
| 94 | + // Set the targeted NPC when the player attacks it |
| 95 | + Entity entity = event.getEntity(); |
| 96 | + if (entity != null) { |
| 97 | + targetedNpc = entity; |
| 98 | + LogUtils.info("Targeted NPC set to: " + entity.getName().getString()); |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + private void useItemToOpenMenu() { |
| 103 | + MinecraftClient mc = MinecraftClient.getInstance(); |
| 104 | + if (mc.player != null && mc.player.getMainHandStack().getItem() == joinItem.get()) { |
| 105 | + mc.interactionManager.interactItem(mc.player, Hand.MAIN_HAND); // Simulate right-click |
| 106 | + LogUtils.info("Used item to open the menu for joining."); |
| 107 | + } else { |
| 108 | + LogUtils.error("Join item is not in hand."); |
| 109 | + } |
| 110 | + } |
| 111 | + |
| 112 | + private void sendChatCommand() { |
| 113 | + String command = "/join <your-game-mode>"; // Replace with the actual command |
| 114 | + ChatUtils.sendPlayerMsg(command); // Send the command to chat using ChatUtils |
| 115 | + LogUtils.info("Sent chat command to join the game."); |
| 116 | + } |
| 117 | + |
| 118 | + @EventHandler |
| 119 | + private void onGameLeft(GameLeftEvent event) { |
| 120 | + // Handle cleanup if necessary |
| 121 | + targetedNpc = null; // Reset targeted NPC when leaving the game |
| 122 | + } |
| 123 | + |
| 124 | + // Custom event class for AttackEntityEvent |
| 125 | + public static class AttackEntityEvent { |
| 126 | + private final Entity entity; |
| 127 | + |
| 128 | + public AttackEntityEvent(Entity entity) { |
| 129 | + this.entity = entity; |
| 130 | + } |
| 131 | + |
| 132 | + public Entity getEntity() { |
| 133 | + return entity; |
| 134 | + } |
| 135 | + } |
| 136 | +} |
0 commit comments