Trader.js example doesnt work
- [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
}
]
What if you log the trades before closing the villager?
What if you log the trades before closing the villager?
Exactly the same as before. InputItem1 and outputItem contains only an empty Item object.
"server: vanilla/spigot/paper 1.8.8" which is it ?
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:
The second run I just logged the first trade's first input and the item showed up fine.
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.