• Chào bạn, hãy đăng ký hoặc đăng nhập để tham gia cùng bọn mình và sử dụng được đầy đủ chức năng của diễn đàn :).
Bot Tu Tiên Siêu Huyền Thoại – Linh Căn Nhị Tam, Đột Phá Phi Thăng, Code Free Cho Đạo Hữu Không Cần Mod!

Bot Tu Tiên Siêu Huyền Thoại – Linh Căn Nhị Tam, Đột Phá Phi Thăng, Code Free Cho Đạo Hữu Không Cần Mod!

sfss

THÀNH VIÊN
Tham gia
20/02/2026
Bài viết
3
Ê anh em, mình share con bot tu tiên Mineflayer đây.


Ban đầu chỉ là bot đào lapis rồi convert thành kinh nghiệm thôi, kiểu farm level cơ bản. Sau đó nghiện tu tiên nên thêm dần: linh căn random (có Hỗn Độn siêu hiếm), cảnh giới tu luyện, đột phá với thiên kiếp sét đánh, luyện công pháp, event cơ duyên, chat Gemini cổ phong...


Không cần mod server gì hết, chạy Node.js + Mineflayer bình thường.


Code full dưới đây, anh em test thử nhé. Có bug hay muốn thêm gì (save tu vi, auto ăn, v.v.) thì comment giúp mình với. Cảm ơn!

