PrismarineJS / mineflayer

Create Minecraft bots with a powerful, stable, and high level JavaScript API.
https://prismarinejs.github.io/mineflayer/
MIT License
4.99k stars 910 forks source link

particle event not working, 1.12.2 #2864

Open ShiniPantz opened 1 year ago

ShiniPantz commented 1 year ago

Versions

Detailed description of a problem

The bot straight up ignores particles. I also have no idea how to get access to Particle instances, when the particle event doesn't even give me the particle Instance according to the api. But it doesn't even work at all.

What did you try yet?

My bot is standing next to an enchantment table with bookshelfs, doesn't detect the etable particles. I also tried water, bubbles, potion effects, villager trade reset particles, the bot just ignores them. Every other event, like "chat", does work.

Your current code

  bot.on("particle",(pinstance)=>{
    console.log(pinstance)
    console.log("test")
  })

does not work, as well as

  bot.on("particle",()=>{
    console.log("test")
  })

Expected behavior

I expect the message

test

to appear in my terminal. Like rapid fire "test" messages, considering the amount of particles there are. If possible, I would also like to put the particle instance into the pinstance variable, to be able to further inspect the particles.

Additional context

I tried asking in the mineflayer discord, they told me to open an issue on github.

ShiniPantz commented 1 year ago

Full code

const mineflayer = require('mineflayer')
const readline = require('readline')
const nbt = require('prismarine-nbt')
const { syncBuiltinESMExports } = require('module')
const exist=()=>{
   const bot = mineflayer.createBot ({
      host:process.argv[3],
      port:parseInt(process.argv[5]),
      version: "1.12.2",
      auth:process.argv[4],
      username:process.argv[2]
      //password:
   })
   return bot
}

const login=()=>{
  console.log("b")
  const bot=exist()
  bot.once("spawn",()=>{
    console.log("beep boob")
    readLineFromTerminal()
  })
  bot.on("particle",(krümel)=>{
    console.log(krümel)
    console.log("test")
  })
  bot.on("chat",()=>{
    console.log("test")
  })

  const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
  });
  function readLineFromTerminal(){
    rl.question("",function (text){
      bot.chat(text)
      console.log(eval(text))
      readLineFromTerminal()
    })
  }
  let id = 1
  let brick = false
  async function trade(id) {
    const Olaf = bot.nearestEntity(entity => entity.metadata[2] == "Olaf") //declare Olaf as nearest Villager with nametag "Olaf"
    const OlafMenu = await bot.openVillager(Olaf)
    console.log(OlafMenu.trades[id])
    if (!brick) {
       if (OlafMenu.trades[id].tradeDisabled) {
          console.log("bricked Villager")
          brick = true
          OlafMenu.close()
       }
       else {
          amount = OlafMenu.maximumNbTradeUses - OlafMenu.nbTradeUses
          await bot.trade(OlafMenu,id,amount)
          setTimeout(OlafMenu.close,1000)
       }
     }
   }

  const loggecr = (name,text)=> {
    if (name==="whispers"){}
    else {
      console.log("<"+name+"> "+text) 
    }
  }
  const loggecw = (name,text)=> {
    console.log("<"+name+"> whispers "+text) 
  }
  bot.on("chat",loggecr)
  bot.on("whisper",loggecw)

  function kickf (info,info2) {
    console.log(info)
    console.log(info2)
    bot.end()
    setTimeout(login, 60000)
  }
  bot.on("kicked",kickf)
  bot.on("error",kickf)
}

login()

In case I fucked up something obvious

ShiniPantz commented 1 year ago

So it seems like the 4.5.1 version of mineflayer from npm is "outdated", and the 4.5.1 version on github is up to date. And apparently the npm version doesn't have the particle code yet. Kinda weird to me that there are 2 versions of 4.5.1 out there, I always thought the point of version numbers is to know which version is outdated, and which one is up to date, in a way where one can always go back to older versions with the old version number. But seems like the newest version gets constantly overwritten. I guess that's just how it it.

So maybe someone may somehow update the npm version of mineflayer?

ShiniPantz commented 1 year ago

So I tried listening to bot._client.on("world_particle".. I also tried manually updating mineflayer to include the particle stuff. Both approaches didn't work sadly.

Zn10plays commented 1 year ago

Is this still an issue?

ShiniPantz commented 1 year ago

yes, I updated mineflayer, to 4.8.0 using npm, nothing changed. I tested with water bubbles and happy villager particles, for both bot.on("particle" and bot._client.on("world_particle"

ShiniPantz commented 1 year ago

I wanna note that the particle documentation in https://mineflayer.prismarine.js.org/#/api is either incomplete or false