Skip to content

How can you get the entire description of an item? #1517

Answered by TheDudeFromCI
ghost asked this question in Q&A
Discussion options

You must be logged in to vote

@goncharovchik

function getLore(item) {
  let message = ''
  if (item.nbt == null) return message

  const nbt = require('prismarine-nbt')
  const ChatMessage = require('prismarine-chat')(bot.version)

  const data = nbt.simplify(item.nbt)
  const display = data['display']
  if (display == null) return message

  const lore = display['Lore']
  if (lore == null) return message

  for (const line of lore) {
    for (const group of JSON.parse(line)) {
      message += new ChatMessage(group).toString()
      message += '\n'
      }
  }

  return message
}

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by rom1504
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant
Converted from issue

This discussion was converted from issue #1517 on December 22, 2020 15:17.