[精讚] [會員登入]
148

Mineflayer測試

1.BOT尋路 const mineflayer = require('mineflayer'); co

分享此文連結 //n.sfs.tw/16431

分享連結 Mineflayer測試@大塚 宏 ~認真玩・輕鬆學~
(文章歡迎轉載,務必尊重版權註明連結來源)
最後編修
2024-06-25 10:07:08 By 大塚 宏
 

 1.BOT尋路

const mineflayer = require('mineflayer');
const { pathfinder, Movements, goals } = require('mineflayer-pathfinder');

// 創建一個 Mineflayer 客戶端
const bot = mineflayer.createBot({
  host: 'your.minecraft.server',  // Minecraft 伺服器地址
  username: 'your_bot_username'    // 你的機器人的使用者名稱
});

// 設置機器人使用路徑規劃和移動
bot.loadPlugin(pathfinder);
bot.once('spawn', () => {
  const mcData = require('minecraft-data')(bot.version);
  const movements = new Movements(bot, mcData);
  movements.scafoldingBlocks = []; // 可選:設置機器人建造時使用的方塊

  bot.on('path_update', (r) => {
    if (r.status === 'noPath') {
      bot.chat('無法到達目的地!');
    } else if (r.status === 'complete') {
      bot.chat('已到達目的地!');
    }
  });

  bot.on('chat', (username, message) => {
    if (username === bot.username) return;
    if (message === 'come') {
      const player = bot.players[username];
      if (!player) {
        bot.chat("我找不到你,我不知道要去哪裡。");
        return;
      }
      const pos = player.entity.position.offset(1, 0, 1);
      const goal = new goals.GoalBlock(pos.x, pos.y, pos.z);
      bot.pathfinder.setGoal(goal);
      bot.chat(`我要來了,${username}!`);
    }
  });
});

// 監聽機器人的登入信息
bot.on('login', () => {
  console.log(`機器人 ${bot.username} 登入了!`);
});

 

2.BOT瞬移

const mineflayer = require('mineflayer');

// 創建一個 Mineflayer 客戶端
const bot = mineflayer.createBot({
  host: 'your.minecraft.server',  // Minecraft 伺服器地址
  username: 'your_bot_username'    // 你的機器人的使用者名稱
});

// 監聽機器人的登入信息
bot.on('login', () => {
  console.log(`機器人 ${bot.username} 登入了!`);

  // 瞬間移動到指定座標 (x, y, z)
  teleportTo(100, 70, 200);
});

// 定義瞬間移動函式
function teleportTo(x, y, z) {
  bot.teleport({
    x: x,
    y: y,
    z: z
  }, () => {
    console.log(`已將機器人移動到座標 (${x}, ${y}, ${z})`);
  });
}

END

你可能感興趣的文章

文章上鎖(TEST)、文字複製(判斷iOS) 文章上鎖(TEST)

getCoinInfo(API測試) getCoinInfo

[jQuery] 一行搞定if判斷式 一行搞定if判斷式

Mineflayer測試 1.BOT尋路 const mineflayer = require('mineflayer'); co

[jQuery] 動態設定欄位是否啟用 $符號真的太萬用了~ 抓取元件變得輕鬆許多

[實用程式] 假文產生器 遇到一個設計表單的工作,需要一些隨機文字來填充欄位,測試排版是否整齊

我有話要說

>>

限制:留言最高字數1000字。 限制:未登入訪客,每則留言間隔需超過10分鐘,每日最多5則留言。

訪客留言

[無留言]

隨機好文

[寶可夢-劍盾] 級別對戰 單打隊伍分享 [S27] 全新規則登場,雙傳說組隊開放,隊伍組合更多樣化! 你的傳說隊伍組合是甚麼呢?

[對戰筆記] 2022年 3月 第四回 [連線對戰] 這次採用BO3、雙傳說的單打規則,真劍勝負!!

[C#] 加密圖片,透過Logistic混沌演算法 加密圖片,透過Logistic混沌演算法

[血洗幣圈] 5/11,一個晚上賠了19萬台幣 5/11,一個晚上賠了19萬台幣

動態文字框(TEST) 多邊文字框(TEST)