Amulet-Team / Amulet-Core

A Python library for reading and writing the Minecraft save formats. See Amulet for the actual editor.
https://www.amuletmc.com/
220 stars 33 forks source link

[Feature Request] Chunk ownership #257

Open gentlegiantJGC opened 2 years ago

gentlegiantJGC commented 2 years ago

Feature Request

The Problem

Currently chunks are intended to be independent of the world however I think we should change this behaviour. There is an issue when adding chunks to a world that the same chunk object may already be in a different world. Should editing this chunk object change the chunk in both worlds? Should marking the chunk as changed do so for both worlds? Which block and biome palette should the chunk reference?

I think it would make it a lot easier if each chunk was associated with at most one level. Putting the chunk in a different level would copy the chunk and put the copy in the new level leaving the original in the old one.

This would also make it possible to reach back into the world that owns the chunk. Amulet-Team/Amulet-Map-Editor#685

Feature Description

Add a weak reference to the chunk that stores the level that owns the chunk. This may be None if the chunk is an orphan chunk.

Here is a prototype including this https://gist.github.com/gentlegiantJGC/d0f0b6d34db696b5e5d41d166a0033e0

gentlegiantJGC commented 1 year ago

After some thought I think we should make the level manage if the chunk has changed and switch to a get set system that deep copies the chunks. It makes threading simpler because only one thread can modify a chunk at the same time

There are benefits to be able to go from the chunk to the level that owns it. I would need to think through what effects this would have on deep copying and serialising the data.