add support for 1.20.4 #3

Closed
opened 2024-02-26 12:25:07 -05:00 by Parker2991 · 4 comments
Owner

add support for 1.20.4 by parsing chat as nbt and not string which i cant figure out how to.
may break support for creayun some possible try to keep 1.20.2 chat as well idk ¯_(ツ)_/¯

add support for 1.20.4 by parsing chat as nbt and not string which i cant figure out how to. may break support for creayun some possible try to keep 1.20.2 chat as well idk ¯\_(ツ)_/¯
Parker2991 added the
Enhancement
label 2024-04-29 13:14:59 -04:00
Author
Owner

@chipmunkmc are you able to help with this please?

@chipmunkmc are you able to help with this please?
Author
Owner
const loadPrismarineChat = require('prismarine-chat')
const kaboomChatParser = require('../chat/kaboom')
const creayunChatParser = require('../chat/creayun')
const fs = require('fs')
const chipmunkmodChatParser = require('../chat/chipmunkmod')
const chipmunkmodblackilykatverChatParser = require('../chat/chipmunkmodBlackilyKatVer')
const typetextChatParser = require('../chat/chatTypeText')
const typeemotetextChatParser = require('../chat/chatTypeEmote')
const nbt = require('prismarine-nbt')
function tryParse (json) {
  try {
    return JSON.parse(json)
  } catch (error) {
    return { text: '' }
  }
}
//  const chat = require('prismarine-chat'); const nbt = require('prismarine-nbt'); chat.processNbtMessage(nbt.comp({ text: nbt.string('hi!') }))
function parseNbt (json) {
  try {
    return loadPrismarineChat.processNbtMessage(nbt.comp({text: nbt.string(json)}))
  } catch (error) {
    return { text: '' }
  }
}
//what was changed??
function inject (bot) {

       // const ChatMessage = require('prismarine-chat')
        
  bot.on('registry_ready', registry => {
    ChatMessage = loadPrismarineChat(registry)
  })
   
  bot.chatParsers = [kaboomChatParser, chipmunkmodChatParser, chipmunkmodblackilykatverChatParser, typetextChatParser, typeemotetextChatParser, creayunChatParser]

  bot.on('packet.profileless_chat', packet => {//loadPrismarineChat.processNbtMessage(nbt.comp(json))
    if (bot.options.version === '1.20.4' || bot.options.version === '1.20.3') {
      message = JSON.parse(loadPrismarineChat.processNbtMessage(nbt.comp(nbt.string(packet.message))))
      sender = JSON.parse(loadPrismarineChat.processNbtMessage(nbt.comp(nbt.string(packet.name))))

    } else if (bot.options.version === '1.20.2' || bot.options.version === '1.20.1' || bot.options.version === '1.20' || bot.options.version === '1.19.4' || bot.options.version === '1.19.3') {// for backward compactability
      message = tryParse(packet.message)
      sender = tryParse(packet.name)
    }
    bot.emit('profileless_chat', {
      message,
      type: packet.type,
      sender
    })

    bot.emit('message', message)

    tryParsingMessage(message, { senderName: sender, players: bot.players, getMessageAsPrismarine: bot.getMessageAsPrismarine })
  })
 // Ignores command set messages
//chat.type.text
//chat.type.announcement
//chat.type.emote
  //packet.chatType_
  bot.on('packet.player_chat', packet => {
    if (bot.options.version === '1.20.2' || bot.options.version === '1.20.1' || bot.options.version === '1.20' || bot.options.version === '1.19.4' || bot.options.version === '1.19.3') { // for backward compactability
      unsigned = tryParse(packet.unsignedChatContent)
    } else if (bot.options.version === '1.20.4' || bot.options.version === '1.20.3') {
      unsigned = JSON.parse(loadPrismarineChat.processNbtMessage(nbt.comp(nbt.string(packet.unsignedChatContent))))
    }
    bot.emit('player_chat', { plain: packet.plainMessage, unsigned, senderUuid: packet.senderUuid })
    
    bot.emit('message', unsigned)
  


    tryParsingMessage(unsigned, { senderUuid: packet.senderUuid, players: bot.players, getMessageAsPrismarine: bot.getMessageAsPrismarine})
  
    })
 bot.getMessageAsPrismarine = message => {
  try {
    if (ChatMessage !== undefined) {
      return new ChatMessage(message)
    }
  } catch (error) {
    console.error(error); // Log any errors that occur during object creation
  }
  return undefined;
}
       
  bot.on('packet.system_chat', packet => {
    const message = tryParse(packet.content)

    if (message.translate === 'advMode.setCommand.success') return // Ignores command set messages
   
    bot.emit('system_chat', { message, actionbar: packet.isActionBar })

    if (packet.isActionBar) {
      return
    }
    
    bot.emit('message', message)
   
    tryParsingMessage(message, { players: bot.players, getMessageAsPrismarine: bot.getMessageAsPrismarine })
  })
/*bot.on('message', async (chatMessage) => {
  if (typeof chatMessage.translate === 'string' && chatMessage.translate.startsWith('advMode.')) return
  console.log(chatMessage.toAnsi())
  */
       
  function tryParsingMessage (message, data) {
    let parsed
    for (const parser of bot.chatParsers) {
      parsed = parser(message, data)
      if (parsed) break
    }

    if (!parsed) return
    bot.emit('parsed_message', parsed)
  }

  bot.getMessageAsPrismarine = message => {
    try {
      if (ChatMessage !== undefined) {
        return new ChatMessage(message)
      }
    } catch {}
    
    return undefined
  }

  bot.chat = message => {
    const acc = 0
    const bitset = Buffer.allocUnsafe(3)
   
    bitset[0] = acc & 0xFF
    bitset[1] = (acc >> 8) & 0xFF
    bitset[2] = (acc >> 16) & 0xFF
      
    bot._client.write('chat_message', {
      message: message.substring(0, 256),
      timestamp: BigInt(Date.now()),      
      salt: 0n,
      offset: 0,
      acknowledged: bitset
      
    })

  }
    
  
  bot.command = command => {
    bot._client.write('chat_command', {
      command: command.substring(0, 256),
      timestamp: BigInt(Date.now()),
      salt: 0n,
      argumentSignatures: [],
      signedPreview: false,
      messageCount: 0,
      acknowledged: Buffer.alloc(3),
      previousMessages: []
    })
  }

  bot.tellraw = (message, selector = '@a') => bot.core.run('/minecraft:tellraw @a ' + JSON.stringify(message)) // ? Should this be here?
}
    
module.exports = inject

it parses it as json for now
i also got this output

{"value":{"extra":[{"extra":[{"bold":1,"color":"dark_red","text":"["},{"bold":1,"color":"red","text":"OP"},{"bold":1,"color":"dark_red","text":"] "},{"color":"red","text":""}],"text":""},{"extra":[{"color":"red","text":"Parker2991"}],"text":""},{"":":"},{"":" "},{"":"e"}],"text":""}

also 1 what?!

```js const loadPrismarineChat = require('prismarine-chat') const kaboomChatParser = require('../chat/kaboom') const creayunChatParser = require('../chat/creayun') const fs = require('fs') const chipmunkmodChatParser = require('../chat/chipmunkmod') const chipmunkmodblackilykatverChatParser = require('../chat/chipmunkmodBlackilyKatVer') const typetextChatParser = require('../chat/chatTypeText') const typeemotetextChatParser = require('../chat/chatTypeEmote') const nbt = require('prismarine-nbt') function tryParse (json) { try { return JSON.parse(json) } catch (error) { return { text: '' } } } // const chat = require('prismarine-chat'); const nbt = require('prismarine-nbt'); chat.processNbtMessage(nbt.comp({ text: nbt.string('hi!') })) function parseNbt (json) { try { return loadPrismarineChat.processNbtMessage(nbt.comp({text: nbt.string(json)})) } catch (error) { return { text: '' } } } //what was changed?? function inject (bot) { // const ChatMessage = require('prismarine-chat') bot.on('registry_ready', registry => { ChatMessage = loadPrismarineChat(registry) }) bot.chatParsers = [kaboomChatParser, chipmunkmodChatParser, chipmunkmodblackilykatverChatParser, typetextChatParser, typeemotetextChatParser, creayunChatParser] bot.on('packet.profileless_chat', packet => {//loadPrismarineChat.processNbtMessage(nbt.comp(json)) if (bot.options.version === '1.20.4' || bot.options.version === '1.20.3') { message = JSON.parse(loadPrismarineChat.processNbtMessage(nbt.comp(nbt.string(packet.message)))) sender = JSON.parse(loadPrismarineChat.processNbtMessage(nbt.comp(nbt.string(packet.name)))) } else if (bot.options.version === '1.20.2' || bot.options.version === '1.20.1' || bot.options.version === '1.20' || bot.options.version === '1.19.4' || bot.options.version === '1.19.3') {// for backward compactability message = tryParse(packet.message) sender = tryParse(packet.name) } bot.emit('profileless_chat', { message, type: packet.type, sender }) bot.emit('message', message) tryParsingMessage(message, { senderName: sender, players: bot.players, getMessageAsPrismarine: bot.getMessageAsPrismarine }) }) // Ignores command set messages //chat.type.text //chat.type.announcement //chat.type.emote //packet.chatType_ bot.on('packet.player_chat', packet => { if (bot.options.version === '1.20.2' || bot.options.version === '1.20.1' || bot.options.version === '1.20' || bot.options.version === '1.19.4' || bot.options.version === '1.19.3') { // for backward compactability unsigned = tryParse(packet.unsignedChatContent) } else if (bot.options.version === '1.20.4' || bot.options.version === '1.20.3') { unsigned = JSON.parse(loadPrismarineChat.processNbtMessage(nbt.comp(nbt.string(packet.unsignedChatContent)))) } bot.emit('player_chat', { plain: packet.plainMessage, unsigned, senderUuid: packet.senderUuid }) bot.emit('message', unsigned) tryParsingMessage(unsigned, { senderUuid: packet.senderUuid, players: bot.players, getMessageAsPrismarine: bot.getMessageAsPrismarine}) }) bot.getMessageAsPrismarine = message => { try { if (ChatMessage !== undefined) { return new ChatMessage(message) } } catch (error) { console.error(error); // Log any errors that occur during object creation } return undefined; } bot.on('packet.system_chat', packet => { const message = tryParse(packet.content) if (message.translate === 'advMode.setCommand.success') return // Ignores command set messages bot.emit('system_chat', { message, actionbar: packet.isActionBar }) if (packet.isActionBar) { return } bot.emit('message', message) tryParsingMessage(message, { players: bot.players, getMessageAsPrismarine: bot.getMessageAsPrismarine }) }) /*bot.on('message', async (chatMessage) => { if (typeof chatMessage.translate === 'string' && chatMessage.translate.startsWith('advMode.')) return console.log(chatMessage.toAnsi()) */ function tryParsingMessage (message, data) { let parsed for (const parser of bot.chatParsers) { parsed = parser(message, data) if (parsed) break } if (!parsed) return bot.emit('parsed_message', parsed) } bot.getMessageAsPrismarine = message => { try { if (ChatMessage !== undefined) { return new ChatMessage(message) } } catch {} return undefined } bot.chat = message => { const acc = 0 const bitset = Buffer.allocUnsafe(3) bitset[0] = acc & 0xFF bitset[1] = (acc >> 8) & 0xFF bitset[2] = (acc >> 16) & 0xFF bot._client.write('chat_message', { message: message.substring(0, 256), timestamp: BigInt(Date.now()), salt: 0n, offset: 0, acknowledged: bitset }) } bot.command = command => { bot._client.write('chat_command', { command: command.substring(0, 256), timestamp: BigInt(Date.now()), salt: 0n, argumentSignatures: [], signedPreview: false, messageCount: 0, acknowledged: Buffer.alloc(3), previousMessages: [] }) } bot.tellraw = (message, selector = '@a') => bot.core.run('/minecraft:tellraw @a ' + JSON.stringify(message)) // ? Should this be here? } module.exports = inject ``` it parses it as json for now i also got this output ```json {"value":{"extra":[{"extra":[{"bold":1,"color":"dark_red","text":"["},{"bold":1,"color":"red","text":"OP"},{"bold":1,"color":"dark_red","text":"] "},{"color":"red","text":""}],"text":""},{"extra":[{"color":"red","text":"Parker2991"}],"text":""},{"":":"},{"":" "},{"":"e"}],"text":""} ``` also 1 what?!
Collaborator

@chipmunkmc are you able to help with this please?

soon™️

> @chipmunkmc are you able to help with this please? > soon:tm:
Parker2991 added the
Status
Abandoned
label 2024-08-17 02:52:30 -04:00
Author
Owner

prismarine nbt fucky cant support versions new than 1.20.2 for right now

prismarine nbt fucky cant support versions new than 1.20.2 for right now
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: Parker2991/FridayNightFunkinBoyfriendBot#3
No description provided.