fix clientbound usage of chat and login for 1.16

This commit is contained in:
Romain Beaumont 2020-06-23 16:52:18 +02:00
parent d3a6a266f6
commit 2da46e1f35
No known key found for this signature in database
GPG key ID: DB60E388B3BCF286
7 changed files with 372 additions and 16 deletions

View file

@ -88,13 +88,72 @@ var server = mc.createServer({
encryption: true, // optional
host: '0.0.0.0', // optional
port: 25565, // optional
version: '1.16-rc1'
});
server.on('login', function(client) {
const w = {
piglin_safe: {
type: 'byte',
value: 0
},
natural: {
type: 'byte',
value: 1
},
ambient_light: {
type: 'float',
value: 0
},
infiniburn: {
type: 'string',
value: 'minecraft:infiniburn_overworld'
},
respawn_anchor_works: {
type: 'byte',
value: 0
},
has_skylight: {
type: 'byte',
value: 1
},
bed_works: {
type: 'byte',
value: 1
},
has_raids: {
type: 'byte',
value: 1
},
name: {
type: 'string',
value: 'minecraft:overworld'
},
logical_height: {
type: 'int',
value: 256
},
shrunk: {
type: 'byte',
value: 0
},
ultrawarm: {
type: 'byte',
value: 0
},
has_ceiling: {
type: 'byte',
value: 0
}
}
client.write('login', {
entityId: client.id,
levelType: 'default',
gameMode: 0,
dimension: 0,
previousGameMode: 255,
worldNames: ['minecraft:overworld'],
dimensionCodec: {name: '', type:'compound', value: {dimension: {type: 'list', value: {type: 'compound', value: [w]}}}},
dimension: 'minecraft:overworld',
worldName: 'minecraft:overworld',
difficulty: 2,
hashedSeed: [0, 0],
maxPlayers: server.maxPlayers,
@ -116,7 +175,7 @@ server.on('login', function(client) {
'Hello, world!'
]
};
client.write("chat", { message: JSON.stringify(msg), position: 0 });
client.write("chat", { message: JSON.stringify(msg), position: 0, sender: '0' });
});
```

View file

@ -73,7 +73,8 @@ function broadcast (message, exclude, username) {
}
client.write('chat', {
message: JSON.stringify(msg),
position: 0
position: 0,
sender: '0'
})
}
}

View file

@ -5,17 +5,75 @@ const server = mc.createServer({
encryption: false, // optional
host: '0.0.0.0', // optional
port: 25565, // optional
version: '1.10'
version: '1.16-rc1'
})
server.on('login', function (client) {
client.registerChannel('MC|Brand', ['string', []])
client.on('MC|Brand', console.log)
const w = {
piglin_safe: {
type: 'byte',
value: 0
},
natural: {
type: 'byte',
value: 1
},
ambient_light: {
type: 'float',
value: 0
},
infiniburn: {
type: 'string',
value: 'minecraft:infiniburn_overworld'
},
respawn_anchor_works: {
type: 'byte',
value: 0
},
has_skylight: {
type: 'byte',
value: 1
},
bed_works: {
type: 'byte',
value: 1
},
has_raids: {
type: 'byte',
value: 1
},
name: {
type: 'string',
value: 'minecraft:overworld'
},
logical_height: {
type: 'int',
value: 256
},
shrunk: {
type: 'byte',
value: 0
},
ultrawarm: {
type: 'byte',
value: 0
},
has_ceiling: {
type: 'byte',
value: 0
}
}
client.write('login', {
entityId: client.id,
levelType: 'default',
gameMode: 0,
dimension: 0,
previousGameMode: 255,
worldNames: ['minecraft:overworld'],
dimensionCodec: { name: '', type: 'compound', value: { dimension: { type: 'list', value: { type: 'compound', value: [{ name: w }] } } } },
dimension: 'minecraft:overworld',
worldName: 'minecraft:overworld',
difficulty: 2,
maxPlayers: server.maxPlayers,
reducedDebugInfo: false,

View file

@ -5,15 +5,73 @@ const server = mc.createServer({
encryption: false, // optional
host: '0.0.0.0', // optional
port: 25565, // optional
version: '1.10'
version: '1.16-rc1'
})
server.on('login', function (client) {
const w = {
piglin_safe: {
type: 'byte',
value: 0
},
natural: {
type: 'byte',
value: 1
},
ambient_light: {
type: 'float',
value: 0
},
infiniburn: {
type: 'string',
value: 'minecraft:infiniburn_overworld'
},
respawn_anchor_works: {
type: 'byte',
value: 0
},
has_skylight: {
type: 'byte',
value: 1
},
bed_works: {
type: 'byte',
value: 1
},
has_raids: {
type: 'byte',
value: 1
},
name: {
type: 'string',
value: 'minecraft:overworld'
},
logical_height: {
type: 'int',
value: 256
},
shrunk: {
type: 'byte',
value: 0
},
ultrawarm: {
type: 'byte',
value: 0
},
has_ceiling: {
type: 'byte',
value: 0
}
}
client.write('login', {
entityId: client.id,
levelType: 'default',
gameMode: 0,
dimension: 0,
previousGameMode: 255,
worldNames: ['minecraft:overworld'],
dimensionCodec: { name: '', type: 'compound', value: { dimension: { type: 'list', value: { type: 'compound', value: [w] } } } },
dimension: 'minecraft:overworld',
worldName: 'minecraft:overworld',
difficulty: 2,
maxPlayers: server.maxPlayers,
reducedDebugInfo: false,

View file

@ -1,7 +1,8 @@
const mc = require('minecraft-protocol')
const options = {
'online-mode': true
'online-mode': true,
version: '1.16-rc1'
}
const server = mc.createServer(options)
@ -18,12 +19,71 @@ server.on('login', function (client) {
console.log('Error:', error)
})
const w = {
piglin_safe: {
type: 'byte',
value: 0
},
natural: {
type: 'byte',
value: 1
},
ambient_light: {
type: 'float',
value: 0
},
infiniburn: {
type: 'string',
value: 'minecraft:infiniburn_overworld'
},
respawn_anchor_works: {
type: 'byte',
value: 0
},
has_skylight: {
type: 'byte',
value: 1
},
bed_works: {
type: 'byte',
value: 1
},
has_raids: {
type: 'byte',
value: 1
},
name: {
type: 'string',
value: 'minecraft:overworld'
},
logical_height: {
type: 'int',
value: 256
},
shrunk: {
type: 'byte',
value: 0
},
ultrawarm: {
type: 'byte',
value: 0
},
has_ceiling: {
type: 'byte',
value: 0
}
}
// send init data so client will start rendering world
client.write('login', {
entityId: client.id,
levelType: 'default',
gameMode: 0,
dimension: 0,
previousGameMode: 255,
worldNames: ['minecraft:overworld'],
dimensionCodec: { name: '', type: 'compound', value: { dimension: { type: 'list', value: { type: 'compound', value: [w] } } } },
dimension: 'minecraft:overworld',
worldName: 'minecraft:overworld',
difficulty: 2,
maxPlayers: server.maxPlayers,
reducedDebugInfo: false,
@ -47,7 +107,7 @@ server.on('login', function (client) {
'Hello, world!'
]
}
client.write('chat', { message: JSON.stringify(msg), position: 0 })
client.write('chat', { message: JSON.stringify(msg), position: 0, sender: '0' })
})
server.on('error', function (error) {

View file

@ -1,12 +1,12 @@
const mc = require('minecraft-protocol')
const Chunk = require('prismarine-chunk')('1.12.1')
const Chunk = require('prismarine-chunk')('1.16-rc1')
const Vec3 = require('vec3')
var server = mc.createServer({
'online-mode': true,
encryption: true,
host: '0.0.0.0',
port: 25565,
version: '1.12.1'
version: '1.16-rc1'
})
var chunk = new Chunk()
@ -20,11 +20,69 @@ for (var x = 0; x < 16; x++) {
}
server.on('login', function (client) {
const w = {
piglin_safe: {
type: 'byte',
value: 0
},
natural: {
type: 'byte',
value: 1
},
ambient_light: {
type: 'float',
value: 0
},
infiniburn: {
type: 'string',
value: 'minecraft:infiniburn_overworld'
},
respawn_anchor_works: {
type: 'byte',
value: 0
},
has_skylight: {
type: 'byte',
value: 1
},
bed_works: {
type: 'byte',
value: 1
},
has_raids: {
type: 'byte',
value: 1
},
name: {
type: 'string',
value: 'minecraft:overworld'
},
logical_height: {
type: 'int',
value: 256
},
shrunk: {
type: 'byte',
value: 0
},
ultrawarm: {
type: 'byte',
value: 0
},
has_ceiling: {
type: 'byte',
value: 0
}
}
client.write('login', {
entityId: client.id,
levelType: 'default',
gameMode: 0,
dimension: 0,
previousGameMode: 255,
worldNames: ['minecraft:overworld'],
dimensionCodec: { name: '', type: 'compound', value: { dimension: { type: 'list', value: { type: 'compound', value: [{ name: w }] } } } },
dimension: 'minecraft:overworld',
worldName: 'minecraft:overworld',
difficulty: 2,
maxPlayers: server.maxPlayers,
reducedDebugInfo: false,

View file

@ -4,6 +4,60 @@ const mc = require('../')
const assert = require('power-assert')
const { firstVersion, lastVersion } = require('./common/parallel')
const w = {
piglin_safe: {
type: 'byte',
value: 0
},
natural: {
type: 'byte',
value: 1
},
ambient_light: {
type: 'float',
value: 0
},
infiniburn: {
type: 'string',
value: 'minecraft:infiniburn_overworld'
},
respawn_anchor_works: {
type: 'byte',
value: 0
},
has_skylight: {
type: 'byte',
value: 1
},
bed_works: {
type: 'byte',
value: 1
},
has_raids: {
type: 'byte',
value: 1
},
name: {
type: 'string',
value: 'minecraft:overworld'
},
logical_height: {
type: 'int',
value: 256
},
shrunk: {
type: 'byte',
value: 0
},
ultrawarm: {
type: 'byte',
value: 0
},
has_ceiling: {
type: 'byte',
value: 0
}
}
mc.supportedVersions.forEach(function (supportedVersion, i) {
if (!(i >= firstVersion && i <= lastVersion)) { return }
@ -151,7 +205,11 @@ mc.supportedVersions.forEach(function (supportedVersion, i) {
entityId: client.id,
levelType: 'default',
gameMode: 1,
dimension: 0,
previousGameMode: 255,
worldNames: ['minecraft:overworld'],
dimensionCodec: { name: '', type: 'compound', value: { dimension: { type: 'list', value: { type: 'compound', value: [w] } } } },
dimension: version.majorVersion === '1.16' ? 'minecraft:overworld' : 0,
worldName: 'minecraft:overworld',
hashedSeed: [0, 0],
difficulty: 2,
maxPlayers: server.maxPlayers,
@ -212,7 +270,7 @@ mc.supportedVersions.forEach(function (supportedVersion, i) {
if (server.clients[clientId] === undefined) continue
client = server.clients[clientId]
if (client !== exclude) client.write('chat', { message: JSON.stringify({ text: message }), position: 0 })
if (client !== exclude) client.write('chat', { message: JSON.stringify({ text: message }), position: 0, sender: '0' })
}
}
})
@ -265,7 +323,11 @@ mc.supportedVersions.forEach(function (supportedVersion, i) {
entityId: client.id,
levelType: 'default',
gameMode: 1,
dimension: 0,
previousGameMode: 255,
worldNames: ['minecraft:overworld'],
dimensionCodec: { name: '', type: 'compound', value: { dimension: { type: 'list', value: { type: 'compound', value: [w] } } } },
dimension: version.majorVersion === '1.16' ? 'minecraft:overworld' : 0,
worldName: 'minecraft:overworld',
hashedSeed: [0, 0],
difficulty: 2,
maxPlayers: server.maxPlayers,