Skip to content

Commit 92ae1d3

Browse files
authored
pc1.18+: Fix world height defaults and light masks (#267)
* pc1.18+: Fix world height defaults and light masks The world height changed in 1.18+ to be between -64 and +320. The value set to the ChunkColumn have to be aligned with the dimension codec or the game will sometimes crash the game and otherwise cause chunks to be misplaced. Since we don't have a way to store this data inside prismarine-registry yet I just fix by changing the defaults to be correct. Also fix for light masks * lint * fix initialize fn not using correct maxY
1 parent 04433dc commit 92ae1d3

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/pc/1.18/ChunkColumn.js

+13-9
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@ const CommonChunkColumn = require('../common/CommonChunkColumn')
66
const constants = require('../common/constants')
77
const neededBits = require('../common/neededBits')
88

9+
const AQUATIC_UPDATE_MIN_Y = -64
10+
const AQUATIC_UPDATE_WORLD_HEIGHT = 384
11+
912
// wrap with func to provide version specific Block
1013
module.exports = (Block, mcData) => {
1114
return class ChunkColumn extends CommonChunkColumn {
1215
static get section () { return ChunkSection }
1316
constructor (options) {
1417
super(mcData)
15-
this.minY = options?.minY ?? 0
16-
this.worldHeight = options?.worldHeight ?? constants.CHUNK_HEIGHT
18+
this.minY = options?.minY ?? AQUATIC_UPDATE_MIN_Y
19+
this.worldHeight = options?.worldHeight ?? AQUATIC_UPDATE_WORLD_HEIGHT
1720
this.numSections = this.worldHeight >> 4
1821
this.maxBitsPerBlock = neededBits(Object.values(mcData.blocks).reduce((high, block) => Math.max(high, block.maxStateId), 0))
1922
this.maxBitsPerBiome = neededBits(Object.values(mcData.biomes).length)
@@ -93,7 +96,8 @@ module.exports = (Block, mcData) => {
9396

9497
initialize (func) {
9598
const p = { x: 0, y: 0, z: 0 }
96-
for (p.y = 0; p.y < this.worldHeight; p.y++) {
99+
const maxY = this.worldHeight + this.minY
100+
for (p.y = this.minY; p.y < maxY; p.y++) {
97101
for (p.z = 0; p.z < constants.SECTION_WIDTH; p.z++) {
98102
for (p.x = 0; p.x < constants.SECTION_WIDTH; p.x++) {
99103
const block = func(p.x, p.y, p.z)
@@ -283,9 +287,9 @@ module.exports = (Block, mcData) => {
283287

284288
_loadBlockLightNibbles (y, buffer) {
285289
if (buffer.length !== 2048) throw new Error('Invalid light nibble buffer length ' + buffer.length)
286-
const minCY = this.minY >> 4
287-
this.blockLightMask.set(y + minCY + 1, 1) // minCY + 1 extra layer below
288-
this.blockLightSections[y - (this.minY >> 4) + 1] = new BitArray({
290+
const minCY = Math.abs(this.minY >> 4)
291+
this.blockLightMask.set(y + minCY, 1) // minCY + 1 extra layer below
292+
this.blockLightSections[y + minCY] = new BitArray({
289293
bitsPerValue: 4,
290294
capacity: 4096,
291295
data: new Int8Array(buffer).buffer
@@ -294,9 +298,9 @@ module.exports = (Block, mcData) => {
294298

295299
_loadSkyLightNibbles (y, buffer) {
296300
if (buffer.length !== 2048) throw new Error('Invalid light nibble buffer length: ' + buffer.length)
297-
const minCY = this.minY >> 4
298-
this.skyLightMask.set(y + minCY + 1, 1) // minCY + 1 extra layer below
299-
this.skyLightSections[y - minCY + 1] = new BitArray({
301+
const minCY = Math.abs(this.minY >> 4)
302+
this.skyLightMask.set(y + minCY, 1) // minCY + 1 extra layer below
303+
this.skyLightSections[y + minCY] = new BitArray({
300304
bitsPerValue: 4,
301305
capacity: 4096,
302306
data: new Int8Array(buffer).buffer

0 commit comments

Comments
 (0)