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

fix: toJson / fromJson didn't use maxBitsPerBlock #238

Merged
merged 4 commits into from
Apr 28, 2024

Conversation

zardoy
Copy link
Contributor

@zardoy zardoy commented Apr 17, 2024

Fixes the following code:

import PChunk from 'prismarine-chunk'
import { Vec3 } from 'vec3'

const Chunk = PChunk('1.18.1')
const chunk = new Chunk(undefined)

const chunk2 = Chunk.fromJson(chunk.toJson()) as any

for (let i = 0; i < 4096; i++) {
    chunk2.setBlockStateId(new Vec3(0, 0, 0), i) // Decides to switch to Direct pallete at some point
    const blockStateId = chunk2.getBlockStateId(new Vec3(0, 0, 0))
    if (blockStateId !== i) throw new Error(`Expected ${i} but got ${blockStateId}`) // Expected 256 but got 0
}

Also what about indirect pallete I don't really know what is the correct behavior but it just feels like always adding a new block into pallete on the block replace is not right (since the block doesn't exist in chunk anymore).

@extremeheat
Copy link
Member

Can you add a test?

@zardoy
Copy link
Contributor Author

zardoy commented Apr 17, 2024

Can you add a test?

Of course, just wanted initial feedback. Also, is it a bug that Pallete doesn't get cleared? I feel its not optimized...

@rom1504 rom1504 merged commit eb39a90 into PrismarineJS:master Apr 28, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Closed
Development

Successfully merging this pull request may close these issues.

3 participants