Untitled

 avatar
unknown
plain_text
9 months ago
7.3 kB
21
Indexable
# auto_fish_linux.py - Wersja dla Ubuntu 24.04 z pynput
import time
import math
import minescript

# Krok 1: Import biblioteki dla Linuksa
try:
    from pynput.mouse import Button, Controller
except ImportError:
    minescript.echo("§cBŁĄD: Biblioteka 'pynput' nie jest zainstalowana!")
    minescript.echo("§cW terminalu wpisz: sudo apt install python3-pynput")
    raise SystemExit

# Stworzenie globalnego obiektu kontrolera myszy
mouse = Controller()

# --- 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 i Współrzędne GUI ---
SELL_FISH_INTERVAL = 15
GUI_COMMAND = "ryby" # Komenda bez ukośnika, zgodnie z dokumentacją

# WAŻNE: Poniższe współrzędne są z Windowsa. Musisz je zaktualizować!
COORDS_MAIN_MENU = (653, 474)
COORDS_TRANSFER_CART = (451, 356)
COORDS_SELL_INGOT = (679, 355)

fish_caught_count = 0

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

# Krok 2: Przepisana funkcja klikania dla pynput
def click_at(x, y):
    """Przesuwa kursor i wykonuje lewy klik używając pynput."""
    mouse.position = (x, y)
    time.sleep(0.1) # Pauza na zarejestrowanie ruchu
    mouse.press(Button.left)
    mouse.release(Button.left)
    time.sleep(0.3) # Pauza po kliknięciu

# --- Reszta skryptu (bez zmian w logice) ---

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

def sell_fish():
    global fish_caught_count
    debug(f"💰 Czas sprzedać ryby ({fish_caught_count} złowionych)!")
    minescript.execute(GUI_COMMAND)
    time.sleep(1.5)
    debug(f"Klikam w menu główne w: X={COORDS_MAIN_MENU[0]}, Y={COORDS_MAIN_MENU[1]}")
    click_at(COORDS_MAIN_MENU[0], COORDS_MAIN_MENU[1])
    time.sleep(1.0)
    debug(f"Klikam w wagonik w: X={COORDS_TRANSFER_CART[0]}, Y={COORDS_TRANSFER_CART[1]}")
    click_at(COORDS_TRANSFER_CART[0], COORDS_TRANSFER_CART[1])
    time.sleep(0.5)
    debug(f"Klikam w sprzedaż w: X={COORDS_SELL_INGOT[0]}, Y={COORDS_SELL_INGOT[1]}")
    click_at(COORDS_SELL_INGOT[0], COORDS_SELL_INGOT[1])
    time.sleep(1.0)
    fish_caught_count = 0
    debug("Ryby sprzedane i licznik 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 (Wersja dla Linux) - 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