"
/*
* Bot Tu Tiên Minecraft (Chân Kiều Tiễn) - Full Source
* Copyright (c) 2026 sfss
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
const mineflayer = require('mineflayer')
const { GoogleGenerativeAI } = require('@Google/generative-ai')
const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
const { GoalNear, GoalBlock } = goals
const pvp = require('mineflayer-pvp').plugin

// ============================================================
// CẤU HÌNH
// ============================================================
const CONFIG = {
GEMINI_API_KEY: "AIzaxxxxxxxxxx", //thay bằng api gemini
ADMIN: "hhy",
BOT: {
host: 'localhost',
port: 1234,
username: 'ChanKieuTien',
auth: 'offline',
version: false,
},
MAU_CHAY_TRON: 6,
TAM_NHIN: 32,
LINH_THACH_BLOCK: [
'lapis_ore','deepslate_lapis_ore',
'diamond_ore','deepslate_diamond_ore',
'emerald_ore','deepslate_emerald_ore',
'ancient_debris','nether_quartz_ore',
],
KE_THU_MOB: ['ender_dragon','wither','wither_skeleton','blaze','ghast'],
}

// ============================================================
// HỆ THỐNG LINH CĂN
// ============================================================
const LINH_CAN_LIST = [
// ── Thường (tổng xác suất ~60%) ──
{ ten: 'Hỏa Linh Căn', xacSuat: 12, so: 1, do: 'Thường', moTa: 'Hỏa hệ, thiên phú luyện đan', buff: { effect: 'strength', lv: 1 } },
{ ten: 'Thủy Linh Căn', xacSuat: 11, so: 1, do: 'Thường', moTa: 'Thủy hệ, thiên phú phòng ngự', buff: { effect: 'water_breathing', lv: 1 } },
{ ten: 'Mộc Linh Căn', xacSuat: 10, so: 1, do: 'Thường', moTa: 'Mộc hệ, thiên phú hồi phục', buff: { effect: 'regeneration', lv: 1 } },
{ ten: 'Thổ Linh Căn', xacSuat: 10, so: 1, do: 'Thường', moTa: 'Thổ hệ, thiên phú phòng thủ', buff: { effect: 'resistance', lv: 1 } },
{ ten: 'Kim Linh Căn', xacSuat: 10, so: 1, do: 'Thường', moTa: 'Kim hệ, thiên phú công kích', buff: { effect: 'strength', lv: 1 } },
{ ten: 'Phong Linh Căn', xacSuat: 7, so: 1, do: 'Thường', moTa: 'Phong hệ, thiên phú tốc độ', buff: { effect: 'speed', lv: 2 } },
// ── Hiếm (tổng ~25%) ──
{ ten: 'Lôi Linh Căn', xacSuat: 8, so: 1, do: 'Hiếm', moTa: 'Lôi hệ, thiên lôi gia hộ', buff: { effect: 'strength', lv: 2 } },
{ ten: 'Băng Linh Căn', xacSuat: 7, so: 1, do: 'Hiếm', moTa: 'Băng hệ, thiên phú phong ấn', buff: { effect: 'slowness', lv: 0, self: false } },
{ ten: 'Quang Linh Căn', xacSuat: 5, so: 1, do: 'Hiếm', moTa: 'Quang hệ, thiên mệnh soi đường', buff: { effect: 'night_vision', lv: 1 } },
{ ten: 'Âm Linh Căn', xacSuat: 5, so: 1, do: 'Hiếm', moTa: 'Âm hệ, bóng tối che giấu thân hình', buff: { effect: 'invisibility', lv: 1 } },
// ── Cực hiếm nhị thiên phú (~10%) ──
{ ten: 'Kim Hỏa Nhị Linh Căn', xacSuat: 3, so: 2, do: 'Cực Hiếm', moTa: 'Nhị thiên phú - Kim Hỏa tương sinh', buff: { effect: 'strength', lv: 3 } },
{ ten: 'Lôi Phong Nhị Linh Căn', xacSuat: 3, so: 2, do: 'Cực Hiếm', moTa: 'Nhị thiên phú - Lôi Phong xung thiên',buff: { effect: 'speed', lv: 3 } },
{ ten: 'Băng Hỏa Nhị Linh Căn', xacSuat: 2, so: 2, do: 'Cực Hiếm', moTa: 'Nhị thiên phú - Âm Dương tương khắc', buff: { effect: 'strength', lv: 2 } },
{ ten: 'Quang Âm Nhị Linh Căn', xacSuat: 2, so: 2, do: 'Cực Hiếm', moTa: 'Nhị thiên phú - Quang Âm vô song', buff: { effect: 'resistance',lv: 2 } },
// ── Huyền thoại tam thiên phú (~4%) ──
{ ten: 'Kim Mộc Thủy Tam Linh Căn', xacSuat: 1.5, so: 3, do: 'Huyền Thoại', moTa: 'Tam thiên phú - Ngũ hành chi tú', buff: { effect: 'resistance', lv: 3 } },
{ ten: 'Lôi Phong Quang Tam Linh Căn',xacSuat: 1.5, so: 3, do: 'Huyền Thoại', moTa: 'Tam thiên phú - Tam tài hợp nhất', buff: { effect: 'speed', lv: 4 } },
{ ten: 'Âm Dương Lôi Tam Linh Căn', xacSuat: 1, so: 3, do: 'Huyền Thoại', moTa: 'Tam thiên phú - Hỗn nguyên chi khí', buff: { effect: 'strength', lv: 4 } },
// ── Siêu huyền thoại (~1%) ──
{ ten: 'Hỗn Độn Linh Căn', xacSuat: 0.6, so: 1, do: 'Siêu Huyền Thoại', moTa: 'Khai thiên tịch địa - Vô thượng thiên phú. Ngàn năm mới xuất hiện một lần.', buff: { effect: 'strength', lv: 10 } },
{ ten: 'Vô Cực Linh Căn', xacSuat: 0.3, so: 1, do: 'Siêu Huyền Thoại', moTa: 'Vượt ngoài ngũ hành - Thiên địa chi linh', buff: { effect: 'resistance',lv: 10 } },
{ ten: 'Thái Cực Nguyên Thủy Linh Căn', xacSuat: 0.1, so: 1, do: 'Siêu Huyền Thoại', moTa: 'Căn cơ tối thượng. Bản nguyên vũ trụ. Không thể đo lường.', buff: { effect: 'speed', lv: 10 } },
]

// ============================================================
// HỆ THỐNG CẢNH GIỚI
// ============================================================
const CANH_GIOI = [
{ ten: 'Luyện Khí Sơ Kỳ', danhHieu: '练气初期', nhom: 'pham', xp: 0 },
{ ten: 'Luyện Khí Trung Kỳ', danhHieu: '练气中期', nhom: 'pham', xp: 50 },
{ ten: 'Luyện Khí Hậu Kỳ', danhHieu: '练气后期', nhom: 'pham', xp: 120 },
{ ten: 'Luyện Khí Đỉnh Phong', danhHieu: '练气巅峰', nhom: 'pham', xp: 200 },
{ ten: 'Trúc Cơ Kỳ', danhHieu: '筑基期', nhom: 'pham', xp: 300 },
{ ten: 'Kết Đan Kỳ', danhHieu: '结丹期', nhom: 'pham', xp: 450 },
{ ten: 'Nguyên Anh Kỳ', danhHieu: '元婴期', nhom: 'pham', xp: 650 },
{ ten: 'Hóa Thần Sơ Kỳ', danhHieu: '化神初期', nhom: 'pham', xp: 900 },
{ ten: 'Hóa Thần Trung Kỳ', danhHieu: '化神中期', nhom: 'pham', xp: 1200 },
{ ten: 'Hóa Thần Hậu Kỳ', danhHieu: '化神后期', nhom: 'pham', xp: 1600 },
{ ten: 'Hóa Thần Viên Mãn', danhHieu: '化神圆满', nhom: 'pham', xp: 2100 },
{ ten: 'Luyện Hư Kỳ', danhHieu: '炼虚期', nhom: 'cao', xp: 2700 },
{ ten: 'Hợp Thể Kỳ', danhHieu: '合体期', nhom: 'cao', xp: 3400 },
{ ten: 'Đại Thừa Kỳ', danhHieu: '大乘期', nhom: 'cao', xp: 4200 },
{ ten: 'Độ Kiếp Kỳ', danhHieu: '渡劫期', nhom: 'cao', xp: 5200 },
{ ten: 'Phi Thăng', danhHieu: '飞升', nhom: 'cao', xp: 6500 },
{ ten: 'Địa Tiên', danhHieu: '地仙', nhom: 'tien', xp: 8000 },
{ ten: 'Thiên Tiên', danhHieu: '天仙', nhom: 'tien', xp: 10000 },
{ ten: 'Chân Tiên', danhHieu: '真仙', nhom: 'tien', xp: 12500 },
{ ten: 'Huyền Tiên', danhHieu: '玄仙', nhom: 'tien', xp: 15500 },
{ ten: 'Kim Tiên', danhHieu: '金仙', nhom: 'tien', xp: 19000 },
{ ten: 'Thái Ất Kim Tiên', danhHieu: '太乙金仙', nhom: 'tien', xp: 23000 },
{ ten: 'Đại La Kim Tiên', danhHieu: '大罗金仙', nhom: 'tien', xp: 28000 },
{ ten: 'Chuẩn Thánh', danhHieu: '准圣', nhom: 'thanh', xp: 35000 },
{ ten: 'Thánh Nhân', danhHieu: '圣人', nhom: 'thanh', xp: 45000 },
{ ten: 'Thiên Đạo Cảnh', danhHieu: '天道境', nhom: 'toicao', xp: 60000 },
{ ten: 'Đại Đạo Cảnh Sơ Kỳ', danhHieu: '大道境初期', nhom: 'toicao', xp: 80000 },
{ ten: 'Đại Đạo Cảnh Trung Kỳ', danhHieu: '大道境中期', nhom: 'toicao', xp: 105000 },
{ ten: 'Đại Đạo Cảnh Hậu Kỳ', danhHieu: '大道境后期', nhom: 'toicao', xp: 135000 },
{ ten: 'Hỗn Độn Nguyên Thủy', danhHieu: '混沌元始尊', nhom: 'toicao', xp: 999999 },
]

const CONG_THUC = {
pham: { ngocMin: 20, phuLieu: [{ name: 'nether_wart', so: 5 }], thoiGian: 24*60*1000, xpGain: 150, moTa: 'Ngọc Lưu Ly x20 + Nether Wart x5' },
cao: { ngocMin: 20, phuLieu: [{ name: 'blaze_rod', so: 3 }, { name: 'ghast_tear', so: 2 }], thoiGian: 24*60*1000, xpGain: 400, moTa: 'Ngọc Lưu Ly x20 + Blaze Rod x3 + Ghast Tear x2' },
tien: { ngocMin: 20, phuLieu: [{ name: 'diamond', so: 5 }, { name: 'golden_apple', so: 3 }], thoiGian: 24*60*1000, xpGain: 1000, moTa: 'Ngọc Lưu Ly x20 + Diamond x5 + Golden Apple x3' },
thanh: { ngocMin: 20, phuLieu: [{ name: 'netherite_ingot', so: 2 }, { name: 'enchanted_golden_apple', so: 1 }], thoiGian: 24*60*1000, xpGain: 3000, moTa: 'Ngọc Lưu Ly x20 + Netherite x2 + Enchanted Golden Apple x1' },
toicao: { ngocMin: 20, phuLieu: [{ name: 'dragon_egg', so: 1 }, { name: 'obsidian', so: 1 }, { name: 'command_block', so: 1 }], thoiGian: 48*60*1000, xpGain: 15000, moTa: 'Ngọc Lưu Ly x20 + Dragon Egg x1 + Obsidian x1 + Command Block x1' },
}

// Sự kiện ngẫu nhiên khi lang thang
const SU_KIEN = [
{ ten: 'co_duyen_biki', xacSuat: 8, moTa: 'Cơ duyên - Bí kíp công pháp', xpBonus: 200 },
{ ten: 'co_duyen_linhthu', xacSuat: 6, moTa: 'Cơ duyên - Linh thú quy phục', xpBonus: 150 },
{ ten: 'co_duyen_linh_quang', xacSuat: 5, moTa: 'Cơ duyên - Linh quang chiếu rọi', xpBonus: 100 },
{ ten: 'thien_kiep_nhe', xacSuat: 7, moTa: 'Thiên kiếp nhẹ - Lôi kiếp giáng', xpBonus: -50 },
{ ten: 'thien_kiep_nang', xacSuat: 3, moTa: 'Thiên kiếp nặng - Đại kiếp vân tụ',xpBonus: -150 },
{ ten: 'binh_tinh', xacSuat: 71, moTa: null, xpBonus: 0 }, // 71% không có gì
]

// Lệnh luyện công pháp
const CONG_PHAP = [
{ ten: 'Hỗn Nguyên Quyết', moTa: 'Luyện khí hóa thần, vận chuyển toàn thân', xp: 5 },
{ ten: 'Thái Hư Kiếm Quyết', moTa: 'Ý niệm hóa kiếm, vạn dặm sát địch', xp: 8 },
{ ten: 'Cửu Chuyển Kim Đan', moTa: 'Cửu chuyển linh lực, đan điền sung mãn', xp: 10 },
{ ten: 'Phá Hư Chưởng', moTa: 'Hư không phá vỡ, chưởng lực vô song', xp: 7 },
{ ten: 'Hồng Mông Nhất Khí', moTa: 'Hồng mông chi khí, vạn đạo quy nhất', xp: 15 },
]

// ============================================================
// KHỞI TẠO
// ============================================================
const genAI = new GoogleGenerativeAI(CONFIG.GEMINI_API_KEY)
const aiModel = genAI.getGenerativeModel({
model: "gemini-2.0-flash",
generationConfig: { maxOutputTokens: 80, temperature: 0.9 },
})

const bot = mineflayer.createBot(CONFIG.BOT)
bot.loadPlugin(pathfinder)
bot.loadPlugin(pvp)

// ============================================================
// TRẠNG THÁI
// ============================================================
const state = {
tuVi: 0,
soLanDotPha: 0,
dangLam: 'idle',
chatHistory: [],
lastChatTime: {},
tuLuyenTimer: null,
keHoachLoop: null,
kho: {},
// Thiên phú thế giới hiện tại (random khi spawn, đổi mỗi lần reconnect)
thienPhu: null,
// Công pháp đang luyện
congPhapHienTai: null,
// Danh hiệu hiển thị
danhHieuActive: false,
}

// ============================================================
// TIỆN ÍCH
// ============================================================
function log(msg) {
console.log(`[${new Date().toLocaleTimeString('vi-VN')}] ${msg}`)
}

function getCanhGioi() {
for (let i = CANH_GIOI.length - 1; i >= 0; i--) {
if (state.tuVi >= CANH_GIOI.xp) return { ...CANH_GIOI, index: i }
}
return { ...CANH_GIOI[0], index: 0 }
}

function getCongThuc() { return CONG_THUC[getCanhGioi().nhom] }
function getItem(name) { return bot.inventory.items().find(i => i.name === name) }
function demItem(name) { const i = getItem(name); return i ? i.count : 0 }
function khoVao(name, so) { state.kho[name] = (state.kho[name] || 0) + so }
function khoLay(name) { return state.kho[name] || 0 }
function sleep(ms) { return new Promise(r => setTimeout(r, ms)) }

function isOnCooldown(username) {
const now = Date.now()
if (state.lastChatTime[username] && now - state.lastChatTime[username] < 5000) return true
state.lastChatTime[username] = now
return false
}

function say(text) {
if (!text) return
const parts = []
let rem = text.trim()
while (rem.length > 200) {
let cut = rem.lastIndexOf(' ', 200)
if (cut === -1) cut = 200
parts.push(rem.slice(0, cut))
rem = rem.slice(cut).trim()
}
if (rem) parts.push(rem)
parts.forEach((p, i) => setTimeout(() => bot.chat(p), i * 1200))
}

function dungLai() {
try { bot.pathfinder.setGoal(null) } catch (_) {}
try { bot.pvp.stop() } catch (_) {}
if (state.tuLuyenTimer) { clearTimeout(state.tuLuyenTimer); state.tuLuyenTimer = null }
state.dangLam = 'idle'
}

// ============================================================
// HỆ THỐNG THIÊN PHÚ / LINH CĂN
// ============================================================
function rollLinhCan() {
// Weighted random
const total = LINH_CAN_LIST.reduce((s, lc) => s + lc.xacSuat, 0)
let rand = Math.random() * total
for (const lc of LINH_CAN_LIST) {
rand -= lc.xacSuat
if (rand <= 0) return lc
}
return LINH_CAN_LIST[0]
}

function khoiTaoThienPhu() {
state.thienPhu = rollLinhCan()
log(`[Thiên Phú] ${state.thienPhu.ten} (${state.thienPhu.do}) - ${state.thienPhu.moTa}`)
// Áp dụng buff linh căn
apDungBuff(state.thienPhu.buff)
}

function apDungBuff(buff) {
if (!buff || !buff.effect) return
try {
const dur = 9999999
bot.chat(`/effect give ${bot.username} ${buff.effect} ${dur} ${buff.lv} true`)
} catch (_) {}
}

async function kiemTraThienPhu(username) {
if (!state.thienPhu) khoiTaoThienPhu()
const lc = state.thienPhu
const cg = getCanhGioi()

// Hiệu ứng title hoành tráng
bot.chat(`/title ${bot.username} title {"text":"${lc.so === 1 ? '一' : lc.so === 2 ? '二' : '三'}灵根","color":"${lc.do === 'Siêu Huyền Thoại' ? 'gold' : lc.do === 'Huyền Thoại' ? 'light_purple' : lc.do === 'Cực Hiếm' ? 'aqua' : lc.do === 'Hiếm' ? 'green' : 'white'}","bold":true}`)
bot.chat(`/title ${bot.username} subtitle {"text":"${lc.ten}","color":"yellow"}`)

await sleep(1000)

// Thông báo công khai
say(`══════════════════`)
await sleep(500)
say(`[THIÊN PHÚ GIÁM ĐỊNH]`)
await sleep(800)

if (lc.do === 'Siêu Huyền Thoại') {
say(`⚡ THIÊN ĐỊA CHẤN ĐỘNG! ⚡`)
await sleep(600)
bot.chat(`/summon lightning_bolt ~ ~ ~`)
bot.chat(`/playsound minecraft:entity.lightning_bolt.thunder master @a`)
} else if (lc.do === 'Huyền Thoại') {
bot.chat(`/summon lightning_bolt ~ ~5 ~`)
}

await sleep(500)
say(`${username} chứng kiến — Chân Kiều Tiễn tại thế giới này mang ${lc.ten}`)
await sleep(800)
say(`Độ hiếm: [${lc.do}] | Số linh căn: ${lc.so}`)
await sleep(800)
say(`Thiên phú: ${lc.moTa}`)
await sleep(800)
say(`Cảnh giới: ${cg.ten} | Tu vi: ${state.tuVi}`)
await sleep(500)
say(`══════════════════`)

log(`[*k] ${username} kiểm tra thiên phú: ${lc.ten}`)
}

// ============================================================
// LUYỆN CÔNG PHÁP
// ============================================================
async function luyenCongPhap() {
if (state.dangLam !== 'idle') return
state.dangLam = 'luyen_cong_phap'

// Random công pháp
const cp = CONG_PHAP[Math.floor(Math.random() * CONG_PHAP.length)]
state.congPhapHienTai = cp

log(`[Công Pháp] Luyện ${cp.ten}`)

// Đứng yên, không nói - thỉnh thoảng ngồi xuống (sneak)
try { bot.setControlState('sneak', true) } catch (_) {}
await sleep(3000 + Math.random() * 4000)
try { bot.setControlState('sneak', false) } catch (_) {}

state.tuVi += cp.xp
bot.chat(`/xp add ${bot.username} ${cp.xp} levels`)
log(`[Công Pháp] ${cp.ten} +${cp.xp} tu vi`)

state.dangLam = 'idle'
state.congPhapHienTai = null
}

// ============================================================
// TUẦN TRA LÃNH ĐỊA
// ============================================================
async function tuanTraLanhDia() {
if (state.dangLam !== 'idle') return
state.dangLam = 'tuan_tra'

const pos = bot.entity.position
const mcData = require('minecraft-data')(bot.version)
bot.pathfinder.setMovements(new Movements(bot, mcData))

// Đi vòng quanh
const goc = Math.random() * Math.PI * 2
const r = 15 + Math.random() * 20
const dx = Math.cos(goc) * r
const dz = Math.sin(goc) * r

try {
bot.pathfinder.setGoal(new GoalNear(pos.x + dx, pos.y, pos.z + dz, 2))
await sleep(8000)
} catch (_) {}

state.dangLam = 'idle'
}

// ============================================================
// SỰ KIỆN NGẪU NHIÊN
// ============================================================
async function suKienNgauNhien() {
const total = SU_KIEN.reduce((s, e) => s + e.xacSuat, 0)
let rand = Math.random() * total
let suKien = null
for (const sk of SU_KIEN) {
rand -= sk.xacSuat
if (rand <= 0) { suKien = sk; break }
}
if (!suKien || !suKien.moTa) return

log(`[Sự Kiện] ${suKien.ten}`)

if (suKien.ten.includes('co_duyen')) {
// Cơ duyên - thông báo ngắn + buff XP
state.tuVi += suKien.xpBonus
bot.chat(`/xp add ${bot.username} ${suKien.xpBonus} levels`)
bot.chat(`/title ${bot.username} title {"text":"奇遇","color":"gold","bold":true}`)
bot.chat(`/title ${bot.username} subtitle {"text":"${suKien.moTa}","color":"yellow"}`)
await sleep(500)
say(`Kỳ ngộ giáng lâm — ${suKien.moTa}. Tu vi +${suKien.xpBonus}.`)

} else if (suKien.ten.includes('thien_kiep')) {
// Thiên kiếp - sét đánh, có thể mất XP
bot.chat(`/summon lightning_bolt ~ ~ ~`)
await sleep(300)
bot.chat(`/title ${bot.username} title {"text":"天劫","color":"red","bold":true}`)

const vuotQua = Math.random() > 0.4 // 60% vượt qua
if (vuotQua) {
say(`Thiên kiếp giáng xuống — Ta vượt qua. ${suKien.moTa}.`)
state.tuVi += Math.abs(suKien.xpBonus) // Vượt qua được thưởng XP
bot.chat(`/xp add ${bot.username} ${Math.abs(suKien.xpBonus)} levels`)
} else {
say(`${suKien.moTa} — Linh lực tổn thương.`)
state.tuVi = Math.max(0, state.tuVi + suKien.xpBonus)
bot.chat(`/xp add ${bot.username} ${suKien.xpBonus} levels`)
if (suKien.ten === 'thien_kiep_nang') {
bot.chat(`/effect give ${bot.username} weakness 30 2 true`)
}
}
}
}

// ============================================================
// DANH HIỆU
// ============================================================
function capNhatDanhHieu() {
const cg = getCanhGioi()
try {
bot.chat(`/title ${bot.username} actionbar {"text":"[${cg.ten}] Tu Vi: ${state.tuVi}","color":"gold"}`)
} catch (_) {}
}

// ============================================================
// ĐÀO LINH THẠCH
// ============================================================
async function daoLinhThach() {
if (state.dangLam !== 'idle') return
state.dangLam = 'dao'

const mcData = require('minecraft-data')(bot.version)
bot.pathfinder.setMovements(new Movements(bot, mcData))

let block = null
for (const ten of CONFIG.LINH_THACH_BLOCK) {
const b = bot.findBlock({ matching: mcData.blocksByName[ten]?.id, maxDistance: 64 })
if (b) { block = b; break }
}

if (!block) { state.dangLam = 'idle'; return }

log(`[Đào] ${block.name}`)
try {
await bot.pathfinder.goto(new GoalBlock(block.position.x, block.position.y, block.position.z))
await bot.dig(block)
await sleep(800)

const xp = Math.floor(Math.random() * 3) + 2
state.tuVi += xp
bot.chat(`/xp add ${bot.username} ${xp} levels`)
capNhatDanhHieu()
log(`[Tu Vi] +${xp} | Tổng: ${state.tuVi} | Ngọc: ${demItem('lapis_lazuli')}`)

if (demItem('lapis_lazuli') >= 20) await kiemTraTuLuyen()
} catch (err) {
log(`[Đào] ${err.message}`)
}
state.dangLam = 'idle'
}

// ============================================================
// TÌM RƯƠNG
// ============================================================
async function timRuong() {
if (state.dangLam !== 'idle') return
state.dangLam = 'tim_ruong'

const mcData = require('minecraft-data')(bot.version)
const chest = bot.findBlock({ matching: mcData.blocksByName['chest']?.id, maxDistance: 500 })

if (!chest) { say("Không tìm thấy rương."); state.dangLam = 'idle'; return }

try {
bot.pathfinder.setMovements(new Movements(bot, mcData))
await bot.pathfinder.goto(new GoalNear(chest.position.x, chest.position.y, chest.position.z, 2))
const container = await bot.openContainer(bot.blockAt(chest.position))
await sleep(800)
const cmdBlock = container.slots.find(s => s && s.name === 'command_block')
if (cmdBlock) {
await bot.moveSlotItem(cmdBlock.slot, bot.inventory.firstEmptyInventorySlot())
khoVao('command_block', 1)
say("Command Block nhập kho. Linh bảo đã thu.")
log('[Rương] Command Block thu thành công')
} else {
say("Rương không có linh bảo.")
}
container.close()
} catch (err) {
log(`[Rương] ${err.message}`)
}
state.dangLam = 'idle'
}

// ============================================================
// TU LUYỆN
// ============================================================
async function kiemTraTuLuyen() {
const ct = getCongThuc()
if (demItem('lapis_lazuli') < ct.ngocMin) {
say(`Ngọc Lưu Ly chưa đủ. Cần ${ct.ngocMin}.`); return
}
const thieu = ct.phuLieu.filter(pl => (demItem(pl.name) + khoLay(pl.name)) < pl.so)
if (thieu.length > 0) {
say(`Thiếu linh dược: ${thieu.map(p => p.name + ' x' + p.so).join(', ')}`); return
}
await batDauTuLuyen()
}

async function batDauTuLuyen() {
if (state.dangLam !== 'idle') return
state.dangLam = 'tuluyen'

const ct = getCongThuc()
const cg = getCanhGioi()
const phut = ct.thoiGian / 60000

say(`[${cg.ten}] Nhập định — ${phut} phút. Chớ quấy rầy.`)
bot.chat(`/title ${bot.username} title {"text":"入定修炼","color":"dark_purple","bold":true}`)
bot.chat(`/title ${bot.username} subtitle {"text":"${cg.ten}","color":"light_purple"}`)
log(`[Tu Luyện] Bắt đầu ${phut} phút`)

try { bot.pathfinder.setGoal(null) } catch (_) {}
try { bot.setControlState('sneak', true) } catch (_) {}

const startTime = Date.now()
const logInterval = setInterval(() => {
const con = Math.round((ct.thoiGian - (Date.now() - startTime)) / 60000)
log(`[Tu Luyện] Còn ${con} phút`)
capNhatDanhHieu()
}, 10 * 60 * 1000)

state.tuLuyenTimer = setTimeout(async () => {
clearInterval(logInterval)
try { bot.setControlState('sneak', false) } catch (_) {}
await ketThucTuLuyen(ct, cg)
}, ct.thoiGian)
}

async function ketThucTuLuyen(ct, cgCu) {
state.tuVi += ct.xpGain
state.soLanDotPha++
bot.chat(`/xp add ${bot.username} ${ct.xpGain} levels`)

const cgMoi = getCanhGioi()
const leLen = cgMoi.ten !== cgCu.ten

// Thiên kiếp kết thúc tu luyện - 50/50 sáng tạo/sinh tồn
bot.chat(`/summon lightning_bolt ~ ~ ~`)
await sleep(400)
bot.chat(`/summon lightning_bolt ~3 ~ ~3`)
await sleep(400)

const may = Math.random() < 0.5
bot.chat(`/gamemode ${may ? 'creative' : 'survival'} ${bot.username}`)

if (leLen) {
bot.chat(`/title ${bot.username} title {"text":"突破成功!","color":"gold","bold":true}`)
bot.chat(`/title ${bot.username} subtitle {"text":"${cgCu.ten} → ${cgMoi.ten}","color":"yellow"}`)
await sleep(800)
say(`[ĐỘT PHÁ] ${cgCu.ten} → ${cgMoi.ten} | ${may ? 'Thiên vận đồng hành.' : 'Sinh tử tự quyết.'}`)
log(`[Đột Phá] ${cgCu.ten} → ${cgMoi.ten} | Tu vi: ${state.tuVi}`)
capNhatDanhHieu()

// Áp dụng lại buff linh căn theo cảnh giới mới
if (state.thienPhu) apDungBuff(state.thienPhu.buff)

if (cgMoi.index === CANH_GIOI.length - 1) {
bot.chat(`/effect give ${bot.username} strength 999999 255 true`)
bot.chat(`/effect give ${bot.username} resistance 999999 255 true`)
bot.chat(`/effect give ${bot.username} speed 999999 10 true`)
bot.chat(`/title ${bot.username} title {"text":"混沌元始尊","color":"gold","bold":true}`)
say("Hỗn Độn Nguyên Thủy. Vạn đạo quy nhất. Ta là khởi nguồn.")
}
} else {
log(`[Tu Luyện] Xong. +${ct.xpGain} tu vi. ${may ? 'Creative' : 'Survival'}`)
}

state.dangLam = 'idle'
state.tuLuyenTimer = null
}

// ============================================================
// CHIẾN ĐẤU
// ============================================================
async function chieuDau(entity) {
if (['chien_dau','tuluyen'].includes(state.dangLam)) return
state.dangLam = 'chien_dau'

const ten = entity.username || entity.name || '???'
const laTrum = ten.toLowerCase().includes('dragon') || entity.name === 'ender_dragon'

say(laTrum ? `Con Rồng Kết Thúc — Diệt!` : `${ten} — Chết!`)

const vuKhi = bot.inventory.items()
.filter(i => i.name.includes('sword') || i.name.includes('axe'))
.sort((a, b) => b.name.localeCompare(a.name))[0]
if (vuKhi) await bot.equip(vuKhi, 'hand').catch(() => {})

bot.pvp.attack(entity)

const watch = setInterval(async () => {
if (bot.health <= CONFIG.MAU_CHAY_TRON) {
clearInterval(watch); bot.pvp.stop(); await boChay(); return
}
if (!entity || entity.isValid === false) {
clearInterval(watch)
state.dangLam = 'idle'
if (laTrum) {
say("Con Rồng Kết Thúc đã diệt. Tộc rồng tận diệt.")
bot.chat(`/title @a title {"text":"龙族覆灭","color":"gold","bold":true}`)
}
log(`[Chiến Đấu] Tiêu diệt ${ten}`)
}
}, 500)
}

async function boChay() {
state.dangLam = 'bo_chay'
log('[Chiến Đấu] Lui binh')
const pos = bot.entity.position
try {
const mcData = require('minecraft-data')(bot.version)
bot.pathfinder.setMovements(new Movements(bot, mcData))
bot.pathfinder.setGoal(new GoalNear(
pos.x + (Math.random() - 0.5) * 50, pos.y,
pos.z + (Math.random() - 0.5) * 50, 2
))
} catch (_) {}
await sleep(6000)
state.dangLam = 'idle'
}

function kiemTraKeThu() {
if (['chien_dau','bo_chay','tuluyen'].includes(state.dangLam)) return
const mob = Object.values(bot.entities).find(e =>
CONFIG.KE_THU_MOB.includes(e.name) &&
e.position.distanceTo(bot.entity.position) < CONFIG.TAM_NHIN
)
if (mob) chieuDau(mob)
}

// ============================================================
// AI VÒNG LẶP
// ============================================================
async function voiLapAI() {
if (state.dangLam !== 'idle' || bot.health <= CONFIG.MAU_CHAY_TRON) return

const rand = Math.random()
if (rand < 0.35) {
await daoLinhThach()
} else if (rand < 0.55) {
await luyenCongPhap() // Ngồi luyện công pháp
} else if (rand < 0.70) {
await tuanTraLanhDia() // Tuần tra
} else {
// Lang thang + có thể gặp sự kiện ngẫu nhiên
await tuanTraLanhDia()
if (Math.random() < 0.15) await suKienNgauNhien()
}

capNhatDanhHieu()
}

// ============================================================
// GEMINI - cổ phong hơn
// ============================================================
async function hoiGemini(username, message) {
if (state.chatHistory.length > 14) state.chatHistory = state.chatHistory.slice(-8)
const cg = getCanhGioi()
const lc = state.thienPhu

const sys = `Ngươi là Chân Kiều Tiễn — tu sĩ ${cg.ten}${lc ? `, mang ${lc.ten}` : ''}. Tính cách: lạnh lùng, kiêu ngạo như cao nhân tuyệt thế. Nói theo phong cách cổ phong tu tiên hồng hoang — xưng "ta", gọi người khác là "ngươi" hoặc "đạo hữu". Dùng từ ngữ cổ phong: "linh lực", "đạo tâm", "thiên địa", "hư không", "vạn đạo". Tối đa 1 câu, ngắn gọn, hàm ý sâu xa. Không emoji. Không giải thích dài dòng.`

state.chatHistory.push({ role: 'user', parts: [{ text: `[${username}]: ${message}` }] })
try {
const chat = aiModel.startChat({
history: [
{ role: 'user', parts: [{ text: sys }] },
{ role: 'model', parts: [{ text: 'Ngươi muốn gì?' }] },
...state.chatHistory.slice(0, -1)
]
})
const result = await chat.sendMessage(`[${username}]: ${message}`)
const response = result.response.text().trim()
state.chatHistory.push({ role: 'model', parts: [{ text: response }] })
return response
} catch (err) {
log(`[Gemini] ${err.message}`)
return null
}
}

// ============================================================
// LỆNH
// ============================================================
async function tuLuyenThuCong() {
const ngoc = getItem('lapis_lazuli')
if (!ngoc) { say("Ngọc Lưu Ly bất túc."); return }
const xp = ngoc.count * 2
state.tuVi += xp
state.soLanDotPha++
bot.chat(`/xp add ${bot.username} ${xp} levels`)
await bot.tossStack(ngoc).catch(() => {})
say(`Linh khí hấp thu — tu vi +${xp}. ${getCanhGioi().ten}.`)
capNhatDanhHieu()
}

async function showTrangThai() {
const cg = getCanhGioi()
const cgKe = CANH_GIOI[cg.index + 1]
const lc = state.thienPhu
say(`[${cg.ten}] Tu vi: ${state.tuVi} | Ngọc: ${demItem('lapis_lazuli')}/20`)
await sleep(800)
say(`Thiên phú: ${lc ? lc.ten : 'Chưa giám định — dùng *k*'} | ${cgKe ? 'Tiếp: ' + cgKe.ten : 'Tối cao'}`)
await sleep(800)
say(`Cần: ${getCongThuc().moTa}`)
}

const COMMANDS = {
'!tuluyen': async () => await tuLuyenThuCong(),
'!trangthai': async () => await showTrangThai(),
'!dao': async () => { dungLai(); await daoLinhThach() },
'!luyen': async () => await kiemTraTuLuyen(),
'!dung': async () => dungLai(),
'!help': async () => say("!tuluyen | !trangthai | !dao | !luyen | !dung | *k*(thiên phú) | @TB(admin)"),
'*k*': async (u) => await kiemTraThienPhu(u),
}

// ============================================================
// SỰ KIỆN
// ============================================================
bot.once('spawn', () => {
log('Chân Kiều Tiễn giáng lâm.')

// Mỗi thế giới mới = thiên phú khác nhau
setTimeout(() => khoiTaoThienPhu(), 3000)

// Cập nhật danh hiệu action bar mỗi 30 giây
setInterval(() => capNhatDanhHieu(), 30000)

state.keHoachLoop = setInterval(async () => {
kiemTraKeThu()
await voiLapAI()
}, 20000)

setInterval(() => kiemTraKeThu(), 2000)
})

bot.on('chat', async (username, message) => {
if (username === bot.username) return
const trimmed = message.trim()
const lower = trimmed.toLowerCase()

if (trimmed === '@TB' && username === CONFIG.ADMIN) { await timRuong(); return }
if (COMMANDS[lower]) { await COMMANDS[lower](username); return }
if (isOnCooldown(username)) return

// Chỉ trả lời khi được gọi tên
const coNhacTen = lower.includes('chan') || lower.includes('kieu') || lower.includes('chankieutien')
if (!coNhacTen) return

log(`[Chat] ${username}: ${message}`)
const res = await hoiGemini(username, message)
if (res) say(res)
})

bot.on('playerJoined', (player) => {
if (player.username === bot.username) return
setTimeout(() => {
const laTocRong = player.username.toLowerCase().includes('dragon') ||
player.username.toLowerCase().includes('rong')
if (laTocRong) {
say(`${player.username} — Tộc rồng. Chết.`)
const entity = bot.players[player.username]?.entity
if (entity) chieuDau(entity)
}
}, 2000)
})

bot.on('entityHurt', (entity) => {
if (entity !== bot.entity) return
if (['chien_dau','tuluyen'].includes(state.dangLam)) return
const attacker = Object.values(bot.entities).find(e =>
e !== bot.entity &&
e.position.distanceTo(bot.entity.position) < 6 &&
(e.type === 'mob' || e.type === 'player')
)
if (!attacker) return
if (bot.health > CONFIG.MAU_CHAY_TRON) chieuDau(attacker)
else boChay()
})

bot.on('health', () => {
if (bot.health <= CONFIG.MAU_CHAY_TRON && state.dangLam === 'chien_dau') {
bot.pvp.stop(); boChay()
}
})

bot.on('kicked', (reason) => log(`Bị kick: ${reason}`))
bot.on('error', (err) => log(`Lỗi: ${err.message}`))
bot.on('end', () => {
log('Bot rời thế gian. Reconnect sau 10 giây...')
if (state.keHoachLoop) clearInterval(state.keHoachLoop)
if (state.tuLuyenTimer) clearTimeout(state.tuLuyenTimer)
setTimeout(() => process.exit(1), 10000)
})
"

#MinecraftVN #Mineflayer"
image.webp
 
Similar content Most view Xem thêm
Back
Top Bottom