Untitled

 avatar
unknown
plain_text
10 months ago
7.0 kB
13
Indexable
# auto_fish_z_klikaczem.py - Wersja dla Linuksa z zewnętrznym skryptem xdotool
import time
import math
import minescript
import subprocess  # Importujemy moduł do uruchamiania zewnętrznych programów

# --- Ustawienia ---
LOOK_CAPTURE_DELAY = 4.0
MAX_WAIT_TIME = 30.0
DIVE_THRESHOLD = 0.20
ANIMATION_TIME = 0.35
ANIMATION_STEPS = 20
DEBUG = True

# --- Ustawienia Sprzedaży ---
SELL_FISH_INTERVAL = 15
GUI_COMMAND = "ryby"
# Pełna, absolutna ścieżka do Twojego skryptu klikającego
KLIKACZ_SCRIPT_PATH = "/home/mateusz/klikacz.sh"

fish_caught_count = 0

def debug(msg):
    if DEBUG:
        minescript.echo(f"§7[AutoFish]§f {msg}")

# --- Funkcje pomocnicze, logika łowienia (bez zmian) ---

def try_get_coords(pos):
    try: return (float(pos.x), float(pos.y), float(pos.z))
    except Exception:
        try: return (float(pos[0]), float(pos[1]), float(pos[2]))
        except Exception: return (0,0,0)

def forward_point(distance=10.0):
    p = minescript.player()
    pos = try_get_coords(p.position)
    yaw, pitch = minescript.player_orientation()
    yr, pr = math.radians(yaw), math.radians(pitch)
    dx = -math.sin(yr) * math.cos(pr)
    dy = -math.sin(pr)
    dz =  math.cos(yr) * math.cos(pr)
    return (pos[0] + dx * distance, pos[1] + dy * distance, pos[2] + dz * distance)

def get_target_point(max_distance=25.0):
    block = minescript.player_get_targeted_block(max_distance)
    if block and hasattr(block, "position"):
        c = try_get_coords(block.position)
        return (c[0]+0.5, c[1]+0.5, c[2]+0.5)
    return forward_point()

def calc_yaw_pitch(from_pos, to_pos):
    dx, dy, dz = to_pos[0]-from_pos[0], to_pos[1]-from_pos[1], to_pos[2]-from_pos[2]
    yaw = -math.degrees(math.atan2(dx, dz))
    horiz = math.sqrt(dx*dx + dz*dz)
    pitch = -math.degrees(math.atan2(dy, horiz))
    return yaw, pitch

def smooth_look_to(target_point):
    p = minescript.player()
    pos = try_get_coords(p.position)
    start_yaw, start_pitch = minescript.player_orientation()
    target_yaw, target_pitch = calc_yaw_pitch(pos, target_point)
    yaw_diff = target_yaw - start_yaw
    if yaw_diff > 180: start_yaw += 360
    elif yaw_diff < -180: start_yaw -= 360
    for i in range(ANIMATION_STEPS + 1):
        progress = i / ANIMATION_STEPS
        current_yaw = start_yaw + (target_yaw - start_yaw) * progress
        current_pitch = start_pitch + (target_pitch - start_pitch) * progress
        minescript.player_set_orientation(current_yaw, current_pitch)
        time.sleep(ANIMATION_TIME / ANIMATION_STEPS)

def cast():
    debug("🎣 Rzucam wędkę...")
    minescript.player_press_use(True)
    time.sleep(0.12)
    minescript.player_press_use(False)

def reel_in():
    debug("🎯 Zwijam wędkę!")
    minescript.player_press_use(True)
    time.sleep(0.12)
    minescript.player_press_use(False)

def get_bobber():
    for e in minescript.entities():
        if hasattr(e, 'name') and "fishing" in e.name.lower():
            return e
    return None

