Advertisement
Thoughtcoder411

Pclient/otowin

Feb 16th, 2024
1,172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.55 KB | Gaming | 0 0
  1. import os
  2. import tkinter as tk
  3. from tkinter import filedialog, messagebox, simpledialog
  4. import pyautogui
  5. import time
  6. import pytesseract
  7. from pygetwindow import getWindowsWithTitle
  8.  
  9. # Configure pytesseract to use the appropriate path for Tesseract OCR executable
  10. pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'  # Update with your Tesseract OCR path
  11.  
  12. def detect_baritone(mods_folder):
  13.     baritone_identifier = None
  14.    
  15.     # Check if Baritone is installed by searching for its files in the mods folder
  16.     for filename in os.listdir(mods_folder):
  17.         if "Baritone" in filename:
  18.             baritone_identifier = input("Enter the identifier for Baritone commands (e.g., '#'): ")
  19.             break
  20.    
  21.     return baritone_identifier
  22.  
  23. def save_config(mods_folder):
  24.     with open("config.txt", "w") as f:
  25.         f.write(mods_folder)
  26.  
  27. def load_config():
  28.     if os.path.exists("config.txt"):
  29.         with open("config.txt", "r") as f:
  30.             return f.read().strip()
  31.     else:
  32.         return None
  33.  
  34. def browse_folder():
  35.     global mods_folder
  36.     mods_folder = filedialog.askdirectory(title="Select Minecraft Mods Folder")
  37.     if mods_folder:
  38.         baritone_identifier = detect_baritone(mods_folder)
  39.         if baritone_identifier:
  40.             messagebox.showinfo("Baritone Detected", f"Baritone detected. Identifier for Baritone commands: {baritone_identifier}")
  41.             save_config(mods_folder)
  42.         else:
  43.             messagebox.showinfo("Baritone Not Detected", "Baritone not detected in the selected mods folder.")
  44.  
  45. def send_command(command):
  46.     if mods_folder:
  47.         try:
  48.             pyautogui.press('t')
  49.             time.sleep(0.1)  # Wait for the chat window to open
  50.             pyautogui.typewrite(command)
  51.             pyautogui.press('enter')
  52.         except Exception as e:
  53.             messagebox.showerror("Error", f"Failed to send command: {e}")
  54.     else:
  55.         messagebox.showinfo("Mods Folder Not Selected", "Please select the mods folder first.")
  56.  
  57. def send_goto_command():
  58.     if mods_folder:
  59.         x = simpledialog.askfloat("Enter X Coordinate", "Please enter the X coordinate:")
  60.         y = simpledialog.askfloat("Enter Y Coordinate", "Please enter the Y coordinate:")
  61.         z = simpledialog.askfloat("Enter Z Coordinate", "Please enter the Z coordinate:")
  62.         if x is not None and y is not None and z is not None:
  63.             command = f"goto {x} {y} {z}"
  64.             send_command(command)
  65.  
  66. def detect_task_completion():
  67.     try:
  68.         # Get Minecraft window
  69.         mc_window = getWindowsWithTitle('Minecraft')[0]
  70.  
  71.         # Get coordinates of chat box region
  72.         chat_box_x = mc_window.left + 8
  73.         chat_box_y = mc_window.top + mc_window.height - 118
  74.         chat_box_width = 830
  75.         chat_box_height = 100
  76.  
  77.         # Take screenshot of chat box region
  78.         screenshot = pyautogui.screenshot(region=(chat_box_x, chat_box_y, chat_box_width, chat_box_height))
  79.  
  80.         # Perform OCR on the screenshot to extract text
  81.         chat_text = pytesseract.image_to_string(screenshot)
  82.  
  83.         # Check if "task complete" is found in the extracted text
  84.         if "task complete" in chat_text.lower():
  85.             messagebox.showinfo("Task Complete", "A task has been completed.")
  86.     except Exception as e:
  87.         messagebox.showerror("Error", f"Failed to detect task completion: {e}")
  88.  
  89. def abort_action():
  90.     if mods_folder:
  91.         identifier = simpledialog.askstring("Enter Identifier", "Please enter the identifier for aborting the action:")
  92.         if identifier:
  93.             command = f"{identifier} cancel"
  94.             send_command(command)
  95.  
  96. # Create the main application window
  97. root = tk.Tk()
  98. root.title("Baritone Control")
  99.  
  100. # Global variable to store the mods folder path
  101. mods_folder = load_config()
  102.  
  103. # Browse Button
  104. browse_button = tk.Button(root, text="Browse Mods Folder", command=browse_folder)
  105. browse_button.pack(pady=10)
  106.  
  107. # Send Help Command Button
  108. send_help_button = tk.Button(root, text="Send Baritone Help Command", command=lambda: send_command("#help"))
  109. send_help_button.pack(pady=10)
  110.  
  111. # Baritone Command Buttons
  112. goto_button = tk.Button(root, text="Goto", command=send_goto_command)
  113. goto_button.pack()
  114.  
  115. mine_button = tk.Button(root, text="Mine", command=lambda: send_command("mine"))
  116. mine_button.pack()
  117.  
  118. build_button = tk.Button(root, text="Build", command=lambda: send_command("build"))
  119. build_button.pack()
  120.  
  121. follow_button = tk.Button(root, text="Follow", command=lambda: send_command("follow"))
  122. follow_button.pack()
  123.  
  124. goto_bed_button = tk.Button(root, text="Goto Bed", command=lambda: send_command("goto bed"))
  125. goto_bed_button.pack()
  126.  
  127. explore_button = tk.Button(root, text="Explore", command=lambda: send_command("explore"))
  128. explore_button.pack()
  129.  
  130. farm_button = tk.Button(root, text="Farm", command=lambda: send_command("farm"))
  131. farm_button.pack()
  132.  
  133. deposit_button = tk.Button(root, text="Deposit", command=lambda: send_command("deposit"))
  134. deposit_button.pack()
  135.  
  136. return_button = tk.Button(root, text="Return", command=lambda: send_command("return"))
  137. return_button.pack()
  138.  
  139. cancel_button = tk.Button(root, text="Cancel", command=lambda: send_command("cancel"))
  140. cancel_button.pack()
  141.  
  142. # Abort Action Button
  143. abort_button = tk.Button(root, text="Abort Action", command=abort_action)
  144. abort_button.pack(pady=10)
  145.  
  146. # Detect Task Completion Button
  147. detect_completion_button = tk.Button(root, text="Detect Task Completion", command=detect_task_completion)
  148. detect_completion_button.pack(pady=10)
  149.  
  150. # Run the application
  151. root.mainloop()
  152.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement