PrismarineJS / node-minecraft-protocol

Parse and serialize minecraft packets, plus authentication and encryption.
https://prismarinejs.github.io/node-minecraft-protocol/
BSD 3-Clause "New" or "Revised" License
1.23k stars 239 forks source link

version 1.8.8 on a server has mcData.loginPacket return undefiend in default usage example #890

Closed ghost closed 2 years ago

ghost commented 3 years ago

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

Versions

Detailed description of a problem

A clear and concise description of what the problem is.

Current code

const mc = require('minecraft-protocol')
const Chunk = require('prismarine-chunk')('1.8.8')
const Vec3 = require('vec3')
const server = mc.createServer({
  'online-mode': true,
  encryption: true,
  host: '0.0.0.0',
  port: 1012,
  version: '1.8.8'
})
const mcData = require('minecraft-data')(server.version)
const loginPacket = mcData.loginPacket
const chunk = new Chunk()

console.log(loginPacket)

for (let x = 0; x < 16; x++) {
  for (let z = 0; z < 16; z++) {
    chunk.setBlockType(new Vec3(x, 100, z), mcData.blocksByName.grass_block.id)
    chunk.setBlockData(new Vec3(x, 100, z), 1)
    for (let y = 0; y < 256; y++) {
      chunk.setSkyLight(new Vec3(x, y, z), 15)
    }
  }
}

server.on('login', function (client) {
  client.write('login', {
    entityId: client.id,
    isHardcore: false,
    gameMode: 0,
    previousGameMode: 255,
    worldNames: loginPacket.worldNames,
    dimensionCodec: loginPacket.dimensionCodec,
    dimension: loginPacket.dimension,
    worldName: 'minecraft:overworld',
    hashedSeed: [0, 0],
    maxPlayers: server.maxPlayers,
    viewDistance: 10,
    reducedDebugInfo: false,
    enableRespawnScreen: true,
    isDebug: false,
    isFlat: false
  })
  client.write('map_chunk', {
    x: 0,
    z: 0,
    groundUp: true,
    biomes: chunk.dumpBiomes !== undefined ? chunk.dumpBiomes() : undefined,
    heightmaps: {
      type: 'compound',
      name: '',
      value: {} // Client will accept fake heightmap
    },
    bitMap: chunk.getMask(),
    chunkData: chunk.dump(),
    blockEntities: []
  })
  client.write('position', {
    x: 15,
    y: 101,
    z: 15,
    yaw: 137,
    pitch: 0,
    flags: 0x00
  })
})

Expected behavior

A clear and concise description of what you expected to happen. loginPackets not to be undefiened

Additional context

Add any other context about the problem here.

u9g commented 3 years ago

the examples are only expected to work for the latest version of mc, you can try seeing when 1.9 came out and find the last commit before that and use that code.

nickelpro commented 3 years ago

1.8 doesn't have a loginPacket json, because 1.8 doesn't support any of the fields the loginPacket json is necessary for. Your login packet is structured incorrectly for 1.8, missing levelType and difficulty and including many fields that don't exist.

NMP is not a protocol-agnostic framework like mineflayer or flying-squid, you must understand the protocol and the packets you're writing. Not a bug, recommend closing.

rom1504 commented 3 years ago

https://github.com/PrismarineJS/flying-squid/blob/debb5fa6b800babfb62d29384a90e420522092ce/src/lib/plugins/login.js#L85 is how to send login whatever the version