From 9bd8f4c2bb59e2ab68acfb82b29d62ef5aa50b19 Mon Sep 17 00:00:00 2001 From: extremeheat Date: Thu, 25 Feb 2021 13:11:22 -0500 Subject: [PATCH] server sending generated chunks --- .gitignore | 2 +- data/new/proto.yml | 2 +- data/newproto.json | 2 +- package.json | 1 + src/serverTest.js | 90 +++++++++++++++++++++++----------------------- 5 files changed, 50 insertions(+), 47 deletions(-) diff --git a/.gitignore b/.gitignore index 4f37984..2f3cd51 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,5 @@ npm-debug.log __* data/*.js src/**/*.json -src/*.txt +src/**/*.txt dist/ \ No newline at end of file diff --git a/data/new/proto.yml b/data/new/proto.yml index b209d4f..db42f42 100644 --- a/data/new/proto.yml +++ b/data/new/proto.yml @@ -1003,7 +1003,7 @@ packet_level_chunk: # true. If set to false, the payload is composed of multiple sub-chunks, each of which carry a version # which indicates the way they are serialised, followed by biomes, border blocks and tile entities. If # CacheEnabled is true, the payload consists out of the border blocks and tile entities only. - payload: string + payload: ByteArray packet_set_commands_enabled: !id: 0x3b diff --git a/data/newproto.json b/data/newproto.json index 689ff79..9779bac 100644 --- a/data/newproto.json +++ b/data/newproto.json @@ -4506,7 +4506,7 @@ }, { "name": "payload", - "type": "string" + "type": "ByteArray" } ] ], diff --git a/package.json b/package.json index 175c491..18a635e 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "@xboxreplay/xboxlive-auth": "^3.3.3", "aes-js": "^3.1.2", "asn1": "^0.2.4", + "bedrock-provider": "github:extremeheat/bedrock-provider", "bn.js": "^4.11.4", "debug": "^4.3.1", "ec-pem": "^0.18.0", diff --git a/src/serverTest.js b/src/serverTest.js index ad54097..6d01f96 100644 --- a/src/serverTest.js +++ b/src/serverTest.js @@ -4,6 +4,7 @@ const CreativeItems = require('../data/creativeitems.json') const NBT = require('prismarine-nbt') const fs = require('fs') + let server = new Server({ }) @@ -38,45 +39,7 @@ server.on('connect', ({ client }) => { }) client.once('resource_pack_client_response', async (packet) => { - // ran = true - // let items = [] - // let ids = 0 - // for (var item of CreativeItems) { - // let creativeitem = { runtime_id: items.length } - // const has_nbt = !!item.nbt_b64 - // if (item.id != 0) { - // creativeitem.item = { - // network_id: item.id, - // auxiliary_value: item.damage || 0, - // has_nbt, - // nbt: { - // version: 1, - // }, - // blocking_tick: 0, - // can_destroy: [], - // can_place_on: [] - // } - // if (has_nbt) { - // let nbtBuf = Buffer.from(item.nbt_b64, 'base64') - // let { parsed } = await NBT.parse(nbtBuf, 'little') - // creativeitem.item.nbt.nbt = parsed - // } - // } - // items.push(creativeitem) - // // console.log(creativeitem) - // } - - // console.log(items, ids) - - // client.write('creative_content', { items }) - // wait a bit just for easier debugging - // setTimeout(() => { - // const biomeDefs = fs.readFileSync('../data/biome_definitions.nbt') - // client.writeRaw('biome_definition_list', biomeDefs) - - // // TODO: send chunks so we can spawn player - // }, 1000) - + }) client.write('network_settings', { @@ -109,10 +72,14 @@ server.on('connect', ({ client }) => { client.queue('game_rules_changed', require('./packets/game_rules_changed.json')) client.queue('respawn', {"x":646.9405517578125,"y":65.62001037597656,"z":77.86255645751953,"state":0,"runtime_entity_id":0}) - for (const file of fs.readdirSync('chunks')) { - const buffer = Buffer.from(fs.readFileSync('./chunks/' + file, 'utf8'), 'hex') - // console.log('Sending chunk', chunk) - client.sendBuffer(buffer) + // for (const file of fs.readdirSync('chunks')) { + // const buffer = Buffer.from(fs.readFileSync('./chunks/' + file, 'utf8'), 'hex') + // // console.log('Sending chunk', chunk) + // client.sendBuffer(buffer) + // } + + for (const chunk of chunks) { + client.queue('level_chunk', chunk) } setInterval(() => { @@ -131,4 +98,39 @@ async function sleep(ms) { return new Promise(res => { setTimeout(() => { res() }, ms) }) -} \ No newline at end of file +} + +// CHUNKS +const { ChunkColumn, Version } = require('bedrock-provider') +const mcData = require('minecraft-data')('1.16') +var chunks = [] +async function buildChunks() { + // "x": 40, + // "z": 4, + + const stone = mcData.blocksByName.stone + + for (var cx = 35; cx < 45; cx++) { + for (var cz = 0; cz < 8; cz++) { + const column = new ChunkColumn(Version.v1_2_0_bis, x, z) + for (var x = 0; x < 16; x++) { + for (var y = 0; y < 60; y++) { + for (var z = 0; z < 16; z++) { + column.setBlock(x,y,z,stone) + } + } + } + + const ser = await column.networkEncodeNoCache() + + chunks.push({ + x:cx, z:cz, sub_chunk_count: column.sectionsLen, cache_enabled: false, + blobs: [], payload: ser + }) + } + } + + // console.log('Chunks',chunks) +} + +buildChunks() \ No newline at end of file