Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add v0 support to the decoder #230

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/bedrock/1.3/SubChunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { getChecksum } = require('../common/util')
const neededBits = require('../../pc/common/neededBits')
const Stream = require('../common/Stream')
const nbt = require('prismarine-nbt')
const legacyBlockIdMap = require('./legacy.json').blocks

class SubChunk {
constructor (registry, Block, options = {}) {
Expand Down Expand Up @@ -47,6 +48,36 @@ class SubChunk {
let storageCount = 1

switch (this.subChunkVersion) {
case 0: {
const blockIds = stream.readBuffer(4096)
const metas = stream.readBuffer(2048)

for (let x = 0; x < 16; x++) {
for (let y = 0; y < 16; y++) {
for (let z = 0; z < 16; z++) {
const index = (x << 8) + (z << 4) + y
const id = blockIds[index]
const meta = metas[index >> 1] >> (index & 1) * 4 & 15

const str = legacyBlockIdMap[`${id}:${meta}`].substring(10)
const name = str.split('[', 1)[0]
let propertiesArr = []
if (str.slice(name.length + 1, -1) !== '') {
propertiesArr = str.slice(name.length + 1, -1).split(',')
}
const properties = Object.fromEntries(propertiesArr.map(property => {
const [key, value] = property.split('=')
const intValue = parseInt(value)
return [key, isNaN(intValue) ? { true: 1, false: 0 }[value] ?? value : intValue]
}))
const b = this.Block.fromProperties(name, properties, 0)
this.setBlock(undefined, x, y, z, b)
}
}
}
this.subChunkVersion = 8
return
}
case 1:
// This is a old SubChunk format that only has one layer - no need to read storage count
// But when re-encoding, we want to use v8 to not loose data
Expand Down
Loading