Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # this python script is for afking (Away from Keyboard) auto mob grinder in Minecraft
- # dont forget to define the 'hotbar' variable according to your needs
- # TODO: add a way to stop the bot instead of CTRL + C, prefebly a key listener at the while loop
- # Done: generate updated requirements.txt file
- import os
- import sys
- import cv2
- import time
- import datetime
- import pytesseract
- import numpy
- import win32con
- import win32gui
- import pynput
- import win32ui
- from PIL import Image
- pytesseract.pytesseract.tesseract_cmd = "C:\\Program Files\\Tesseract-OCR\\tesseract.exe"
- # hotbar dictionary for key switwinch in Minecraft, the values are the number of items in the slot, or a keyword for the item
- # the slot 3 to 9 filled with a full stack - 1 becuase we need to reserve inventory space for the exp bottles. without it the inventory
- # will be filled with mobs drops and the exp bottles will be dropped on the ground
- hotbar = {
- "1": 64, # food slot
- "2": "Weapon", # weapon slot
- "3": 63, # exp potion slot
- "4": 63, # exp potion slot
- "5": 63, # exp potion slot
- "6": 63, # exp potion slot
- "7": 63, # exp potion slot
- "8": 63, # exp potion slot
- "9": 63 # exp potion slot
- }
- def windowEnumerationHandler(hwnd, top_windows):
- top_windows.append((hwnd, win32gui.GetWindowText(hwnd)))
- def switch_to_window(winName):
- results = []
- top_windows = []
- win32gui.EnumWindows(windowEnumerationHandler, top_windows)
- for i in top_windows:
- if winName in i[1].lower():
- print(i)
- win32gui.ShowWindow(i[0],5)
- win32gui.SetForegroundWindow(i[0])
- break
- def type_a_command(command_string):
- pynput.keyboard.Controller().press(pynput.keyboard.KeyCode.from_char("/"))
- pynput.keyboard.Controller().release(pynput.keyboard.KeyCode.from_char("/"))
- time.sleep(0.2)
- pynput.keyboard.Controller().type(command_string[1:])
- time.sleep(0.2)
- pynput.keyboard.Controller().press(pynput.keyboard.Key.enter)
- pynput.keyboard.Controller().release(pynput.keyboard.Key.enter)
- time.sleep(0.2)
- pynput.mouse.Controller().click(pynput.mouse.Button.left)
- time.sleep(0.2)
- def fill_exp_potions():
- # this function is for filling the empty bottles from the SlimeFun plugin with exp
- pynput.keyboard.Controller().type('3')
- time.sleep(0.2)
- pynput.mouse.Controller().click(pynput.mouse.Button.right)
- time.sleep(0.2)
- pynput.keyboard.Controller().type('2')
- def main():
- if not switch_to_window("minecraft"):
- print("error: no Minecraft windows found")
- loop_count = 0
- left_right = False
- time.sleep(0.2)
- # it is neccecary to press the ESC key to close the inventory/menu window
- pynput.keyboard.Controller().press(pynput.keyboard.Key.esc)
- pynput.keyboard.Controller().release(pynput.keyboard.Key.esc)
- while True:
- k = cv2.waitKey(1) & 0xFF
- # press 'r' to exit
- #if k == ord('r'):
- if cv2.waitKey(1) == ord("r"):
- break
- if left_right:
- pynput.mouse.Controller().click(pynput.mouse.Button.left)
- pynput.mouse.Controller().move(200, 0)
- time.sleep(0.8)
- pynput.mouse.Controller().click(pynput.mouse.Button.left)
- pynput.mouse.Controller().move(200, 0)
- time.sleep(0.8)
- pynput.mouse.Controller().click(pynput.mouse.Button.left)
- pynput.mouse.Controller().move(200, 0)
- time.sleep(0.8)
- pynput.mouse.Controller().click(pynput.mouse.Button.left)
- pynput.mouse.Controller().move(200, 0)
- time.sleep(0.8)
- pynput.mouse.Controller().click(pynput.mouse.Button.left)
- pynput.mouse.Controller().move(200, 0)
- time.sleep(0.8)
- left_right = False
- print("Moved to the Right")
- else:
- pynput.mouse.Controller().click(pynput.mouse.Button.left)
- pynput.mouse.Controller().move(-200, 0)
- time.sleep(0.8)
- pynput.mouse.Controller().click(pynput.mouse.Button.left)
- pynput.mouse.Controller().move(-200, 0)
- time.sleep(0.8)
- pynput.mouse.Controller().click(pynput.mouse.Button.left)
- pynput.mouse.Controller().move(-200, 0)
- time.sleep(0.8)
- pynput.mouse.Controller().click(pynput.mouse.Button.left)
- pynput.mouse.Controller().move(-200, 0)
- time.sleep(0.8)
- pynput.mouse.Controller().click(pynput.mouse.Button.left)
- pynput.mouse.Controller().move(-200, 0)
- time.sleep(0.8)
- left_right = True
- print("Moved to the Left")
- # executing the /balance command to track how much money you get from McMMO Swords/Axe/Unarmed skills
- # type_a_command("/bal")
- fill_exp_potions()
- loop_count += 1
- print("loop_count: {},".format(loop_count))
- if __name__ == "__main__":
- start_time = datetime.datetime.now().time()
- end_time = datetime.datetime.now().time()
- print("starting afk at: {}".format(start_time))
- try:
- main()
- except KeyboardInterrupt:
- # execute the next lines after KeyboardInterrupt: Ctrl+C
- end_time = datetime.datetime.now().time()
- td_start = datetime.timedelta(hours=start_time.hour, minutes=start_time.minute, seconds=start_time.second)
- td_end = datetime.timedelta(hours=end_time.hour, minutes=end_time.minute, seconds=end_time.second)
- print("afk'ed for: {} (hh:mm:ss)".format(td_end - td_start))
- try:
- sys.exit(130)
- except SystemExit:
- os._exit(130)
Advertisement
Comments
-
- if any1 got a suggestion about how to make a clean "quit" from the script while off screen, please tell me:)
-
- Something like this > https://stackoverflow.com/questions/52601252/which-python-module-can-monitor-3-keys-combination-in-a-while-loop
-
- amazing!
Add Comment
Please, Sign In to add comment
Advertisement