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

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

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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();
})();