Skip to content

Conversation

@suzakuwcx
Copy link

Fix relate issue: #10, cite: https://minecraft.wiki/w/Chunk_format

But in contrast, this pr will cause that deprecating the support for old versions. So maybe creating a new branch is a better idea?

image

@MestreLion
Copy link
Owner

Thank you, this is such a welcome contribution!

Btw, is the difference only in the capitalization of names (sections vs Sections) or were there other structural changes? If it is, it might be easy to create a unified get_blocks() that is compatible with both the old and the new standard. Even some minor structural changes (palette / data being under block_state or directly in Sections) might be handled without too complex logic.

If not, I'd prefer the old function to remain intact, possibly provisionally renamed as get_blocks_old(), remove any compatibility logic in get_blocks(), and add documentation (as docstrings or plain comments) on which game versions each one operates.

In the future, if desired, get_blocks() may become a wrapper that automatically chooses the appropriate function based on the actual save file version.

@MestreLion
Copy link
Owner

Also, would you mind adding a "Fix #10" suffix to the commit message so that bug is properly closed and linked to this fix?

@suzakuwcx
Copy link
Author

Thanks, I would try your suggestion to make backward compatible and update suffix.

About difference, it is not the only capitalization, base on my experiment on 1.21 and wiki description, the different is:

  • Name change: "section" -> "Section", "BlockStates" -> "block_states", "Palette" -> "palette"
  • Structure change: "palette" now is under "block_state" (before is under "section")
  • If only one block in "palette", the "data" field will be remove
  • sometime a strange "Y=-5" Section will appear and this is useless

@suzakuwcx suzakuwcx marked this pull request as draft October 9, 2024 09:20
@suzakuwcx suzakuwcx marked this pull request as ready for review October 10, 2024 02:55
@suzakuwcx
Copy link
Author

suzakuwcx commented Oct 10, 2024

Now I modify get_blocks() as a wrapper and it will choose correct function to parse

I test the test case and now they goes well

blocks()
image

pretty()
image

@SorkoPiko
Copy link

When is this getting merged? I would love to see this implemented, as there are currently no working MC world manipulation python libraries.

Because that the index of palette array begins from 0, so the maximux
index is 1 less than palette length
@MestreLion
Copy link
Owner

@SorkoPiko

When is this getting merged? I would love to see this implemented, as there are currently no working MC world manipulation python libraries.

I didn't have the time to properly review or test it yet. The new block state format changes more than just renaming/reorganizing keys in the NBT structure, and this PR also deals with backward-compatibility at run time, so not very trivial. If anyone can/wants to test this, or even step up as a co-maintainer of this project, I would appreciate!

@corgi-in-tights
Copy link

To anyone in the future: PR seems to work for 1.21.8. (atleast the few methods I tested), recommend just cloning and replacing your current mcworldlib folder with the one from suzaku's repo

def get_blocks(self):
"""Yield a (Y, Palette, BlockState Indexes Array) tuple for every chunk section.

def is_version_1_21(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def is_version_1_21(self):
def is_version_1_18(self):

In fact (as described in the Wiki and I also tested by myself), the change of name "Sections" to "sections" and other name changes is applied from 1.18 rather than 1.21.

So the name can be changed?

@Starrah
Copy link
Contributor

Starrah commented Jan 7, 2026

I tested this PR on:

  • 1.17.1 (The last version of the old format)
  • 1.18.2 (The changes of the chunk format related to this PR are since 1.18)
  • 1.20.1
  • 1.21.1

All of them work well.

So I think it is OK to merge this PR. The function work good, though it has some code names that may confuse others as I commented above.

@Starrah
Copy link
Contributor

Starrah commented Jan 7, 2026

If anyone can/wants to test this, or even step up as a co-maintainer of this project

Besides, I'm also interested in step up as a co-maintainer of this project, (as it is very useful and helped me find my Little Maid's tomb position when I'm offline, on 1.20.1.) @MestreLion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants