mirror of
https://github.com/danbulant/flying-squid
synced 2026-06-24 17:21:43 +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 EventEmitter = require('events').EventEmitter
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const requireIndex = require('./lib/requireindex')
|
const requireIndex = require('./lib/requireindex')
|
||||||
|
const supportedVersions = require('./lib/version').supportedVersions
|
||||||
require('emit-then').register()
|
require('emit-then').register()
|
||||||
if (process.env.NODE_ENV === 'dev') {
|
if (process.env.NODE_ENV === 'dev') {
|
||||||
require('longjohn')
|
require('longjohn')
|
||||||
|
|
@ -31,6 +32,12 @@ class MCServer extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
connect (options) {
|
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'))
|
const plugins = requireIndex(path.join(__dirname, 'lib', 'plugins'))
|
||||||
this._server = mc.createServer(options)
|
this._server = mc.createServer(options)
|
||||||
Object.keys(plugins)
|
Object.keys(plugins)
|
||||||
|
|
|
||||||
|
|
@ -82,14 +82,21 @@ module.exports.server = async function (serv, {version, worldFolder, generation
|
||||||
module.exports.player = function (player, serv, settings) {
|
module.exports.player = function (player, serv, settings) {
|
||||||
player.unloadChunk = (chunkX, chunkZ) => {
|
player.unloadChunk = (chunkX, chunkZ) => {
|
||||||
delete player.loadedChunks[chunkX + ',' + chunkZ]
|
delete player.loadedChunks[chunkX + ',' + chunkZ]
|
||||||
player._client.write('map_chunk', {
|
|
||||||
x: chunkX,
|
if (serv.majorVersion === '1.8') {
|
||||||
z: chunkZ,
|
player._client.write('map_chunk', {
|
||||||
groundUp: true,
|
x: chunkX,
|
||||||
bitMap: 0x0000,
|
z: chunkZ,
|
||||||
chunkData: Buffer.alloc(0),
|
groundUp: true,
|
||||||
blockEntities: []
|
bitMap: 0x0000,
|
||||||
})
|
chunkData: Buffer.alloc(0)
|
||||||
|
})
|
||||||
|
} else if (serv.majorVersion === '1.12') {
|
||||||
|
player._client.write('unload_chunk', {
|
||||||
|
chunkX,
|
||||||
|
chunkZ
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
player.sendChunk = (chunkX, chunkZ, column) => {
|
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