mineflayer icon indicating copy to clipboard operation
mineflayer copied to clipboard

Trader.js example doesnt work

Open Shiiiwa opened this issue 3 years ago • 3 comments

  • [X] The FAQ doesn't contain a resolution to my issue

Versions

  • mineflayer: 4.3.0
  • server: vanilla/spigot/paper 1.8.8
  • node: 16.0.0

Detailed description of a problem

I used the trader.js example from github mineflayer, to write all trades of a Villager into the chat. Atfer finding a Villager, the bot only prints the following lines:

1: (undefined/undefined) nothing >> undefined / undefined 2: (undefined/undefined) nothing >> undefined / undefined

What did you try yet?

I used the exact same method sayTrades(), stringifyTrades(), stringifyItem() from the example.

Your current code


const e = bot.entities[id]
  switch (true) {
    case !e:
      bot.chat("There are no Villagers")
      break
    case e.entityType !== mcData.entitiesByName["Villager"].id:
      bot.chat("entity is not a villager")
      break
    case bot.entity.position.distanceTo(e.position) > 3:
      bot.chat("villager out of reach")
      break
    default: {
      const villager = await bot.openVillager(e);
      
     villager.close()
     stringifyTrades(villager.trades).forEach((trade, i) => {
         bot.chat(`${i + 1}: ${trade}`)
     })  
    }
  }
// stringifyTrades() is the same as in the example on github

Expected behavior

Print all possible trades

Additional context

I realized after logging villager.trades(), that it only returns some empty Item - objects.

[
  {
    inputItem1: Item {}, // empty
    outputItem: Item {}, // empty
    hasItem2: false,
    inputItem2: null,
    tradeDisabled: true,
    nbTradeUses: -2080309248,
    maximumNbTradeUses: 0,
    realPrice: undefined
  }
]

Shiiiwa avatar Aug 11 '22 14:08 Shiiiwa

What if you log the trades before closing the villager?

amoraschi avatar Aug 11 '22 15:08 amoraschi

What if you log the trades before closing the villager?

Exactly the same as before. InputItem1 and outputItem contains only an empty Item object.

Shiiiwa avatar Aug 11 '22 23:08 Shiiiwa

"server: vanilla/spigot/paper 1.8.8" which is it ?

rom1504 avatar Aug 30 '22 07:08 rom1504

After poking around, it seems that the stringifyTrades is the culprit. The items in the villager object are being stored fine, as shown by these logs: image The second run I just logged the first trade's first input and the item showed up fine.

drakemj avatar Nov 02 '22 21:11 drakemj

Yeah, it looks like the names referring to the trades are wrong. It seems like at some point these variable names were changed or something similar, and this example was simply left unupdated.

drakemj avatar Nov 02 '22 21:11 drakemj