chunky-dev / chunky

A path tracer to create realistic images of your Minecraft worlds.
https://chunky-dev.github.io/docs
GNU General Public License v3.0
651 stars 77 forks source link

Chunk interface proposal #1139

Open NotStirred opened 2 years ago

NotStirred commented 2 years ago

Looking for comments on this before I start implementing it.

public interface Chunk {
  ChunkPosition getPosition();

  void getChunkData(Mutable<ChunkData> reusableChunkData, Set<String> request, BlockPalette blockPalette, BiomePalette biomePalette, int yMin, int yMax);

  boolean chunkChangedSince(int timestamp, int yMin, int yMax);

  void getHeightmap(int[] chunkHeightmap, int yMin, int yMax);

  //map view specific to be removed on map view rewrite
  void renderSurface(MapTile tile);
  void renderBiomes(MapTile tile);
  int biomeColor();
  void reset();
  void queueTopography();
}

This is a step towards the world format api (#1038), making it much easier to add new chunk implementations. I'm thinking of keeping some of the map-view specific calls to avoid messing with it at all, but those can be removed with the map view rewrite in the future. (properly tracking the lifetime of chunks on the map view side is not something I want to look at)

The largest change here is that there is now only a single implementation of loading chunks (replacing the old loadChunk, loadSurface and getChunkData methods). It would then be up to the caller to implement the behaviour in terms of the ChunkData interface.

Another issue is that the Set<String> request passed to getChunkData is only compatible with worlds that stick very closely to the vanilla java nbt format (basically only vanilla and cubicchunks). One idea I had is to pass a Request type that specifies whether blocks, biomes, entities, etc. should be loaded. Though I'm not sure how nice that is either.

NotStirred commented 2 years ago

The idea behind this is to move as much out of Chunk as possible, and have a nice generic interface that works for vanilla, bedrock, cubicchuks, etc.