Minefun Auto-Scaffold

Tự động đổi tay sang block và đặt xuống khi sắp bước vào lỗ hổng trong Minefun

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         Minefun Auto-Scaffold
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Tự động đổi tay sang block và đặt xuống khi sắp bước vào lỗ hổng trong Minefun
// @match        https://minefun.io/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    const SETTINGS = {
        enabled: true,
        toggleKey: 'KeyB',       // Phím B để Bật/Tắt Scaffold
        blockSlot: '1',          // Số slot ô chứa block trên thanh hotbar (1-9)
        placeDelay: 40,          // Tốc độ đặt block (ms)
        offsetDown: 1.2          // Độ sâu dò lỗ hổng dưới chân
    };

    let lastPlaceTime = 0;

    // Lắng nghe phím Bật/Tắt
    window.addEventListener('keydown', (e) => {
        if (e.code === SETTINGS.toggleKey) {
            SETTINGS.enabled = !SETTINGS.enabled;
            console.log(`[Scaffold] State: ${SETTINGS.enabled ? 'ON' : 'OFF'}`);
        }
    });

    // Giả lập chọn ô Hotbar (Slot 1-9)
    function selectBlockSlot() {
        window.dispatchEvent(new KeyboardEvent('keydown', { code: `Digit${SETTINGS.blockSlot}`, key: SETTINGS.blockSlot, bubbles: true }));
        window.dispatchEvent(new KeyboardEvent('keyup', { code: `Digit${SETTINGS.blockSlot}`, key: SETTINGS.blockSlot, bubbles: true }));
    }

    // Giả lập Click chuột phải (Đặt block)
    function triggerRightClick() {
        const canvas = document.querySelector('canvas') || document;
        canvas.dispatchEvent(new MouseEvent('mousedown', { button: 2, clientX: window.innerWidth / 2, clientY: window.innerHeight / 2, bubbles: true }));
        setTimeout(() => {
            canvas.dispatchEvent(new MouseEvent('mouseup', { button: 2, clientX: window.innerWidth / 2, clientY: window.innerHeight / 2, bubbles: true }));
        }, 10);
    }

    // Vòng lặp quét lỗ hổng và đặt block
    function loop() {
        requestAnimationFrame(loop);

        if (!SETTINGS.enabled) return;

        const now = Date.now();
        if (now - lastPlaceTime < SETTINGS.placeDelay) return;

        // Lấy đối tượng Game & Player từ global window
        const game = window.game || window.Client || window.App;
        const player = window.localPlayer || (game && game.player) || window.player;
        const world = window.world || (game && game.world);

        if (!player || !player.position) return;

        // Vị trí người chơi hiện tại
        const px = player.position.x;
        const py = player.position.y;
        const pz = player.position.z;

        // Hướng di chuyển (Velocity) hoặc hướng nhìn
        const vx = player.velocity ? player.velocity.x : 0;
        const vz = player.velocity ? player.velocity.z : 0;

        // Tính tọa độ ô block ngay trước mặt/dưới chân theo đà đi
        const checkX = Math.floor(px + (Math.abs(vx) > 0.01 ? Math.sign(vx) * 0.6 : 0));
        const checkY = Math.floor(py - SETTINGS.offsetDown);
        const checkZ = Math.floor(pz + (Math.abs(vz) > 0.01 ? Math.sign(vz) * 0.6 : 0));

        let isHole = false;

        if (world && typeof world.getBlock === 'function') {
            const block = world.getBlock(checkX, checkY, checkZ);
            // Block bằng 0 hoặc null/undefined nghĩa là không khí (lỗ hổng)
            if (!block || block === 0 || block.id === 0) {
                isHole = true;
            }
        } else {
            // Trường hợp không can thiệp sâu vào world data, kiểm tra trạng thái rơi/trên không
            if (player.onGround === false || (Math.abs(vx) > 0.05 || Math.abs(vz) > 0.05)) {
                isHole = true;
            }
        }

        if (isHole) {
            selectBlockSlot();
            triggerRightClick();
            lastPlaceTime = now;
        }
    }

    // Khởi chạy vòng lặp
    loop();
})();