def wait_for_bite():
    start_time = time.time()
    initial_y = None
    bobber_found_time = None
    while time.time() - start_time < 5:
        bobber = get_bobber()
        if bobber:
            if bobber_found_time is None: bobber_found_time = time.time()
            if time.time() - bobber_found_time > 0.5:
                initial_y = try_get_coords(bobber.position)[1]
                debug(f"🪱 Spławik na wodzie (y={initial_y:.2f}). Oczekuję na branie...")
                break
        time.sleep(0.1)
    if initial_y is None:
        debug("⚠️ Nie znaleziono spławika. Ponawiam rzut.")
        return False
    while time.time() - start_time < MAX_WAIT_TIME:
        bobber = get_bobber()
        if not bobber:
            debug("🤔 Spławik zniknął.")
            return True
        current_y = try_get_coords(bobber.position)[1]
        if initial_y - current_y >= DIVE_THRESHOLD:
            debug(f"🐟 BRANIE! Zanurzenie: {initial_y - current_y:.2f}")
            return True
        time.sleep(0.05)
    debug("⏰ Brak brania w określonym czasie.")
    return False

# --- UPROSZCZONA FUNKCJA SPRZEDAŻY ---
def sell_fish():
    global fish_caught_count
    debug(f"💰 Czas sprzedać ryby ({fish_caught_count} złowionych)!")

    # Krok 1: Otwórz GUI w grze
    debug("Otwieram menu /ryby...")
    minescript.execute(GUI_COMMAND)
    time.sleep(1.5) # Dajmy GUI czas na pełne załadowanie

    # Krok 2: Uruchom zewnętrzny skrypt klikający
    debug(f"Uruchamiam zewnętrzny skrypt: {KLIKACZ_SCRIPT_PATH}")
    try:
        # Używamy ['bash', path] dla pewności, że skrypt zostanie poprawnie wykonany
        subprocess.run(['bash', KLIKACZ_SCRIPT_PATH], check=True)
        debug("✅ Zewnętrzny skrypt klikający zakończył działanie.")
    except FileNotFoundError:
        debug(f"❌ BŁĄD KRYTYCZNY: Nie znaleziono skryptu pod ścieżką: {KLIKACZ_SCRIPT_PATH}")
        debug("❌ Sprawdź, czy ścieżka w skrypcie jest poprawna.")
    except Exception as e:
        debug(f"❌ Wystąpił błąd podczas uruchamiania skryptu klikacza: {e}")

    # Krok 3: Zresetuj licznik
    fish_caught_count = 0
    debug("Licznik ryb zresetowany.")

def fish_at_point(target_point):
    global fish_caught_count
    smooth_look_to(target_point)
    time.sleep(0.1)
    cast()
    if wait_for_bite():
        reel_in()
        debug("✅ Złowiono!")
        fish_caught_count += 1
        debug(f"Złowiono {fish_caught_count} z {SELL_FISH_INTERVAL} ryb.")
        time.sleep(1.2)
        if fish_caught_count >= SELL_FISH_INTERVAL:
            sell_fish()
            time.sleep(1.0)
    else:
        reel_in()
        debug("❌ Bez brania.")
        time.sleep(0.5)

def main():
    minescript.echo("§aAutoFish (z zewnętrznym klikaczem) - Start!")
    time.sleep(1.0)
    minescript.echo(f"§eBot sprzeda ryby co {SELL_FISH_INTERVAL} złowionych sztuk.")
    minescript.echo("§eUstaw się i spójrz w PIERWSZE łowisko (A)...")
    time.sleep(LOOK_CAPTURE_DELAY)
    point_a = get_target_point()
    minescript.echo(f"§bPunkt A zapisany: ({point_a[0]:.1f}, {point_a[1]:.1f}, {point_a[2]:.1f})")
    minescript.echo("§eTeraz spójrz w DRUGIE łowisko (B)...")
    time.sleep(LOOK_CAPTURE_DELAY)
    point_b = get_target_point()
    minescript.echo(f"§bPunkt B zapisany: ({point_b[0]:.1f}, {point_b[1]:.1f}, {point_b[2]:.1f})")
    minescript.echo("§6Rozpoczynam automatyczne łowienie! Użyj §c/killjob§6 aby zatrzymać.")
    is_point_a = True
    while True:
        if is_point_a:
            debug("=== Celuję w punkt A ===")
            fish_at_point(point_a)
        else:
            debug("=== Celuję w punkt B ===")
            fish_at_point(point_b)
        is_point_a = not is_point_a

if __name__ == "__main__":
    main()
Editor is loading...
Leave a Comment