diff --git a/debug_color_search.png b/debug_color_search.png new file mode 100644 index 0000000..d83764c Binary files /dev/null and b/debug_color_search.png differ diff --git a/debug_trade_window.png b/debug_trade_window.png new file mode 100644 index 0000000..ed89744 Binary files /dev/null and b/debug_trade_window.png differ diff --git a/minecraft_automation_log.txt b/minecraft_automation_log.txt index 95a1518..87ae38c 100644 --- a/minecraft_automation_log.txt +++ b/minecraft_automation_log.txt @@ -12101,3 +12101,214 @@ 2023-11-29 09:35:59,828: Posted to Discord: Potion clicked. 2023-11-29 09:35:59,829: Pressing 'Esc' key. 2023-11-29 09:36:00,844: Holding 'D' key for a step. +2023-12-17 11:30:09,838: Performing right click at (2725, 1203). +2023-12-17 11:30:11,040: Checking for trade window... +2023-12-17 11:30:12,374: Color at check position: 59, 61, 59 +2023-12-17 11:30:12,374: Trade window not detected. +2023-12-17 11:30:12,374: Trade window not detected. Stopping script. +2023-12-17 11:30:23,490: Performing right click at (2725, 1203). +2023-12-17 11:30:24,691: Checking for trade window... +2023-12-17 11:30:25,994: Color at check position: 59, 61, 59 +2023-12-17 11:30:25,994: Trade window not detected. +2023-12-17 11:30:25,994: Trade window not detected. Stopping script. +2023-12-17 11:30:37,932: Performing right click at (2725, 1203). +2023-12-17 11:30:39,133: Checking for trade window... +2023-12-17 11:30:40,269: Color at check position: 61, 63, 61 +2023-12-17 11:30:40,269: Trade window not detected. +2023-12-17 11:30:40,269: Trade window not detected. Stopping script. +2023-12-17 11:30:54,291: Performing right click at (2725, 1203). +2023-12-17 11:30:55,492: Checking for trade window... +2023-12-17 11:30:56,764: Color at check position: 137, 51, 24 +2023-12-17 11:30:56,764: Trade window detected. +2023-12-17 11:30:56,764: Dragging slider from (2600, 1399) to (2600, 1408). +2023-12-17 11:31:02,122: Taking a screenshot for color search... +2023-12-17 11:31:07,224: Color not found on the screen. Using fallback coordinates. +2023-12-17 11:31:07,325: Performing left click at (2535, 1421). +2023-12-17 11:31:08,433: Color not found on the screen. Using fallback coordinates. +2023-12-17 11:31:08,534: Performing left click at (2535, 1421). +2023-12-17 11:31:09,735: Performing left click at (None, None). +2023-12-17 11:31:09,835: Performing shift click at (2994, 1105). +2023-12-17 11:31:10,036: Performing left click at (2994, 1105). +2023-12-17 11:31:11,772: Posted to Discord: Potion clicked. +2023-12-17 11:31:11,873: Performing left click at (None, None). +2023-12-17 11:31:11,974: Performing shift click at (2994, 1105). +2023-12-17 11:31:12,174: Performing left click at (2994, 1105). +2023-12-17 11:31:35,194: Focusing Minecraft window... +2023-12-17 11:31:37,214: Pressing Esc... +2023-12-17 11:31:39,234: Performing right click. +2023-12-17 11:31:40,337: Checking for trade window... +2023-12-17 11:31:41,603: Trade window detected. +2023-12-17 11:31:41,604: Dragging slider. +2023-12-17 11:31:48,521: Focusing Minecraft window... +2023-12-17 11:31:50,540: Pressing Esc... +2023-12-17 11:31:52,558: Performing right click. +2023-12-17 11:31:53,661: Checking for trade window... +2023-12-17 11:31:54,941: Trade window not detected. Adjusting position. +2023-12-17 11:33:59,870: Focusing Minecraft window... +2023-12-17 11:34:01,888: Pressing Esc... +2023-12-17 11:34:03,906: Performing right click. +2023-12-17 11:34:05,009: Checking for trade window... +2023-12-17 11:34:06,314: Trade window not detected. Adjusting position. +2023-12-17 11:34:45,764: Focusing Minecraft window... +2023-12-17 11:34:47,782: Pressing Esc... +2023-12-17 11:34:49,800: Performing right click. +2023-12-17 11:34:50,903: Checking for trade window... +2023-12-17 11:34:51,343: Trade window not detected. Adjusting position. +2023-12-17 11:36:22,104: Focusing Minecraft window... +2023-12-17 11:36:24,123: Pressing Esc... +2023-12-17 11:36:26,141: Performing right click. +2023-12-17 11:36:27,244: Checking for trade window... +2023-12-17 11:36:28,540: Trade window not detected. Adjusting position. +2023-12-17 11:36:30,548: Focusing Minecraft window... +2023-12-17 11:36:32,564: Pressing Esc... +2023-12-17 11:36:34,582: Performing right click. +2023-12-17 11:36:35,685: Checking for trade window... +2023-12-17 11:36:36,936: Trade window not detected. Adjusting position. +2023-12-17 11:37:17,098: Focusing Minecraft window... +2023-12-17 11:37:19,116: Pressing Esc... +2023-12-17 11:37:21,136: Performing right click. +2023-12-17 11:37:22,239: Checking for trade window... +2023-12-17 11:37:23,526: Trade window not detected. Adjusting position. +2023-12-17 11:47:33,320: Focusing Minecraft window... +2023-12-17 11:47:35,339: Pressing Esc... +2023-12-17 11:47:37,359: Performing right click. +2023-12-17 11:47:38,462: Checking for trade window... +2023-12-17 11:47:39,722: Trade window not detected. Adjusting position. +2023-12-17 11:57:25,020: Focusing Minecraft window... +2023-12-17 11:57:27,028: Pressing Esc... +2023-12-17 11:57:29,048: Performing right click. +2023-12-17 11:57:30,151: Checking for trade window... +2023-12-17 11:57:31,450: Trade window not detected. Adjusting position. +2023-12-17 12:03:40,825: Focusing Minecraft window... +2023-12-17 12:03:42,832: Pressing Esc... +2023-12-17 12:03:44,851: Performing right click. +2023-12-17 12:04:17,389: Focusing Minecraft window... +2023-12-17 12:04:19,397: Pressing Esc... +2023-12-17 12:04:21,417: Performing right click. +2023-12-17 12:04:22,520: Checking for trade window... +2023-12-17 12:04:23,831: Trade window not detected. Adjusting position. +2023-12-17 12:04:54,886: Focusing Minecraft window... +2023-12-17 12:04:56,893: Pressing Esc... +2023-12-17 12:04:58,913: Performing right click. +2023-12-17 12:05:00,015: Checking for trade window... +2023-12-17 12:05:01,311: Trade window not detected. Adjusting position. +2023-12-17 12:07:14,402: Focusing Minecraft window... +2023-12-17 12:07:16,409: Pressing Esc... +2023-12-17 12:07:18,430: Performing right click. +2023-12-17 12:07:19,533: Checking for trade window... +2023-12-17 12:07:20,854: Trade window not detected. Adjusting position. +2023-12-17 12:07:54,996: Focusing Minecraft window... +2023-12-17 12:07:57,003: Pressing Esc... +2023-12-17 12:07:59,023: Performing right click. +2023-12-17 12:52:50,663: Focusing Minecraft window... +2023-12-17 12:52:52,670: Pressing Esc... +2023-12-17 12:52:54,690: Performing right click. +2023-12-17 12:52:55,793: Checking for trade window... +2023-12-17 12:53:36,015: Focusing Minecraft window... +2023-12-17 12:53:38,023: Pressing Esc... +2023-12-17 12:53:40,044: Performing right click. +2023-12-17 12:53:41,148: Checking for trade window... +2023-12-17 12:59:07,660: Focusing Minecraft window... +2023-12-17 12:59:09,675: Pressing Esc... +2023-12-17 12:59:11,695: Performing right click. +2023-12-17 13:08:03,057: Focusing Minecraft window... +2023-12-17 13:08:05,065: Pressing Esc... +2023-12-17 13:08:07,085: Performing right click. +2023-12-17 13:08:08,188: Checking for trade window... +2023-12-17 13:15:00,953: Focusing Minecraft window... +2023-12-17 13:15:02,962: Pressing Esc... +2023-12-17 13:15:04,982: Performing right click. +2023-12-17 13:15:06,085: Checking for trade window... +2023-12-17 13:15:30,776: Focusing Minecraft window... +2023-12-17 13:15:32,784: Pressing Esc... +2023-12-17 13:15:34,805: Performing right click. +2023-12-17 13:15:35,908: Checking for trade window... +2023-12-17 13:15:37,381: Trade window not detected. Adjusting position. +2023-12-17 13:23:35,530: Focusing Minecraft window... +2023-12-17 13:23:37,537: Pressing Esc... +2023-12-17 13:23:39,559: Performing right click. +2023-12-17 13:23:40,661: Checking for trade window... +2023-12-17 13:26:44,907: Focusing Minecraft window... +2023-12-17 13:26:46,913: Pressing Esc... +2023-12-17 13:26:48,940: Performing right click. +2023-12-17 13:30:11,777: Focusing Minecraft window... +2023-12-17 13:30:13,850: Pressing Esc... +2023-12-17 13:30:15,870: Performing right click. +2023-12-17 13:30:36,904: Focusing Minecraft window... +2023-12-17 13:30:38,911: Pressing Esc... +2023-12-17 13:30:40,940: Performing right click. +2023-12-17 13:30:42,043: Checking for trade window... +2023-12-17 13:33:45,069: Focusing Minecraft window... +2023-12-17 13:33:47,076: Pressing Esc... +2023-12-17 13:33:49,098: Performing right click. +2023-12-17 13:33:50,202: Checking for trade window... +2023-12-17 13:38:48,123: Focusing Minecraft window... +2023-12-17 13:38:50,130: Pressing Esc... +2023-12-19 11:06:16,101: Focusing Minecraft window... +2023-12-19 11:06:18,113: Pressing Esc... +2023-12-19 11:06:20,133: Performing right click. +2023-12-19 11:13:21,313: Performing right click. +2023-12-19 11:14:45,252: Performing right click. +2023-12-19 11:14:54,858: Performing right click. +2023-12-19 11:16:07,710: Focusing Minecraft window... +2023-12-19 11:16:09,720: Pressing Esc... +2023-12-19 11:16:11,739: Performing right click. +2023-12-19 11:16:12,841: Checking for trade window... +2023-12-19 11:16:14,338: Trade window not detected. Adjusting position. +2023-12-19 11:18:36,361: Focusing Minecraft window... +2023-12-19 11:18:38,372: Pressing Esc... +2023-12-19 11:18:40,389: Performing right click. +2023-12-19 11:18:41,491: Checking for trade window... +2023-12-19 11:20:55,308: Focusing Minecraft window... +2023-12-19 11:20:57,318: Pressing Esc... +2023-12-19 11:20:59,334: Performing right click. +2023-12-19 11:21:00,436: Checking for trade window... +2023-12-19 11:21:01,954: Trade window not detected. Adjusting position. +2023-12-19 11:21:21,695: Focusing Minecraft window... +2023-12-19 11:21:23,706: Pressing Esc... +2023-12-19 11:21:25,721: Performing right click. +2023-12-19 11:21:26,823: Checking for trade window... +2023-12-19 11:21:28,437: Trade window not detected. Adjusting position. +2023-12-19 11:21:46,566: Focusing Minecraft window... +2023-12-19 11:21:48,577: Pressing Esc... +2023-12-19 11:21:50,594: Performing right click. +2023-12-19 11:21:51,696: Checking for trade window... +2023-12-19 11:21:53,101: Trade window not detected. Adjusting position. +2023-12-19 11:30:02,483: Focusing Minecraft window... +2023-12-19 11:30:04,488: Pressing Esc... +2023-12-19 11:30:06,506: Performing right click. +2023-12-19 11:39:44,616: Focusing Minecraft window... +2023-12-19 11:39:46,622: Pressing Esc... +2023-12-19 11:39:48,646: Performing right click. +2023-12-19 11:39:49,748: Checking for trade window... +2023-12-19 11:39:51,102: Trade window not detected. Adjusting position. +2023-12-19 11:44:04,820: Focusing Minecraft window... +2023-12-19 11:44:06,826: Pressing Esc... +2023-12-19 11:44:08,844: Performing right click. +2023-12-19 11:48:54,901: Focusing Minecraft window... +2023-12-19 11:49:17,255: Focusing Minecraft window... +2023-12-19 11:49:19,256: Pressing Esc... +2023-12-19 11:49:21,257: Performing right click. +2023-12-19 11:49:22,258: Checking for trade window... +2023-12-19 11:50:23,569: Focusing Minecraft window... +2023-12-19 11:50:25,569: Pressing Esc... +2023-12-19 11:50:27,571: Performing right click. +2023-12-19 11:50:28,571: Checking for trade window... +2023-12-19 11:51:54,538: Focusing Minecraft window... +2023-12-19 11:51:56,539: Pressing Esc... +2023-12-19 11:51:58,540: Performing right click. +2023-12-19 11:51:59,541: Checking for trade window... +2023-12-19 11:51:59,541: Trade window not detected. Adjusting position. +2023-12-19 11:54:49,750: Focusing Minecraft window... +2023-12-19 11:54:51,751: Pressing Esc... +2023-12-19 11:54:53,764: Performing right click. +2023-12-19 11:54:54,790: Checking for trade window... +2023-12-19 11:54:54,791: Trade window not detected. Adjusting position. +2023-12-19 11:55:19,122: Focusing Minecraft window... +2023-12-19 11:55:21,123: Pressing Esc... +2023-12-19 11:55:23,124: Performing right click. +2023-12-19 12:01:33,410: Focusing Minecraft window... +2023-12-19 12:01:35,411: Pressing Esc... +2023-12-19 12:01:37,412: Performing right click. +2023-12-19 12:01:38,413: Checking for trade window... +2023-12-19 12:01:38,413: Trade window not detected. Adjusting position. diff --git a/move1.py b/move1.py new file mode 100644 index 0000000..f1f6832 --- /dev/null +++ b/move1.py @@ -0,0 +1,44 @@ +import pyautogui +import time +import threading +from Xlib import display + +def is_minecraft_focused(): + current_display = display.Display() + window_id = current_display.get_input_focus().focus.get_full_property(current_display.intern_atom('_NET_WM_NAME'), 0) + if window_id: + window_name = window_id.value + if "Minecraft" in window_name: + return True + return False + +def hold_key(): + time.sleep(5) # Wait for 5 seconds before starting + print("Starting to hold 'W' key. Press 'E' to stop.") + while not stop_thread: + if is_minecraft_focused(): + pyautogui.keyDown('w') + else: + pyautogui.keyUp('w') + time.sleep(0.1) + pyautogui.keyUp('w') + +# This flag will control the thread execution +stop_thread = False + +# Starting the thread that holds down the 'W' key +thread = threading.Thread(target=hold_key) +thread.start() + +# Waiting for the user to press 'E' to stop +try: + while True: + time.sleep(0.1) # Small delay to reduce CPU usage + if is_minecraft_focused() and pyautogui.press('x'): + stop_thread = True + break +except KeyboardInterrupt: + stop_thread = True + +thread.join() +print("Stopped.") diff --git a/trader.py b/trader.py index d4ea71f..36f6a3d 100644 --- a/trader.py +++ b/trader.py @@ -4,6 +4,7 @@ import time from PIL import Image, ImageGrab import logging + # Setup logging logging.basicConfig(filename='minecraft_automation_log.txt', level=logging.INFO, format='%(asctime)s: %(message)s') @@ -52,7 +53,7 @@ def find_color_in_image(target_color, image): def focus_minecraft_window(): log_and_print("Focusing Minecraft window...") - subprocess.run(['xdotool', 'search', '--name', 'Minecraft*1.20.2 - Multiplayer (3rd-party-Server)', 'windowactivate', '--sync']) + subprocess.run(['xdotool', 'search', '--name', 'Minecraft*3.20.2 - Multiplayer (3rd-party-Server)', 'windowactivate', '--sync']) time.sleep(2) log_and_print("Pressing Esc...") subprocess.run(['xdotool', 'key', 'Escape']) diff --git a/trader3.py b/trader3.py new file mode 100644 index 0000000..7798c30 --- /dev/null +++ b/trader3.py @@ -0,0 +1,124 @@ +import requests +import subprocess +import time +from PIL import Image +import logging +from wayland_screenshot import take_screenshot # This will be a custom function you need to implement + +# Setup logging +logging.basicConfig(filename='minecraft_automation_log.txt', level=logging.INFO, format='%(asctime)s: %(message)s') + +def log_and_print(message): + print(message) + logging.info(message) + +def post_to_discord(message): + webhook_url = 'YOUR_DISCORD_WEBHOOK_URL' + data = {"content": message} + response = requests.post(webhook_url, json=data) + log_and_print(f"Posted to Discord: {message}") + +def right_click(x, y): + move_mouse(x, y) + log_and_print("Performing right click.") + subprocess.run(['ydotool', 'click', '3']) # Right-click + +def drag_slider(start_x, start_y, end_x, end_y): + log_and_print("Dragging slider.") + move_mouse(start_x, start_y) + subprocess.run(['ydotool', 'mousedown', '1']) # Left mouse button down + move_mouse(end_x, end_y) + subprocess.run(['ydotool', 'mouseup', '1']) # Left mouse button up + +def click(x, y): + move_mouse(x, y) + log_and_print("Performing left click.") + subprocess.run(['ydotool', 'click', '1']) # Left-click + +def shift_click(x, y): + log_and_print("Performing shift click.") + move_mouse(x, y) + subprocess.run(['ydotool', 'keydown', 'Shift', 'click', '1', 'keyup', 'Shift']) # Shift-click + +def move_mouse(x, y): + subprocess.run(['ydotool', 'mousemove', str(x), str(y)]) + +def find_color_in_image(target_color, image): + width, height = image.size + for x in range(width): + for y in range(height): + if image.getpixel((x, y))[:3] == target_color: + return x, y + return None, None + +def focus_minecraft_window(): + log_and_print("Focusing Minecraft window...") + # Note: Focusing a specific window might not work in Wayland as it does in X11 + subprocess.run(['ydotool', 'search', '--name', 'Minecraft*3.20.2 - Multiplayer (3rd-party-Server)', 'windowactivate', '--sync']) + time.sleep(2) + log_and_print("Pressing Esc...") + subprocess.run(['ydotool', 'key', 'Escape']) + time.sleep(2) + +def check_trade_window(): + log_and_print("Checking for trade window...") + trade_window_area = (2314, 974, 3124, 1455) + screenshot = take_screenshot(trade_window_area) # This needs a custom implementation for Wayland + r, g, b = screenshot.getpixel((51, 69))[:3] + if (r, g, b) == (137, 51, 24): + log_and_print("Trade window detected.") + return True + else: + log_and_print("Trade window not detected. Adjusting position.") + # Adjusting position might not work as expected in Wayland + # This part needs to be tested and potentially adjusted + # ... + +def trade_actions(): + right_click(2725, 1203) + time.sleep(1) + + if not check_trade_window(): + log_and_print("Trade window not detected after right click. Stopping script.") + return False + + drag_slider(2600, 1399, 2600, 1408) + time.sleep(3) + + log_and_print("Taking a screenshot for color search...") + screenshot = take_screenshot() # This needs a custom implementation for Wayland + target_color = (222, 227, 114) # The color to search for + found_x, found_y = find_color_in_image(target_color, screenshot) + + if found_x is not None and found_y is not None: + log_and_print(f"Color found at ({found_x}, {found_y}). Clicking at this position.") + click(found_x, found_y) + else: + log_and_print("Color not found on the screen. Using fallback coordinates.") + click(2535, 1421) + time.sleep(1) + + for _ in range(2): + shift_click(2994, 1105) + time.sleep(1) + post_to_discord("Potion clicked.") + + log_and_print("Pressing 'Esc' key.") + subprocess.run(['ydotool', 'key', 'Escape']) + time.sleep(1) + + log_and_print("Holding 'D' key for a step.") + subprocess.run(['ydotool', 'keydown', 'd']) + time.sleep(0.45) # Hold 'D' for 0.45 seconds + subprocess.run(['ydotool', 'keyup', 'd']) + time.sleep(1) + + return True # Indicate that the trade action was successful + + +focus_minecraft_window() + +for _ in range(40): # Number of trades to perform + result = trade_actions() + if not result: + break # Stop the script if trade window is not detected