mirror of
https://github.com/danbulant/flying-squid
synced 2026-06-13 03:21:03 +00:00
chunk unloading for 1.12 and 1.8
This commit is contained in:
parent
069e30cb7e
commit
c01f9dcfca
3 changed files with 25 additions and 8 deletions
|
|
@ -2,6 +2,7 @@ const mc = require('minecraft-protocol')
|
|||
const EventEmitter = require('events').EventEmitter
|
||||
const path = require('path')
|
||||
const requireIndex = require('./lib/requireindex')
|
||||
const supportedVersions = require('./lib/version').supportedVersions
|
||||
require('emit-then').register()
|
||||
if (process.env.NODE_ENV === 'dev') {
|
||||
require('longjohn')
|
||||
|
|
@ -31,6 +32,12 @@ class MCServer extends EventEmitter {
|
|||
}
|
||||
|
||||
connect (options) {
|
||||
const version = require('minecraft-data')(options.version).version
|
||||
if (supportedVersions.indexOf(version.majorVersion) === -1) {
|
||||
throw new Error(`Version ${version.minecraftVersion} is not supported.`)
|
||||
}
|
||||
this.majorVersion = version.majorVersion
|
||||
|
||||
const plugins = requireIndex(path.join(__dirname, 'lib', 'plugins'))
|
||||
this._server = mc.createServer(options)
|
||||
Object.keys(plugins)
|
||||
|
|
|
|||
|
|
@ -82,14 +82,21 @@ module.exports.server = async function (serv, {version, worldFolder, generation
|
|||
module.exports.player = function (player, serv, settings) {
|
||||
player.unloadChunk = (chunkX, chunkZ) => {
|
||||
delete player.loadedChunks[chunkX + ',' + chunkZ]
|
||||
player._client.write('map_chunk', {
|
||||
x: chunkX,
|
||||
z: chunkZ,
|
||||
groundUp: true,
|
||||
bitMap: 0x0000,
|
||||
chunkData: Buffer.alloc(0),
|
||||
blockEntities: []
|
||||
})
|
||||
|
||||
if (serv.majorVersion === '1.8') {
|
||||
player._client.write('map_chunk', {
|
||||
x: chunkX,
|
||||
z: chunkZ,
|
||||
groundUp: true,
|
||||
bitMap: 0x0000,
|
||||
chunkData: Buffer.alloc(0)
|
||||
})
|
||||
} else if (serv.majorVersion === '1.12') {
|
||||
player._client.write('unload_chunk', {
|
||||
chunkX,
|
||||
chunkZ
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
player.sendChunk = (chunkX, chunkZ, column) => {
|
||||
|
|
|
|||
3
src/lib/version.js
Normal file
3
src/lib/version.js
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
supportedVersions: ['1.8', '1.12']
|
||||
}
|
||||
Loading…
Reference in a new issue